Skip to content

Commit 4e8b246

Browse files
authored
cgen: fix asm stmt separators (#25067)
1 parent a2f65c6 commit 4e8b246

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

‎vlib/v/gen/c/cgen.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3255,7 +3255,7 @@ fn (mut g Gen) asm_stmt(stmt ast.AsmStmt) {
32553255
}
32563256

32573257
if !template.is_label {
3258-
g.write(';')
3258+
g.write('\\n\\t')
32593259
}
32603260
g.writeln('"')
32613261
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
import time
3+
4+
const asm_file_content = '
5+
fn asm_fn() {
6+
mut x := u64(0)
7+
mut y := u64(0)
8+
mut z := u64(0)
9+
mut hi := u64(0)
10+
mut lo := u64(0)
11+
asm amd64 {
12+
mulq rdx
13+
addq rax, z
14+
adcq rdx, 0
15+
; =a (lo)
16+
=d (hi)
17+
; a (x)
18+
d (y)
19+
r (z)
20+
; cc
21+
}
22+
}
23+
24+
fn main() {
25+
asm_fn()
26+
}
27+
'
28+
29+
const vexe = os.getenv('VEXE')
30+
const v_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.amd64.v')
31+
const genexe_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.exe')
32+
const c_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.exe.tmp.c')
33+
34+
fn test_stmt_separator() {
35+
os.write_file(v_file, asm_file_content)!
36+
eprintln('Compiling...')
37+
compile_cmd := '${os.quoted_path(vexe)} -cg -skip-running -no-rsp -keepc -o ${os.quoted_path(genexe_file)} ${os.quoted_path(v_file)}'
38+
eprintln('> compile_cmd: ${compile_cmd}')
39+
time.sleep(1000 * time.millisecond) // improve chances of working on windows
40+
compile_res := os.system(compile_cmd)
41+
assert compile_res == 0
42+
43+
content := os.read_file(c_file)!
44+
os.rm(v_file)!
45+
os.rm(genexe_file)!
46+
os.rm(c_file)!
47+
assert content.contains(r'addq %[z], %%rax\n\t')
48+
}

0 commit comments

Comments
 (0)