code wiki / (root) / nx_smoke_nxc_pipeline9.nx

nx_smoke_nxc_pipeline9.nx source

↩ module page · 63 lines · 2267 B

1// Pipeline first, but call write_elf with a FRESH code buffer 2// (not the one from assemble) -- to isolate whether memory 3// corruption from the pipeline damages later allocations. 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_lex_kinds.nx" 14import "nx_outbuf.nx" 15import "nx_ir.nx" 16import "nx_tokenizer.nx" 17import "nx_parse.nx" 18import "nx_opt.nx" 19import "nx_regalloc.nx" 20import "nx_riscv.nx" 21import "crt0.nx" 22import "nxasm_v2.nx" 23import "elf_writer.nx" 24 25func main() -> i64 { 26 let demo: *u8 = "func main() -> i64 { return __syscall(93, 30, 0, 0, 0, 0, 0) }" 27 28 let toks: *Tok = lex_source(demo, 4096) 29 let m: *Module = parse_module(toks, 0 as *Module) 30 let asm_out: *OutBuf = out_new(131072) 31 emit_crt0_start(asm_out) 32 var fi: i64 = 0 33 while fi < m.n_functions { 34 let fn_base: i64 = m.functions as i64 35 let f: *Function = (fn_base + fi * 176) as *Function 36 opt_run(f) 37 let locs_raw: *u8 = sys_mmap(f.n_values * 24 + 64) 38 let locs: *ValueLoc = locs_raw as *ValueLoc 39 let cs_raw: *u8 = sys_mmap(16) 40 let cs: *i64 = cs_raw as *i64 41 *cs = 0 42 let cs_fpr_raw: *u8 = sys_mmap(16) 43 let cs_fpr: *i64 = cs_fpr_raw as *i64 44 *cs_fpr = 0 45 let sb_raw: *u8 = sys_mmap(16) 46 let sb: *i64 = sb_raw as *i64 47 *sb = 0 48 regalloc_function(f, locs, cs, cs_fpr, sb) 49 let name_addr: i64 = f.name_start 50 let fn_name: *u8 = name_addr as *u8 51 emit_function(f, locs, asm_out, fn_name, 16, 8, *cs, *cs_fpr) 52 fi = fi + 1 53 } 54 let code_buf: *u8 = sys_mmap(65536) 55 let code_len: i64 = assemble(asm_out.buf, asm_out.pos, code_buf, 65536) 56 57 // Now call write_elf with a FRESH 4-byte buffer (not code_buf). 58 let fresh_code: *u8 = sys_mmap(64) 59 fresh_code[0] = 0x67; fresh_code[1] = 0x80; fresh_code[2] = 0; fresh_code[3] = 0 60 let n: i64 = write_elf(fresh_code, 4, 2) 61 if n < 0 { return __syscall(93, 50, 0, 0, 0, 0, 0) } 62 return __syscall(93, 42, 0, 0, 0, 0, 0) 63}