wasm2elf

A WebAssembly → static x86-64 Linux ELF compiler, written in MoonBit. No C, no LLVM, no runtime: the output is a single PT_LOAD segment with hand-encoded machine code.

wasm-tools parse examples/shine_rise.wat -o shine_rise.wasm
moon build --target native
_build/native/debug/build/cmd/main/main.exe shine_rise.wasm shine_rise [entry-export]
./shine_rise     # wasm trap: unreachable   (exit 134)

The entry export (default _start, then main, then the first function export) is called from _start; its i32 result becomes the exit code. Traps print a message to stderr and exit 134.

Supported: i32 only; locals, params, calls, block/loop/if/else/br/br_if/return, select/drop, all i32 arithmetic/comparison/shift/rotate ops, divide-by-zero and INT_MIN/-1 traps. Not supported: i64/floats, memory, globals, tables, imports, br_table. Input is assumed valid (wasm-tools validate it first). ./run_examples.sh builds and runs everything in examples/.

S
Description
i32 WebAssembly to static x86-64 ELF compiler in MoonBit
Readme Apache-2.0
111 KiB
0 Stars 1 Watchers 0 Forks
Languages
MoonBit 95.5%
Just 2.5%
AMPL 1.1%
Shell 0.9%