smoke_regalloc_min7.nx source
↩ module page · 30 lines · 1329 B
1// Build a binop, then INSPECT the IR fields directly without
2// calling regalloc. See whether the struct fields read correctly
3// under qemu (rules out a Value/Instr layout mismatch).
4
5import "syscalls.nx"
6import "types.nx"
7import "ir.nx"
8
9func main() -> i64 {
10 let m_raw: *u8 = sys_mmap(256)
11 let m: *Module = m_raw as *Module
12 m.functions = 0 as *Function
13 m.n_functions = 0
14 let f: *Function = ir_function_new(m, "x" as *u8, 1, ir_type_i64())
15 let b: *BasicBlock = ir_block_new(f)
16 let c1: i64 = ir_const_i64(f, 10)
17 let c2: i64 = ir_const_i64(f, 20)
18 let s: i64 = ir_emit_binop(b, OP_ADD, c1, c2, ir_type_i64())
19
20 // Read the binop instruction back via b.head and check fields.
21 let inst: *Instr = b.head
22 if inst == (0 as *Instr) { return __syscall(93, 1, 0, 0, 0, 0, 0) }
23 if inst.op != OP_ADD { return __syscall(93, 2, 0, 0, 0, 0, 0) }
24 if inst.n_operands != 2 { return __syscall(93, 3, 0, 0, 0, 0, 0) }
25 if inst.op0 != c1 { return __syscall(93, 4, 0, 0, 0, 0, 0) }
26 if inst.op1 != c2 { return __syscall(93, 5, 0, 0, 0, 0, 0) }
27 if inst.result != s { return __syscall(93, 6, 0, 0, 0, 0, 0) }
28 if inst.next != (0 as *Instr) { return __syscall(93, 7, 0, 0, 0, 0, 0) }
29 return __syscall(93, 42, 0, 0, 0, 0, 0)
30}