Skip to content

wabt — The Binary Toolkit

wabt — the WebAssembly Binary Toolkit — is the reference implementation for the WAT text format. Every conversion, inspection, or validation task that touches the text ↔ binary boundary goes through one of its four main programs.

wat2wasm is the primary compiler. It parses .wat source, type-checks it, and emits a conforming .wasm binary. Useful flags include --debug-names (preserve $name annotations in the binary’s name section) and --output / -o to control the output file.

Terminal window
# Basic compilation
wat2wasm add.wat -o add.wasm
# Keep debug names in the binary
wat2wasm add.wat --debug-names -o add.debug.wasm
# Validate only, don't write output
wat2wasm add.wat --no-check=false --output=/dev/null

wasm2wat reverses the process: it reads a .wasm binary and emits readable WAT text. This is invaluable when you want to inspect what a higher-level compiler (Emscripten, wasm-pack, etc.) actually produced.

Terminal window
# Disassemble to stdout
wasm2wat add.wasm
# Disassemble to a file
wasm2wat add.wasm -o add.wat
# Include source locations from the DWARF section
wasm2wat add.wasm --generate-names

wasm-objdump prints structured metadata about a .wasm file — its section layout, imports, exports, and function signatures — without producing a WAT disassembly. Use -x for a full summary or -d to disassemble only the code section.

Terminal window
# Full section summary
wasm-objdump -x add.wasm
# Disassemble code section only
wasm-objdump -d add.wasm
# Show only the export section
wasm-objdump -j export add.wasm

A typical -x output looks like this:

Terminal window
add.wasm: file format wasm 0x1
Section Details:
Type[1]:
- type[0] (i32, i32) -> i32
Function[1]:
- func[0] sig=0
Export[1]:
- func[0] <add> -> "add"
Code[1]:
- func[0] size=7

wasm-validate checks that a binary conforms to the WebAssembly specification. It exits with code 0 on success and prints a diagnostic on failure. Use it in CI to catch corrupted or invalid modules before they reach production.

Terminal window
# Validate a module
wasm-validate add.wasm
# → add.wasm: OK
# Validate a module with a future proposal
wasm-validate --enable-threads shared.wasm

The four bytes at offset 0 of every valid .wasm file are 00 61 73 6d — the module magic (\0asm). The runnable below compiles a minimal WAT module and logs both the binary length and those four magic bytes, making the compilation process concrete.

WebAssembly
Which flag tells wat2wasm to keep $name annotations in the output binary?
What are the first four bytes of every valid .wasm file?
Which wabt tool prints section headers and exports without a full disassembly?
What exit code does wasm-validate return on a valid module?