WAT to WASM Converter
Convert WAT (WebAssembly Text Format) files to WASM binary online. Paste or upload .wat code, validate syntax, and download the compiled .wasm file instantly.
About
WebAssembly Text Format (WAT) is the human-readable S-expression representation of WASM binary modules. Converting WAT to WASM requires lexical analysis, type validation, and binary encoding conforming to the WebAssembly Core Specification (W3C). A malformed module - incorrect type signatures, mismatched stack depths, or invalid section ordering - produces a binary that engines reject at instantiation. This tool performs full parsing and validation before emitting the binary, catching errors that a manual hex-editing workflow would miss entirely.
The output binary begins with the magic number 0x00 0x61 0x73 0x6D followed by version 0x01 0x00 0x00 0x00, then encodes each section (Type, Function, Memory, Export, Code) with LEB128-encoded lengths. This converter handles multi-value returns, bulk memory operations, and reference types. Note: this tool approximates the behavior of the wat2wasm CLI from the WebAssembly Binary Toolkit. Certain proposal-stage features (e.g., exception handling, GC types) may not be supported depending on the parser version loaded.
Formulas
The WASM binary format encodes all integers using LEB128 (Little Endian Base 128) variable-length encoding. An unsigned integer n is encoded as a sequence of bytes where each byte stores 7 data bits and 1 continuation bit:
Where n is the unsigned integer value, i is the byte index starting from 0, and the 0x80 high bit signals continuation. Signed LEB128 uses two's complement with sign extension on the final byte.
Module validation requires that the function type section declares signatures as vectors of value types: 0x7F (i32), 0x7E (i64), 0x7D (f32), 0x7C (f64). The magic number is 0x00 0x61 0x73 0x6D (ASCII: \0asm) and version is fixed at 0x01 0x00 0x00 0x00.
Reference Data
| WASM Section ID | Section Name | Description | Binary ID |
|---|---|---|---|
| 0 | Custom | Name annotations, debug info, metadata | 0x00 |
| 1 | Type | Function type signatures (params → results) | 0x01 |
| 2 | Import | External function, table, memory, global imports | 0x02 |
| 3 | Function | Maps function index to type index | 0x03 |
| 4 | Table | Indirect function call tables (funcref) | 0x04 |
| 5 | Memory | Linear memory declarations (pages of 64 KiB) | 0x05 |
| 6 | Global | Global variable declarations with mutability | 0x06 |
| 7 | Export | Exported functions, memories, tables, globals | 0x07 |
| 8 | Start | Module start function index (auto-invoked) | 0x08 |
| 9 | Element | Table element initialization segments | 0x09 |
| 10 | Code | Function bodies (locals + expression bytecode) | 0x0A |
| 11 | Data | Linear memory initialization segments | 0x0B |
| 12 | DataCount | Number of data segments (bulk memory proposal) | 0x0C |
Frequently Asked Questions
WebAssembly.instantiate() - if it throws a CompileError, the binary is malformed. The converter runs validation before emitting, so a successful conversion implies the binary passes engine-level validation.(func $add ...)), the converter emits a Name custom section in the binary. This is useful for debugging in browser DevTools, which display symbolic names from this section when inspecting WASM call stacks.