nx_nx86.nx
buildroot/runtime/nx_nx86.nx
about
nx_nx86.nx -- x86_64 assembly emitter from nx_nir IR, in NishiLang.
FOURTH AND FINAL CONCRETE STEP of the nxc2 self-hosting pipeline
(subset). Walks the IR produced by nx_nir and emits valid AT&T-
syntax x86_64 assembly into a string buffer.
Closes the loop: NishiLang source -> tokens -> AST -> IR -> asm.
All four steps written in NishiLang. Compiler-piece self-hosting
demonstrated.
Minimum opcode support:
NX_IR_CONST_I64 -> movabsq $val, %rax
NX_IR_RETURN -> mov %rbp, %rsp; popq %rbp; ret (epilogue)
Function emission:
.globl main
main:
pushq %rbp
movq %rsp, %rbp
<body>
<epilogue>
Output: byte buffer with assembly text + length.
dependencies 2 imports · 8 importers
imports: syscalls.nxnx_nir.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_nx86_test.nx
structs
| 28 | struct NxAsmBuf |
consts
| none |
functions
| 34 | func nx_asm_new(cap: i64) -> *NxAsmBuf |
| 43 | func nx_asm_putc(a: *NxAsmBuf, c: i64) -> i64 |
| 50 | func nx_asm_puts(a: *NxAsmBuf, s: *u8, n: i64) -> i64 |
| 60 | func nx_asm_put_i64(a: *NxAsmBuf, v: i64) -> i64 |
| 88 | func nx_asm_emit_static(a: *NxAsmBuf, b: *u8, n: i64) -> i64 calls 1: nx_asm_puts |
| 94 | func nx_nx86_emit_instr(a: *NxAsmBuf, ins: *NxInstr) -> i64 |
| 276 | func nx_nx86_emit_func(a: *NxAsmBuf, src: *u8, f: *NxIrFunc) -> i64 called by 8: mainmainmainmainmainmain+2 calls 4: nx_asm_putcnx_asm_put_i64nx_nir_instr_atnx_nx86_emit_instr |