nx_wasm_call_count_gate_t143.nx source
↩ module page · 72 lines · 3112 B
1// Independent negative review of the private WAT call operand change.
2import "nx_wasm_call_operands_t143.nx"
3import "nx_gate_verdict.nx"
4const WCG_OUTPUT_BYTES: i64 = 4096
5func wcg_attempt(f: *Function, i: *Instr, o: *OutBuf, tail: i64, count: i64, simd: i64, ctr: *i64) -> i64 {
6 i.n_operands = count; i.callee = f
7 if simd == 1 { f.name_start = "v128_sad16" as i64 } else { f.name_start = "ordinary" as i64 }
8 o.pos = 0
9 let status: *i64 = sys_mmap_shared(8) as *i64
10 if (status as i64) <= 0 { return 3 }
11 status[0] = 0
12 let pid: i64 = sys_fork()
13 if pid < 0 { sys_munmap(status as *u8,8); return 3 }
14 if pid == 0 {
15 if tail == 1 { wat_emit_tail_call(f,o,0,i) } else { wat_emit_call(f,o,0,i) }
16 sys_exit(0)
17 }
18 let waited: i64 = sys_wait4(pid,status,0)
19 gv_kv("tail",tail); gv_kv("simd_name",simd); gv_kv("malformed_count",count)
20 gv_kv("child_exit",wait_exit_code(status[0])); gv_kv("emitted_bytes",o.pos)
21 gv_check_eq("owned child reaped",waited,pid,ctr)
22 gv_check_eq("refusal exits without signal",wait_term_signal(status[0]),0,ctr)
23 gv_check_eq("malformed count refuses with code3",wait_exit_code(status[0]),3,ctr)
24 gv_check_eq("malformed count emits no output",o.pos,0,ctr)
25 sys_munmap(status as *u8,8)
26 return 0
27}
28func wcg_contains(o: *OutBuf, text: *u8) -> i64 {
29 var at: i64 = 0
30 while at < o.pos {
31 var k: i64 = 0
32 while text[k] != (0 as u8) && at+k < o.pos {
33 if o.buf[at+k] != text[k] { break }
34 k = k+1
35 }
36 if text[k] == (0 as u8) { return 1 }
37 at = at+1
38 }
39 return 0
40}
41func main() -> i64 {
42 let ctr: *i64 = gv_ctr()
43 gv_head("WAT / malformed call counts" as *u8)
44 let ty: *Type = ir_type_i64()
45 let f: *Function = ir_function_new(0 as *Module,"ordinary" as *u8,8,ty)
46 let i: *Instr = alloc_instr(f,OP_CALL,ty)
47 i.op0 = ir_const_i64(f,0); i.op1 = ir_const_i64(f,16)
48 let raw: *u8 = sys_mmap_shared(WCG_OUTPUT_BYTES+64)
49 if (raw as i64) <= 0 { return 3 }
50 let o: *OutBuf = raw as *OutBuf
51 o.buf = (raw as i64+64) as *u8; o.cap = WCG_OUTPUT_BYTES; o.pos = 0
52 let first: *i64 = &i.op0; let end: *i64 = &i.callee as *i64
53 let slots: i64 = ((end as i64)-(first as i64))/8
54 gv_check_eq("actual operand storage has24slots",slots,24,ctr)
55 var tail: i64 = 0
56 while tail < 2 {
57 if wcg_attempt(f,i,o,tail,0-1,0,ctr) != 0 { return 3 }
58 if wcg_attempt(f,i,o,tail,slots+1,0,ctr) != 0 { return 3 }
59 if wcg_attempt(f,i,o,tail,9223372036854775807,0,ctr) != 0 { return 3 }
60 if wcg_attempt(f,i,o,tail,0-1,1,ctr) != 0 { return 3 }
61 if wcg_attempt(f,i,o,tail,slots+1,1,ctr) != 0 { return 3 }
62 if wcg_attempt(f,i,o,tail,1,1,ctr) != 0 { return 3 }
63 if wcg_attempt(f,i,o,tail,3,1,ctr) != 0 { return 3 }
64 i.n_operands = 2; i.callee = f; f.name_start = "v128_sad16" as i64; o.pos = 0
65 if tail == 1 { wat_emit_tail_call(f,o,0,i) } else { wat_emit_call(f,o,0,i) }
66 gv_check("valid two-argument SIMD emits output" as *u8,o.pos>0,ctr)
67 gv_check_eq("valid SIMD emits actual vector load",wcg_contains(o,"v128.load" as *u8),1,ctr)
68 tail = tail + 1
69 }
70 sys_munmap(raw,WCG_OUTPUT_BYTES+64)
71 return gv_verdict("WAT-CALL-COUNT" as *u8,ctr,"ordinary and named SIMD malformed IR; private compiler only" as *u8)
72}