code wiki / (root) / nx_vcc_color_wat.nx

nx_vcc_color_wat.nx source

↩ module page · 65 lines · 2525 B

1// nx_vcc_color_wat.nx -- argless build-driver: lowers runtime/nx_vcodec_color_wasm.nx to WAT at a fixed 2// output path. nx_sov_build_run swallows argv, so a parameterized nx_compile_wat can't be driven through it; 3// this fixes the paths and runs the SAME sovereign pipeline (expand_imports -> lex -> parse -> opt -> 4// wat_emit_module -> write). Sovereign, no .sh. license_tier: ORIGINAL 5import "nx_syscalls.nx" 6import "nx_types.nx" 7import "nx_lex_kinds.nx" 8import "nx_outbuf.nx" 9import "nx_ir.nx" 10import "nx_tokenizer.nx" 11import "nx_parse.nx" 12import "nx_opt.nx" 13import "nx_ir_dump.nx" 14import "nx_ir_validate.nx" 15import "nx_import.nx" 16import "nx_wasm.nx" 17 18const VCC_OUT_CAP: i64 = 16777216 19const VCC_EXPAND_CAP: i64 = 4194304 20 21func main() -> i64 { 22 let path: *u8 = "runtime/nx_vcodec_color_wasm.nx" as *u8 23 let out_path: *u8 = "web_assets/_video_build/nx_vcodec_color.wat" as *u8 24 25 let expand_buf: *u8 = sys_mmap(VCC_EXPAND_CAP) 26 let ctx: *ExpandCtx = expand_ctx_new(expand_buf, VCC_EXPAND_CAP) 27 let rc: i64 = expand_imports(ctx, path) 28 if rc < 0 { sys_write(2, "nx_vcc_color_wat: expand_imports failed\n" as *u8, 40); return 10 } 29 let op: *i64 = ctx.out_pos 30 let end: i64 = *op 31 expand_buf[end] = 0 as u8 32 33 let toks: *Tok = lex_source(expand_buf, 262144) 34 if toks == (0 as *Tok) { sys_write(2, "nx_vcc_color_wat: lex failed\n" as *u8, 29); return 2 } 35 let m: *Module = parse_module(toks, 0 as *Module) 36 if m == (0 as *Module) { sys_write(2, "nx_vcc_color_wat: parse failed\n" as *u8, 31); return 3 } 37 if m.n_functions <= 0 { sys_write(2, "nx_vcc_color_wat: no functions\n" as *u8, 31); return 4 } 38 39 var fi: i64 = 0 40 while fi < m.n_functions { 41 let f: *Function = ((m.functions as i64) + fi * 176) as *Function 42 opt_run(f) 43 fi = fi + 1 44 } 45 46 let o: *OutBuf = out_new(VCC_OUT_CAP) 47 wat_emit_module(m, o) 48 let fd: i64 = sys_openat_wr(out_path, 0x1a4) 49 if fd < 0 { sys_write(2, "nx_vcc_color_wat: open out failed\n" as *u8, 34); return 7 } 50 sys_write(fd, o.buf, o.pos) 51 sys_close(fd) 52 sys_write(1, "nx_vcc_color_wat: wrote WAT bytes=" as *u8, 34) 53 // print o.pos 54 let nb: i64 = o.pos 55 let bb: *u8 = sys_mmap(28); var x: i64 = nb 56 if x == 0 { sys_write(1, "0" as *u8, 1) } else { 57 var d: i64=0; var y: i64=x 58 while y>0 { d=d+1; y=y/10 } 59 var k: i64=d-1; y=x 60 while k>=0 { bb[k]=(48+(y%10)) as u8; y=y/10; k=k-1 } 61 sys_write(1, bb, d) 62 } 63 sys_write(1, "\n" as *u8, 1) 64 return 0 65}