Converting WAST into WASM
wat2wasm
helps to convert the WAST format into WASM. Let's take it for a spin:
- Create a new folder called
wabt-playground
and go into the folder:$ mkdir wabt-playground $ cd wabt-playground
- Create a
.wat
file calledadd.wat
:$ touch add.wat
- Add the following contents to
add.wat
:(module (func $add (param $lhs i32) (param $rhs i32) (result i32) get_local $lhs get_local $rhs i32.add ) )
- Convert the WAST format into WASM using the
wat2wasm
binary:$ /path/to/build/directory/of/wabt/wat2wasm add.wat
This generates a valid WebAssembly binary in add.wasm
file:
00 61 73 6d 01 00 00 00 01 07 01 60 02 7f 7f 017f 03 02 01 00 0a 09 01 07 00 20 00 20 01 6a 0b
Note that the size of the generated binary is 32 bytes.
- WABT reads the WAST format file (
.wat
) and converts it into a WebAssembly module (.wasm
).wat2wasm
first validates the given file (.wat
) and then converts it into a.wasm
file...