nx_smoke_nxc_pipeline7.nx source
↩ module page · 70 lines · 2526 B
1// Add stage 5 (write_elf) to the pipeline replay. Writes to fd 3
2// (a pipe / dummy fd that we don't care about — kernel returns
3// EBADF, sys_write returns negative). We just want to confirm
4// write_elf can be CALLED without crashing.
5
6// nx_safety_envelope:
7// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
8// sil_target: SIL1
9// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
10// verdict: NOT_YET_EVALUATED
11
12import "nx_syscalls.nx"
13import "nx_types.nx"
14import "nx_lex_kinds.nx"
15import "nx_outbuf.nx"
16import "nx_ir.nx"
17import "nx_tokenizer.nx"
18import "nx_parse.nx"
19import "nx_opt.nx"
20import "nx_regalloc.nx"
21import "nx_riscv.nx"
22import "crt0.nx"
23import "nxasm_v2.nx"
24import "elf_writer.nx"
25
26func main() -> i64 {
27 let demo: *u8 = "func main() -> i64 { return __syscall(93, 30, 0, 0, 0, 0, 0) }"
28
29 let toks: *Tok = lex_source(demo, 4096)
30 if toks == (0 as *Tok) { return __syscall(93, 1, 0, 0, 0, 0, 0) }
31
32 let m: *Module = parse_module(toks, 0 as *Module)
33 if m == (0 as *Module) { return __syscall(93, 2, 0, 0, 0, 0, 0) }
34
35 let asm_out: *OutBuf = out_new(131072)
36 emit_crt0_start(asm_out)
37 var fi: i64 = 0
38 while fi < m.n_functions {
39 let fn_base: i64 = m.functions as i64
40 let f: *Function = (fn_base + fi * 176) as *Function
41 opt_run(f)
42 let locs_raw: *u8 = sys_mmap(f.n_values * 24 + 64)
43 let locs: *ValueLoc = locs_raw as *ValueLoc
44 let cs_raw: *u8 = sys_mmap(16)
45 let cs: *i64 = cs_raw as *i64
46 *cs = 0
47 let cs_fpr_raw: *u8 = sys_mmap(16)
48 let cs_fpr: *i64 = cs_fpr_raw as *i64
49 *cs_fpr = 0
50 let sb_raw: *u8 = sys_mmap(16)
51 let sb: *i64 = sb_raw as *i64
52 *sb = 0
53 regalloc_function(f, locs, cs, cs_fpr, sb)
54 let name_addr: i64 = f.name_start
55 let fn_name: *u8 = name_addr as *u8
56 emit_function(f, locs, asm_out, fn_name, 16, 8, *cs, *cs_fpr)
57 fi = fi + 1
58 }
59
60 let code_buf: *u8 = sys_mmap(65536)
61 let code_len: i64 = assemble(asm_out.buf, asm_out.pos, code_buf, 65536)
62 if code_len <= 0 { return __syscall(93, 100, 0, 0, 0, 0, 0) }
63
64 // Stage 5: write_elf to a discarded fd. We just want to know
65 // if it crashes or completes.
66 let n_written: i64 = write_elf(code_buf, code_len, 1)
67 // If we got here without crashing, exit with a marker.
68 if n_written < 0 { return __syscall(93, 50, 0, 0, 0, 0, 0) }
69 return __syscall(93, 42, 0, 0, 0, 0, 0)
70}