nx_nir.nx
buildroot/runtime/nx_nir.nx
about
nx_nir.nx -- NishiLang IR builder, in pure NishiLang.
THIRD CONCRETE STEP of the nxc2 self-hosting trajectory. Consumes
the AST produced by nx_nparse and emits IR instructions (mirroring
a subset of nxc2/ir.h's Opcode enum).
Minimum viable opcodes:
NX_IR_CONST_I64 (value in operand 0)
NX_IR_RETURN (value-id in operand 0)
NX_IR_ADD/SUB/MUL (operand 0 + 1 -> result)
SSA value-ids are dense integers (0, 1, 2, ...). Each NxInstr's
result_id is its own slot index. Operands reference earlier slots.
dependencies 3 imports · 10 importers
imports: syscalls.nxnx_nlex.nxnx_nparse.nx
imported by: _a2a_selfhost_binop.nx_a2a_selfhost_let.nx_selfhost_compile_42.nx_selfhost_compile_binop.nx_selfhost_compile_if.nx_selfhost_compile_if_false.nx_selfhost_compile_let.nxnx_nir_test.nxnx_nx86.nxnx_nx86_test.nx
structs
| 30 | struct NxInstr |
| 37 | struct NxIrFunc |
consts
| 20 | const NX_IR_CONST_I64: i64 = 1 |
| 21 | const NX_IR_RETURN: i64 = 2 |
| 22 | const NX_IR_ADD: i64 = 3 |
| 23 | const NX_IR_SUB: i64 = 4 |
| 24 | const NX_IR_MUL: i64 = 5 |
| 25 | const NX_IR_STORE_LOCAL: i64 = 6 // op0 = slot index, op1 = value-id |
| 26 | const NX_IR_LOAD_LOCAL: i64 = 7 // op0 = slot index, result = loaded value |
| 27 | const NX_IR_BR_IF_ZERO: i64 = 8 // op0 = value-id, op1 = label-id (jump if value is 0) |
| 28 | const NX_IR_LABEL: i64 = 9 // op0 = label-id (placeholder, emits .Lid:) |
functions
| 48 | func nx_nir_func_new(cap: i64) -> *NxIrFunc called by 1: nx_nir_lower_func |
| 62 | func nx_nir_new_label(f: *NxIrFunc) -> i64 called by 1: nx_nir_lower_stmt |
| 68 | func nx_nir_instr_at(f: *NxIrFunc, i: i64) -> *NxInstr |
| 72 | func nx_nir_emit(f: *NxIrFunc, opcode: i64, op0: i64, op1: i64) -> i64 |
| 86 | func nx_nir_lower_expr(f: *NxIrFunc, parser: *NxNParser, ast_idx: i64) -> i64 called by 2: nx_nir_lower_exprnx_nir_lower_stmt calls 3: nx_nparse_node_atnx_nir_emitnx_nir_lower_expr |
| 107 | func nx_nir_lower_stmt(f: *NxIrFunc, parser: *NxNParser, ast_idx: i64) -> i64 |
| 142 | func nx_nir_lower_block(f: *NxIrFunc, parser: *NxNParser, ast_idx: i64) -> i64 |
| 153 | func nx_nir_lower_func(parser: *NxNParser, func_ast_idx: i64, cap: i64) -> *NxIrFunc |