v2 / vlib / v / slow_tests / assembly / stmt_separator_test.amd64.v
48 lines · 43 sloc · 1.1 KB · 4e8b24694bb265d29826ae38c87d9467c3267e11
Raw
1import os
2import time
3
4const asm_file_content = '
5fn 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
24fn main() {
25 asm_fn()
26}
27'
28
29const vexe = os.getenv('VEXE')
30const v_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.amd64.v')
31const genexe_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.exe')
32const c_file = os.join_path(os.vtmp_dir(), 'generated_stmt_separator.exe.tmp.c')
33
34fn 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}
49