Converting WASM into C
WABT has a wasm2c
converter that converts WASM into C source code and a header.
Let's create a simple.wat
file:
$ touch simple.wat
Add the following contents to simple.wat
:
(module (func $uanswer (result i32) i32.const 22 i32.const 20 i32.add ) )
wat
here defines a uanswer
function that adds 22
and 20
to give 42
as the answer. Let's create a WebAssembly binary using wat2wasm
:
$ /path/to/build/directory/of/wabt/wat2wasm simple.wat -o simple.wasm
This generates the simple.wasm
binary. Now, convert the binary into C code using wasm2c
:
$ /path/to/build/directory/of/wabt/wasm2c simple.wasm -o simple.c
This generates simple.c
and simple.h
.
Note
Both simple.c
and simple.h
might look huge. Remember this is an autogenerated...