code wiki / (root) / wasm.nx

wasm.nx

buildroot/runtime/wasm.nx

15189 B424 linesdepth 5pulls 10 transitivereach 1 importersview sourcekind librarytopic wasm
docsdependenciesstructsconstsfunctions

about

wasm.nx -- NishiLang port of wasm.c (WAT backend). Lowers our SSA IR to WebAssembly Text format. The core challenge WAT imposes is structured control flow: there are no arbitrary branches, only block/loop/if scopes with break-to-label. Our IR has free-form CFG edges, so we use the universal block-dispatch pattern (`br_table` driven by a `$target` local) that encodes any CFG at small constant cost. Per-op semantics match wasm.c exactly; every Value gets a $vN local, comparisons extend to i64 after the i32 WASM result, and constants materialize inline as i64.const. Functions are prefixed `wat_` so they don't collide with riscv.nx's asm-side `rv_*` / `emit_*` naming when both libraries are imported into a driver.

dependencies 4 imports · 1 importers

syscalls.nx types.nx ir.nx outbuf.nx wasm.nx wasm_test.nx

imports: syscalls.nxtypes.nxir.nxoutbuf.nx

imported by: wasm_test.nx

structs

none

consts

none

functions

28func wat_push_operand(f: *Function, o: *OutBuf, ind: i64, v: i64) -> i64 {
43func wat_store_result(o: *OutBuf, ind: i64, v: i64) -> i64 {
53func wat_binop_mnem(op: i64, o: *OutBuf) -> i64 {
called by 1: wat_emit_binop calls 1: out_str
68func wat_cmp_mnem(op: i64, o: *OutBuf) -> i64 {
called by 1: wat_emit_cmp calls 1: out_str
80func wat_emit_binop(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
90func wat_emit_cmp(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
103func wat_emit_call(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
127func wat_emit_return(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
138func wat_emit_branch(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
182func wat_emit_f32(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
218func wat_emit_instr(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
267func wat_emit_function(f: *Function, o: *OutBuf) -> i64 {
407func wat_emit_module(m: *Module, o: *OutBuf) -> i64 {