code wiki / _hdl_build / nx_doc_constscan_run.nx

nx_doc_constscan_run.nx source

↩ module page · 29 lines · 1374 B

1import "nx_gate_gn.nx" 2// nx_doc_constscan_run.nx -- CLI to DOGFOOD the LM-030 const-pointer-direct-index detector on REAL files. Each arg 3// is a source path; it reports the FIRST const[i] footgun per file (or clean). No-arg = usage (build-smoke safe). 4// run: nx_doc_constscan_run.elf <file.nx> [more.nx ...] 5import "nx_syscalls.nx" 6import "nx_doc_constscan.nx" 7 8func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9 10func main(argc: i64, argv: *i64) -> i64 { 11 if argc < 2 { gp("nx_doc_constscan_run: usage: nx_doc_constscan_run <file.nx> [more...]\n" as *u8); return 0 } 12 let name: *u8 = sys_mmap(64) 13 let pos: *i64 = sys_mmap(16) as *i64 14 var scanned: i64=0; var hits: i64=0 15 var i: i64=1 16 while i < argc { 17 let path: *u8 = argv[i] as *u8 18 let lp: *i64 = sys_mmap(16) as *i64; lp[0]=0 19 let buf: *u8 = sys_read_file(path, lp) 20 if (buf as i64)!=0 { 21 scanned=scanned+1 22 let r: i64 = cs_scan(buf, lp[0], name, pos) 23 if r >= 0 { gp(" HIT " as *u8); gp(path); gp(" @byte=" as *u8); gn(pos[0]); gp(" const `" as *u8); gp(name); gp("` indexed directly (LM-030 silent miscompile)\n" as *u8); hits=hits+1 } 24 } 25 i=i+1 26 } 27 gp("CONSTSCAN-RUN scanned=" as *u8); gn(scanned); gp(" hits=" as *u8); gn(hits); gp("\n" as *u8) 28 return 0 29}