nx_smoke_regalloc_min7.nx source
↩ module page · 36 lines · 1559 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
5// nx_safety_envelope:
6// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
7// sil_target: SIL1
8// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
9// verdict: NOT_YET_EVALUATED
10
11import "nx_syscalls.nx"
12import "nx_types.nx"
13import "nx_ir.nx"
14
15func main() -> i64 {
16 let m_raw: *u8 = sys_mmap(256)
17 let m: *Module = m_raw as *Module
18 m.functions = 0 as *Function
19 m.n_functions = 0
20 let f: *Function = ir_function_new(m, "x" as *u8, 1, ir_type_i64())
21 let b: *BasicBlock = ir_block_new(f)
22 let c1: i64 = ir_const_i64(f, 10)
23 let c2: i64 = ir_const_i64(f, 20)
24 let s: i64 = ir_emit_binop(b, OP_ADD, c1, c2, ir_type_i64())
25
26 // Read the binop instruction back via b.head and check fields.
27 let inst: *Instr = b.head
28 if inst == (0 as *Instr) { return __syscall(93, 1, 0, 0, 0, 0, 0) }
29 if inst.op != OP_ADD { return __syscall(93, 2, 0, 0, 0, 0, 0) }
30 if inst.n_operands != 2 { return __syscall(93, 3, 0, 0, 0, 0, 0) }
31 if inst.op0 != c1 { return __syscall(93, 4, 0, 0, 0, 0, 0) }
32 if inst.op1 != c2 { return __syscall(93, 5, 0, 0, 0, 0, 0) }
33 if inst.result != s { return __syscall(93, 6, 0, 0, 0, 0, 0) }
34 if inst.next != (0 as *Instr) { return __syscall(93, 7, 0, 0, 0, 0, 0) }
35 return __syscall(93, 42, 0, 0, 0, 0, 0)
36}