code wiki / _hdl_build / nx_toolchain_sweep.nx
nx_toolchain_sweep.nx source
↩ module page · 106 lines · 6602 B
1// nx_toolchain_sweep.nx -- the ENTERPRISE SWEEP: the team runs a real corpus through the SOVEREIGN x86
2// toolchain (nxasm_x86) AND through gcc (the oracle), measures sovereign-build coverage + behavioral
3// parity, and uses the maturity ladder to classify the x86 toolchain's level from EVIDENCE (operator:
4// "do the sweep with that enterprise evaluation"). Flags the verdict + any coverage gap to the PM review
5// log. NishiLang fork/exec, no .sh orchestration. license_tier: ORIGINAL Reuses _run from nx_build_orchestrator.
6
7import "nx_maturity_auditor.nx"
8import "nx_pm_review_log.nx"
9import "nx_syscalls.nx"
10
11func _puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func _putn(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
13func _exitcode(status: i64) -> i64 { return (status >> 8) & 0xff }
14func _run(path: *u8, argv: *i64, envp: *i64, redir_fd: i64) -> i64 {
15 let pid: i64 = sys_fork()
16 if pid == 0 { if redir_fd >= 0 { sys_dup3(redir_fd, 1, 0) } sys_execve(path, argv, envp) sys_exit(127) }
17 let st: *i64 = sys_mmap(16) as *i64; sys_wait4(pid, st, 0); return _exitcode(st[0])
18}
19
20// build one target sovereignly + via gcc oracle; return: -1 compile-fail, 0 nxasm coverage gap,
21// 1 built-but-behavior-differs, 2 behavioral PARITY vs gcc.
22func _sweep_one(compiler: *u8, asm_tool: *u8, gcc: *u8, src: *u8, spath: *u8, sovelf: *u8, gccelf: *u8, envp: *i64) -> i64 {
23 let sfd: i64 = sys_openat_wr(spath, 0x1a4)
24 let ac: *i64 = sys_mmap(8*4) as *i64; ac[0]=compiler as i64; ac[1]=src as i64; ac[2]=0
25 let rc_c: i64 = _run(compiler, ac, envp, sfd); sys_close(sfd)
26 if rc_c != 0 { return 0 - 1 }
27 let aa: *i64 = sys_mmap(8*4) as *i64; aa[0]=asm_tool as i64; aa[1]=spath as i64; aa[2]=sovelf as i64; aa[3]=0
28 let rc_a: i64 = _run(asm_tool, aa, envp, 0 - 1)
29 if rc_a != 0 { return 0 }
30 let ar: *i64 = sys_mmap(8*4) as *i64; ar[0]=sovelf as i64; ar[1]=0
31 let ex_s: i64 = _run(sovelf, ar, envp, 0 - 1)
32 let ag: *i64 = sys_mmap(8*12) as *i64
33 ag[0]=gcc as i64; ag[1]="-nostdlib" as *u8 as i64; ag[2]="-no-pie" as *u8 as i64; ag[3]="-static" as *u8 as i64
34 ag[4]=spath as i64; ag[5]="-o" as *u8 as i64; ag[6]=gccelf as i64; ag[7]=0
35 let rc_g: i64 = _run(gcc, ag, envp, 0 - 1)
36 let gr: *i64 = sys_mmap(8*4) as *i64; gr[0]=gccelf as i64; gr[1]=0
37 let ex_g: i64 = _run(gccelf, gr, envp, 0 - 1)
38 if ex_s == ex_g { return 2 }
39 return 1
40}
41
42func main() -> i64 {
43 _puts("=== TOOLCHAIN SWEEP: sovereign nxasm_x86 vs gcc oracle across a real corpus ===\n" as *u8)
44 let compiler: *u8 = "_offc/nx_cc_known_good.elf" as *u8
45 let gcc: *u8 = "/usr/bin/gcc" as *u8
46 let asm_tool: *u8 = "/tmp/nxasm_x86" as *u8
47 let spath: *u8 = "/tmp/_sweep.s" as *u8
48 let sovelf: *u8 = "/tmp/_sweep.sov" as *u8
49 let gccelf: *u8 = "/tmp/_sweep.gcc" as *u8
50 let envp: *i64 = sys_mmap(8*4) as *i64
51 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0
52
53 // bootstrap the sovereign assembler tool (one-time gcc bootstrap of the TOOL)
54 let bsfd: i64 = sys_openat_wr("/tmp/nxasm_x86.s" as *u8, 0x1a4)
55 let bac: *i64 = sys_mmap(8*4) as *i64; bac[0]=compiler as i64; bac[1]="nxasm/nxasm_x86_main.nx" as *u8 as i64; bac[2]=0
56 let brc: i64 = _run(compiler, bac, envp, bsfd); sys_close(bsfd)
57 let bal: *i64 = sys_mmap(8*12) as *i64
58 bal[0]=gcc as i64; bal[1]="-nostdlib" as *u8 as i64; bal[2]="-no-pie" as *u8 as i64; bal[3]="-static" as *u8 as i64
59 bal[4]="/tmp/nxasm_x86.s" as *u8 as i64; bal[5]="-o" as *u8 as i64; bal[6]=asm_tool as i64; bal[7]=0
60 _run(gcc, bal, envp, 0 - 1)
61
62 // the corpus -- self-contained _hdl_build tests with varied instruction surfaces
63 let N: i64 = 6
64 let corpus: *i64 = sys_mmap(8*N) as *i64
65 corpus[0]="runtime/_hdl_build/_min42.nx" as *u8 as i64
66 corpus[1]="runtime/_hdl_build/_orch_probe.nx" as *u8 as i64
67 corpus[2]="runtime/_hdl_build/nx_dep_retire_test.nx" as *u8 as i64
68 corpus[3]="runtime/_hdl_build/nx_loop_monitor_test.nx" as *u8 as i64
69 corpus[4]="runtime/_hdl_build/nx_maturity_auditor_test.nx" as *u8 as i64
70 corpus[5]="runtime/_hdl_build/nx_pm_review_log_test.nx" as *u8 as i64
71
72 var built: i64 = 0; var parity: i64 = 0; var covgap: i64 = 0; var cfail: i64 = 0
73 var i: i64 = 0
74 while i < N {
75 let res: i64 = _sweep_one(compiler, asm_tool, gcc, corpus[i] as *u8, spath, sovelf, gccelf, envp)
76 _puts(" [" as *u8)
77 if res == 2 { _puts("PARITY " as *u8) }
78 if res == 1 { _puts("DIFFERS" as *u8) }
79 if res == 0 { _puts("COV-GAP" as *u8) }
80 if res == 0 - 1 { _puts("CC-FAIL" as *u8) }
81 _puts("] " as *u8); _puts(corpus[i] as *u8); _puts("\n" as *u8)
82 if res >= 1 { built = built + 1 }
83 if res == 2 { parity = parity + 1 }
84 if res == 0 { covgap = covgap + 1 }
85 if res == 0 - 1 { cfail = cfail + 1 }
86 i = i + 1
87 }
88
89 // EVIDENCE -> maturity. hardened = built+matched the WHOLE corpus. byte-exact parity NOT yet measured,
90 // so we do NOT auto-claim S-class on exit-parity alone (Referee discipline).
91 var hardened: i64 = 0
92 if built == N { if parity == N { hardened = 1 } }
93 let level: i64 = mat_level(1, 1, hardened, 0, 0)
94 _puts("---- corpus=" as *u8); _putn(N); _puts(" sovereign-built=" as *u8); _putn(built); _puts(" exit-parity-vs-gcc=" as *u8); _putn(parity); _puts(" coverage-gaps=" as *u8); _putn(covgap); _puts(" cc-fails=" as *u8); _putn(cfail); _puts("\n" as *u8)
95 _puts(" x86 toolchain maturity = " as *u8); _puts(mat_label(level)); _puts(" (gap->S-class " as *u8); _putn(mat_gap_to_sclass(level)); _puts(")\n" as *u8)
96
97 let pm: i64 = pm_open("/tmp/nishi_pm_review.log" as *u8)
98 if level >= MAT_PRODUCTION {
99 pm_deliverable(pm, "toolchain/x86_64" as *u8, "sovereign-vs-gcc corpus sweep" as *u8, "nxasm_x86 sovereign-built + exit-parity vs gcc on the WHOLE corpus -> PRODUCTION; byte-exact differential = the step to claim triangulated S-class" as *u8)
100 } else {
101 pm_gap(pm, "toolchain/x86_64" as *u8, "NEEDS-CAPABILITY" as *u8, "nxasm_x86 coverage" as *u8, "sovereign assembler did not cover the whole corpus -- a COV-GAP target has an unencoded instruction/directive needing nxasm_x86_enc support" as *u8)
102 }
103 sys_close(pm)
104 _puts(" verdict flagged to /tmp/nishi_pm_review.log\n" as *u8)
105 sys_exit(0); return 0
106}