How does this work? Is this expanding the VM instructions into C code and thus provides some ahead-of-time compilation of WASM code? The README is quite terse.
If your host system is able to build wasm2c, you want something production-ready, and translation speed and memory usage are not a concern, then you are probably better off with wasm2c.
Retrocomputing is actually exactly the reason why I started w2c2.
C is a fine compiler target to be honest. It’s a lot less exciting than you’d think, but it works for the output of compilers. Not to mention gcc can probably do some crazy optimization when you compile things for native code.
How does this work? Is this expanding the VM instructions into C code and thus provides some ahead-of-time compilation of WASM code? The README is quite terse.
Correct, it ahead-of-time compiles the WASM instructions to equivalent C code.
Here is a blog post by the author of wasm2c, another compiler which translates WASM to C (wasm2c was the inspiration for w2c2), which explains the approach and uses: https://kripken.github.io/blog/wasm/2020/07/27/wasmboxc.html.
Here is an example of the input and output using wasm2c (w2c2 is very similar): https://github.com/WebAssembly/wabt/tree/main/wasm2c#a-quick-look-at-facc
Is there a reason to use this over wasm2c if I am fine with C++? I mostly consider C a retrocomputing language at this point.
If your host system is able to build wasm2c, you want something production-ready, and translation speed and memory usage are not a concern, then you are probably better off with wasm2c.
Retrocomputing is actually exactly the reason why I started w2c2.
Volodymyr of wasm3 fame did a nice analysis / comparison here: https://github.com/turbolent/w2c2/issues/1
C is a fine compiler target to be honest. It’s a lot less exciting than you’d think, but it works for the output of compilers. Not to mention gcc can probably do some crazy optimization when you compile things for native code.
Some people are questioning C vs C++, but given the goals I think C is probably the correct choice (at least for output).
My question is why C89. Seriously?
wasm2c also output C. It’s just implemented in C++.
C89, cause retrocomputing.
Oh the goal to run the wash on older arches that don’t have modern compilers? (I use modern loosely here :D )
Yes, seriously. This allows e.g. compiling to NeXTSTEP 3.3 which has gcc 2.5.8 and was released in 1995.
https://twitter.com/turbolent/status/1473666308596248580