Skip to main content

Module func

Module func 

Source
Expand description

Per-function WebAssembly lowering: a region of VM bytecode (&[Op], a register machine) → a WebAssembly function (a stack machine with i64 locals).

§Control flow

VM bytecode uses absolute jumps; WebAssembly has only structured control flow. The lowering splits the region into basic blocks and emits the standard dispatch loop: a loop wrapping blocks nested one-per-basic-block, with a br_table on a “next block” local at the bottom. Each block runs its arithmetic, then sets the next-block index and re-dispatches (br to the loop) — or returns. This translates any reducible (and irreducible) control flow correctly, not just recognized patterns.

§Eligibility (Phase 6 deopt-at-concurrency, mirrored)

Only integer regions are emitted: const/move/arith/compare/jump/return. Any op outside that set — every concurrency / channel / networking op included — makes compile_region_to_wasm return None, so the region stays on the bytecode tier (a yield-free emitted module by construction, exactly like the native backend’s deny-list).

This is the byte emitter both the browser WASM-JIT tier (super::region_jit) and the direct AOT backend consume; it depends only on super::encode, not on the wasm-jit feature.

Functions§

compile_function_to_wasm
Lower function fi of a compiled program to a WebAssembly module — the integration entry the VM’s tier-up uses. A function’s body lives in the shared program.code from its entry_pc until the next function’s entry (or the program end), with absolute jump targets; this extracts that slice and rebases every jump into the region-local 0-based space compile_region_to_wasm expects. Returns None (stay on bytecode) if the body leaves the integer fragment or a jump escapes the function.
compile_region_to_wasm
Lower an integer region to a WebAssembly module exporting one function f of num_params i64 parameters returning i64. VM registers map 1:1 to WASM locals (0..num_params params, num_params..num_regs declared i64 locals); one extra i32 local at index num_regs is the dispatch “next block” index.