nx_ir_validate.nx
buildroot/runtime/nx_ir_validate.nx
about
ir_validate.nx -- structural invariants on the in-memory IR.
Mirrors what nxc2/ir_validate.c does for the C anchor, ported to
run inside nxc.elf so the sovereign pipeline can self-check.
Catches the class of bug that bit us 2026-04-25:
* BR / BR_COND op_X references a block id past f.n_blocks
(the dangling-label landmine).
* BR / BR_COND op_X disagrees with bb.succ0 / bb.succ1
(the stale-pointer landmine).
* A block listed in f.blocks has a different .id than its
position (the compaction-skew landmine).
Designed to run AFTER each opt pass. When an invariant breaks,
the validator prints {function name, pass label, block id,
invariant code, instr op} to stderr and returns the count of
violations. Caller decides whether to abort or continue.
Design rule: validator reads f only -- no writes. Safe to
invoke between any two passes without altering pipeline behavior.
dependencies 3 imports · 7 importers
imports: nx_types.nxnx_syscalls.nxnx_ir.nx
imported by: ir_validate.nxnx_compile_wat.nxnx_compile_x86.nxnx_dom_oracle_gate.nxnx_nxc.nxnx_vcc_color_wat.nxnx_vcc_probe_wat.nx
structs
| none |
consts
| none |
functions
| 33 | func iv_putc(c: i64) -> i64 |
| 40 | func iv_puts(s: *u8) -> i64 |
| 47 | func iv_putd(v: i64) -> i64 |
| 72 | func iv_violation(f: *Function, pass_label: *u8) -> i64 |
| 89 | func ir_validate_function(f: *Function, pass_label: *u8) -> i64 |
| 261 | func ir_validate_module(m: *Module, pass_label: *u8) -> i64 |