vfmt: fix asm volatile & goto (#9688)

pull/9700/head
Louis Schmieder 2021-04-11 22:32:28 +02:00 committed by GitHub
parent a851901620
commit 273655ecc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

View File

@ -228,7 +228,7 @@ pub enum Map_flags {
fn sys_call0(scn u64) u64 { fn sys_call0(scn u64) u64 {
res := u64(0) res := u64(0)
asm amd64 { asm amd64 {
syscall syscall
; =a (res) ; =a (res)
; a (scn) ; a (scn)
} }
@ -238,7 +238,7 @@ fn sys_call0(scn u64) u64 {
fn sys_call1(scn u64, arg1 u64) u64 { fn sys_call1(scn u64, arg1 u64) u64 {
res := u64(0) res := u64(0)
asm amd64 { asm amd64 {
syscall syscall
; =a (res) ; =a (res)
; a (scn) ; a (scn)
D (arg1) D (arg1)
@ -249,7 +249,7 @@ fn sys_call1(scn u64, arg1 u64) u64 {
fn sys_call2(scn u64, arg1 u64, arg2 u64) u64 { fn sys_call2(scn u64, arg1 u64, arg2 u64) u64 {
res := u64(0) res := u64(0)
asm amd64 { asm amd64 {
syscall syscall
; =a (res) ; =a (res)
; a (scn) ; a (scn)
D (arg1) D (arg1)
@ -261,7 +261,7 @@ fn sys_call2(scn u64, arg1 u64, arg2 u64) u64 {
fn sys_call3(scn u64, arg1 u64, arg2 u64, arg3 u64) u64 { fn sys_call3(scn u64, arg1 u64, arg2 u64, arg3 u64) u64 {
res := u64(0) res := u64(0)
asm amd64 { asm amd64 {
syscall syscall
; =a (res) ; =a (res)
; a (scn) ; a (scn)
D (arg1) D (arg1)
@ -275,7 +275,7 @@ fn sys_call4(scn u64, arg1 u64, arg2 u64, arg3 u64, arg4 u64) u64 {
res := u64(0) res := u64(0)
asm amd64 { asm amd64 {
mov r10, arg4 mov r10, arg4
syscall syscall
; =a (res) ; =a (res)
; a (scn) ; a (scn)
D (arg1) D (arg1)
@ -292,7 +292,7 @@ fn sys_call5(scn u64, arg1 u64, arg2 u64, arg3 u64, arg4 u64, arg5 u64) u64 {
asm amd64 { asm amd64 {
mov r10, arg4 mov r10, arg4
mov r8, arg5 mov r8, arg5
syscall syscall
; =a (res) ; =a (res)
; a (scn) ; a (scn)
D (arg1) D (arg1)
@ -312,7 +312,7 @@ fn sys_call6(scn u64, arg1 u64, arg2 u64, arg3 u64, arg4 u64, arg5 u64, arg6 u64
mov r10, arg4 mov r10, arg4
mov r8, arg5 mov r8, arg5
mov r9, arg6 mov r9, arg6
syscall syscall
; =a (res) ; =a (res)
; a (scn) ; a (scn)
D (arg1) D (arg1)

View File

@ -668,7 +668,13 @@ fn expr_is_single_line(expr ast.Expr) bool {
//=== Specific Stmt methods ===// //=== Specific Stmt methods ===//
fn (mut f Fmt) asm_stmt(stmt ast.AsmStmt) { fn (mut f Fmt) asm_stmt(stmt ast.AsmStmt) {
f.writeln('asm $stmt.arch {') f.write('asm ')
if stmt.is_volatile {
f.write('volatile ')
} else if stmt.is_goto {
f.write('goto ')
}
f.writeln('$stmt.arch {')
f.indent++ f.indent++
for template in stmt.templates { for template in stmt.templates {
if template.is_directive { if template.is_directive {
@ -678,7 +684,9 @@ fn (mut f Fmt) asm_stmt(stmt ast.AsmStmt) {
if template.is_label { if template.is_label {
f.write(':') f.write(':')
} else { } else {
f.write(' ') if template.args.len > 0 {
f.write(' ')
}
} }
for i, arg in template.args { for i, arg in template.args {
f.asm_arg(arg) f.asm_arg(arg)