hn.today

WASM to Go Source Code

github.com4 points0 comments
Screenshot of WASM to Go Source Code

wasm2go is an ahead-of-time compiler that converts a WebAssembly binary into standalone Go source code so the resulting package runs natively without an interpreter or embedded wasm runtime. Generated output is dual-arch: each function gets amd64.s and arm64.s bodies produced by an SSA-based register allocator (block-local regalloc, cross-block stack allocation, m-pointer caching, slot reuse, peephole optimizations and branch-fusion) and a pure-Go fallback selected by build constraints for other GOOS/GOARCH targets. The asm and pure-Go paths expose the same New()/exported-method API so callers are unchanged. Translating supports dead-code elimination, multi-file splitting for large modules, memory-promotion reporting, bulk-export handling and other automatic layout decisions.

Usage includes a CLI (wasm2go -i module.wasm -o module.go -pkg mymodule) and an importable transpile package exposing Transpile/Parse/Translate hooks and options. When a module imports wasi_snapshot_preview1, native Go implementations of preview1 calls are emitted using only the standard library and build for all supported GOOS. Performance measurements show large wins versus a wazero-driven runtime: cold compile reduced ~4.67s→0.56s (8.4×) and short, call-bound queries sped up 18-81×, while long scan-heavy queries are within ±10%; per-call allocations also fall. Development targets, build/test/lint recipes and an MIT license are included.

Read on github.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.