Add wasm2elf: i32 WebAssembly to static x86-64 ELF compiler in MoonBit

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-21 00:53:04 -08:00
commit b8617c7aaa
22 files changed
+1219

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
# 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/`.