wasm2wat
Convert WebAssembly binary files to WAT text
TLDR
Convert a file to the text format and display it to the console
Write the output to a given file
SYNOPSIS
wasm2wat [options] [input-file] [-o output-file]
PARAMETERS
input-file
The path to the input WebAssembly binary (.wasm) file. If omitted, input is read from standard input.
-o output-file
Specifies the path for the output WebAssembly text (.wat) file. If omitted, output is written to standard output.
-h, --help
Displays a help message with available options and exits.
-v, --version
Prints the version of wasm2wat and exits.
--fold-exprs
Formats expressions in the output by folding them, which can make the output more compact and easier to read for complex expressions.
--no-debug-names
Disables the output of debug names (e.g., for functions, locals, globals) that might be embedded in the .wasm file. This results in a smaller, more generic .wat output.
--inline-exports
Inlines exports directly into their definitions (e.g., function exports appear with the function definition), rather than listing them separately at the end of the module.
--enable-all
Enables all experimental WebAssembly proposals supported by wasm2wat. Use with caution, as some proposals might still be in flux.
--enable-exceptions
Enables the WebAssembly exceptions proposal, allowing the conversion of related instructions.
--enable-reference-types
Enables the WebAssembly reference types proposal, which introduces new types like funcref and externref.
--enable-simd
Enables the WebAssembly SIMD (Single Instruction, Multiple Data) proposal, for vector operations.
--enable-threads
Enables the WebAssembly threads proposal, including shared memory and atomic operations.
--enable-tail-call
Enables the WebAssembly tail call proposal, allowing for optimization of recursive calls.
--enable-multi-value
Enables the WebAssembly multi-value proposal, allowing functions to return multiple values and blocks to yield multiple values.
--enable-bulk-memory
Enables the WebAssembly bulk memory operations and reference type instructions proposal.
--enable-mutable-globals
Enables the WebAssembly mutable globals proposal, allowing global variables to be declared as mutable.
--enable-sign-extension
Enables the WebAssembly sign extension operations proposal.
--enable-nontrapping-fptoint
Enables the WebAssembly non-trapping float-to-int conversions proposal.
DESCRIPTION
wasm2wat is a fundamental utility from the WebAssembly Binary Toolkit (WABT), designed to convert a WebAssembly binary module (typically a .wasm file) into its human-readable text representation (a .wat file). WebAssembly (Wasm) is a low-level bytecode format optimized for high-performance execution, primarily in web browsers but also in serverless and embedded environments. While .wasm files are compact and efficient for machines, they are opaque and difficult for humans to interpret directly.
The WebAssembly Text Format (WAT) provides an S-expression-based syntax that mirrors the structure of the binary module. This conversion is invaluable for developers for several reasons: it enables debugging, allows for manual inspection of code generated by compilers (like Emscripten, Rust, or Go), and facilitates learning the WebAssembly instruction set. Developers can inspect the module's imports, exports, functions, types, and data segments in a clear, structured way. wasm2wat supports various WebAssembly proposals and features, offering command-line options to control the output format and enable experimental features, ensuring it stays current with the evolving WebAssembly standard.
CAVEATS
Converting very large .wasm files can result in excessively large .wat files, potentially making them difficult to view, search, or process with standard text editors. The output format and support for specific WebAssembly features can vary between different versions of wasm2wat; always ensure you are using a version compatible with your WebAssembly binary's origin and target environment. Enabling experimental features via --enable-* flags might produce .wat output that cannot be re-assembled by older wat2wasm versions or validated by tools that do not support those same proposals.
USAGE SCENARIOS
wasm2wat is indispensable for debugging Wasm modules, reverse-engineering compiled code, understanding the output of WebAssembly compilers (e.g., Emscripten, Rust's wasm32-unknown-unknown target), and learning the intricacies of the WebAssembly instruction set. It provides a textual representation that can be more easily analyzed and understood than raw binary data.
WEBASSEMBLY TEXT FORMAT (WAT)
The WebAssembly Text Format (WAT) uses a concise S-expression syntax, making it structured and relatively easy to parse by humans. It directly maps to the WebAssembly binary format, allowing developers to see the module's structure, functions (including their local variables, parameters, and return types), types, imports, exports, global variables, and data/element segments. This human-readable form is crucial for effective development and debugging.
HISTORY
wasm2wat is a core component of the WebAssembly Binary Toolkit (WABT), an open-source project primarily developed by Google engineers and contributors from the WebAssembly working group. WABT was created to provide essential command-line tools for working with WebAssembly modules, facilitating the development and debugging workflow before comprehensive browser developer tools for WebAssembly were widely available. wasm2wat has been a foundational part of WABT since its early days, evolving in lockstep with the WebAssembly specification itself, and continually integrating support for new proposals and features as they advance through the standardization process. Its development reflects the community's need for transparent inspection of the Wasm binary format.
SEE ALSO
wat2wasm(1), wasm-objdump(1), wasm-validate(1), wasm-interp(1), wasm-strip(1)