wasm.nx
buildroot/runtime/wasm.nx
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
imports: syscalls.nxtypes.nxir.nxoutbuf.nx
imported by: wasm_test.nx
structs
| none |
consts
| none |
functions
| 28 | func wat_push_operand(f: *Function, o: *OutBuf, ind: i64, v: i64) -> i64 { |
| 43 | func wat_store_result(o: *OutBuf, ind: i64, v: i64) -> i64 {
called by 5: wat_emit_binopwat_emit_cmpwat_emit_callwat_emit_f32wat_emit_instr calls 3: out_indentout_strout_char |
| 53 | func wat_binop_mnem(op: i64, o: *OutBuf) -> i64 { |
| 68 | func wat_cmp_mnem(op: i64, o: *OutBuf) -> i64 { |
| 80 | func wat_emit_binop(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
called by 1: wat_emit_instr calls 5: wat_push_operandout_indentwat_binop_mnemout_charwat_store_result |
| 90 | func wat_emit_cmp(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
called by 1: wat_emit_instr calls 6: wat_push_operandout_indentwat_cmp_mnemout_charout_strwat_store_result |
| 103 | func wat_emit_call(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 { |
| 127 | func wat_emit_return(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 { |
| 138 | func wat_emit_branch(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 { |
| 182 | func wat_emit_f32(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 { |
| 218 | func wat_emit_instr(f: *Function, o: *OutBuf, ind: i64, i: *Instr) -> i64 {
called by 1: wat_emit_function calls 11: wat_emit_binopwat_emit_f32wat_emit_cmpwat_emit_callwat_emit_returnwat_emit_branch+5 |
| 267 | func wat_emit_function(f: *Function, o: *OutBuf) -> i64 { |
| 407 | func wat_emit_module(m: *Module, o: *OutBuf) -> i64 { |