LinuxCommandLibrary

wasm2wat

Convert WebAssembly binary files to WAT text

TLDR

Convert a file to the text format and display it to the console

$ wasm2wat [file.wasm]
copy

Write the output to a given file
$ wasm2wat [file.wasm] [[-o|--output]] [file.wat]
copy

SYNOPSIS

wasm2wat [options] [output.wat]

PARAMETERS

-o, --output=
    Specify the output file for the WAT representation. If not provided, the output is written to standard output.

--debug-names
    Include debugging names in the output WAT file. This makes the output more readable, especially when the Wasm module contains name sections.

--no-canonicalize-leb128s
    Disable canonicalizing LEB128 encodings. By default, LEB128 encodings are canonicalized.

--help
    Display help information about the command and its options.

--version
    Display the version of the `wasm2wat` tool.


    The input WebAssembly binary file to be converted.

[output.wat]
    Optional. The output WebAssembly text file. If not specified uses standard output.

DESCRIPTION

The `wasm2wat` command is a crucial part of the WebAssembly (Wasm) toolchain. It translates a WebAssembly binary file (``.wasm``) into its human-readable text equivalent, known as WebAssembly Text format (``.wat``). This conversion is invaluable for developers who need to inspect, debug, or understand the structure and logic of Wasm modules. The output WAT file represents the same functionality as the original Wasm binary but in a format that's easier to comprehend.

The command can be used to decompile optimized Wasm files, allowing developers to analyze how compilers transform source code into WebAssembly. It supports various options to control the output, such as printing to standard output, specifying the output file, and controlling the verbosity of the output.

`wasm2wat` is particularly useful during development to verify that the generated Wasm code is as intended. It is also helpful in analyzing existing Wasm libraries or applications when the original source code is unavailable.

EXAMPLES

1. Convert a Wasm file to WAT and print to standard output:
`wasm2wat input.wasm`

2. Convert a Wasm file to WAT and save to a file:
`wasm2wat input.wasm output.wat`

3. Convert a Wasm file to WAT and save to a file with debug names:
`wasm2wat --debug-names input.wasm output.wat`

SEE ALSO

Copied to clipboard