turbolent/w2c2
FreeTranslates WebAssembly modules to portable C
About turbolent/w2c2
w2c2 is an open-source tool that translates WebAssembly modules into portable C code, inspired by wabt's wasm2c. It implements the WebAssembly Core Specification 1.0 along with several extensions (threads, bulk memory, sign-extension, non-trapping float-to-int conversions) and passes 99.9% of the WebAssembly core semantics test suite. The tool is written in (mostly) C89 and generates (mostly) C89 output, supporting a wide range of operating systems (Mac OS X, Mac OS 9, Haiku, DOS, Windows XP, etc.), architectures (x86, ARM, PowerPC, SPARC, PA-RISC), compilers (old GCC, MSVC, CodeWarrior), and big-endian systems. Features include streaming/single-pass compilation with low memory usage, separate compilation into multiple files, parallel compilation when built with threading support, and generation of debug information (function names and source line mapping) via libdwarf. w2c2 also includes a WASI implementation capable of running clang and Python. Performance benchmarks show Coremark 1.0 runs about 7% slower than native.
Key Features
Pros & Cons
- High compliance with WebAssembly specification (99.9% test suite pass rate)
- Generates portable C89 code that runs on a vast array of operating systems, architectures, and compilers
- Streaming/single-pass compilation minimizes memory usage, ideal for large modules or limited resources
- Support for separate and parallel compilation to speed up builds and handle large modules
- Includes a built-in WASI implementation capable of running real-world applications like clang and Python
- Performance is close to native (Coremark 1.0: 7% slower), making it suitable for production use
- Can generate debug information for easier troubleshooting
- Open source and free to use
- Does not pass 100% of the WebAssembly core semantics test suite (99.9% pass rate, minor deviations)
- Debug info generation requires libdwarf, an external library
- Only generates C89 output, which may not leverage modern C features or compiler optimizations
- Performance is slightly slower than native (~7% on Coremark), though still competitive
- Some common C extensions are used in output; may not compile on extremely strict C89 compilers