LinuxCommandLibrary

wat2wasm

Convert WebAssembly text format to binary

TLDR

Parse and check a file for errors

$ wat2wasm [file.wat]
copy

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

Display simplified representation of every byte
$ wat2wasm [[-v|--verbose]] [file.wat]
copy

SYNOPSIS

wat2wasm [options] input.wat -o output.wasm

PARAMETERS

input.wat
    The input file in WebAssembly Text format (WAT).

-o output.wasm
    Specifies the output file for the generated WebAssembly binary. If not specified, output is written to standard output.

--output=output.wasm
    Same as -o output.wasm, specifies the output file.

--debug-names
    Emit section containing debug names.

--enable-gc
    Enable garbage collection (GC) features.

--enable-threads
    Enable threads features.

--enable-exceptions
    Enable exceptions features.

--enable-all
    Enable all features. It is equivalent to use all flags like --enable-gc --enable-threads --enable-exceptions

--no-check
    Disable validation of the input WebAssembly Text format.

--help
    Display help information.

--version
    Display version information.

DESCRIPTION

The wat2wasm command is a crucial component of the WebAssembly (Wasm) toolchain. It's a command-line utility that translates WebAssembly Text format (WAT) into the binary WebAssembly format (Wasm). WAT provides a human-readable representation of Wasm modules, making it easier for developers to write, inspect, and debug WebAssembly code. wat2wasm enables developers to compile these WAT files into the efficient, compact binary format that web browsers and other Wasm runtimes can execute. This command essentially acts as an assembler for WebAssembly, converting the high-level, text-based source code into the low-level, binary machine code.
The generated Wasm file can then be used within web applications, server-side environments, or embedded systems. Its primary function is to facilitate the compilation process from a developer-friendly textual format to a machine-executable binary format for WebAssembly.

CAVEATS

wat2wasm requires a properly formatted WAT file as input. Incorrect syntax or semantic errors in the WAT file will result in compilation failures. Feature flags like --enable-gc are tied to specific WebAssembly proposals and may not be supported by all runtimes.

<B>EXAMPLE</B>

To compile a WAT file named my_module.wat into a Wasm file named my_module.wasm, use the command: wat2wasm my_module.wat -o my_module.wasm

HISTORY

wat2wasm was developed as part of the WebAssembly project to provide a tool for converting the human-readable WebAssembly Text format into the binary format. It has been continuously updated and improved along with the evolution of the WebAssembly standard, with new features and optimizations added to support the latest WebAssembly proposals. It's a core part of the WebAssembly toolchain and widely used by developers working with WebAssembly.

SEE ALSO

Copied to clipboard