cgen: fix asm stmt separators (#25067)

This commit is contained in:
kbkpbot 2025-08-09 15:14:06 +08:00 committed by GitHub
parent a2f65c6977
commit 4e8b24694b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 49 additions and 1 deletions

View file

@ -3255,7 +3255,7 @@ fn (mut g Gen) asm_stmt(stmt ast.AsmStmt) {
}
if !template.is_label {
g.write(';')
g.write('\\n\\t')
}
g.writeln('"')
}

View file

@ -0,0 +1,48 @@
import os
import time
const asm_file_content = '
fn asm_fn() {
mut x := u64(0)
mut y := u64(0)
mut z := u64(0)
mut hi := u64(0)
mut lo := u64(0)
asm amd64 {
mulq rdx
addq rax, z
adcq rdx, 0
; =a (lo)
=d (hi)
; a (x)
d (y)
r (z)
; cc
}
}
fn main() {
asm_fn()
}
'
const vexe = os.getenv('VEXE')
const v_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.amd64.v')
const genexe_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.exe')
const c_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.exe.tmp.c')
fn test_stmt_separator() {
os.write_file(v_file, asm_file_content)!
eprintln('Compiling...')
compile_cmd := '${os.quoted_path(vexe)} -cg -skip-running -no-rsp -keepc -o ${os.quoted_path(genexe_file)} ${os.quoted_path(v_file)}'
eprintln('> compile_cmd: ${compile_cmd}')
time.sleep(1000 * time.millisecond) // improve chances of working on windows
compile_res := os.system(compile_cmd)
assert compile_res == 0
content := os.read_file(c_file)!
os.rm(v_file)!
os.rm(genexe_file)!
os.rm(c_file)!
assert content.contains(r'addq %[z], %%rax\n\t')
}