wasm2js
The wasm2js
tool converts WASM/WAST files into JavaScript files. Let's look at the steps:
- Create a file called
add-with-export.wast
:$ touch add-with-export.wast
Then, add the following code:
(module (export "add" (func $add)) (func $add (param $x i32) (param $y i32) (result i32) (i32.add (local.get $x) (local.get $y) ) ) )
- In order to convert the WebAssembly text format into JavaScript using
wasm2js
, run the following command:$ /path/to/build/directory/of/binaryen/wasm2js add- with-export.wast
This will print out the generated JavaScript:
function asmFunc(global, env) ...