Advanced Tools

WebAssembly is supported by a number of tools to help developers build and process source files and generated binary content. If you’re a compiler writer, enjoy low level coding or just want to experiment with the raw WebAssembly format, these tools are for you.

There are currently two distinct sets of tools that are of interest to compiler writers or developers who want to work with WebAssembly binary generated by other tools like Emscripten:

  • WABT - The WebAssembly Binary Toolkit
  • Binaryen - Compiler and toolchain infrastructure

WABT: The WebAssembly Binary Toolkit

WABT (we pronounce it “wabbit”) is a suite of tools for WebAssembly, including:

wasm2wat tool

This is a command line tool that takes a binary file as input and generates an output file containing the readable text.

Developers could edit or manipulate the text file in some other way and convert it back into the binary format for things like trying out optimization algorithms, tracing, inserting debugging hooks, etc.

wat2wasm tool

This is a command line tool that performs the inverse of wasm2wast, i.e. it converts files from the WebAssembly test format into WebAssembly binaries.

Using wasm2wat and wat2wasm together allows lossless round tripping of WebAssembly binaries, and provides developers with a convenient way to manipulate the content of WebAssembly binaries using external tools.

wasm-objdump tool

This is a command line tool for inspecting WebAssembly binary files. It works in a similar fashion to that tradition UNIX objdump and can, amongst other things, be used to disassemble to code in a WebAssembly binary.

wasm-interp tool

This is an interpreter that lets developers run a WebAssembly binary from the command line stand-alone. It implements a stack-machine based interpreter that interprets the WebAssembly binary directly. This differs from how a browser would JIT the WebAssembly binary into native code for its target architecture at load time.

The interpreter can be useful for running unit tests, validating WebAssembly binary files, etc. outside of a browser environment.

Binaryen

Binaryen is a comprehensive set of tools with supporting infrastructure for use as the backend of compilers that are targeting WebAssembly as an output format. It has a C API and implements its own internal intermediate representation (IR) of program logic and can perform a number of optimizations on the IR, support parallelization of code generation, etc.

For example, binaryen is used as part of the compiler asm2wasm that can convert asm.js files into WebAssembly files. It’s also used for supporting the LLVM compiler infrastructure generation of WebAssembly and compilation from Rust.

Developers working on compilers, advanced optimization techniques and so forth should take advantage of binaryen and its tools that include a shell that can load and interpret WebAssembly code, assembler and disassembler, converters for asm.js and LLVM .s files into WebAssembly and so on.

Tool developers are highly encouraged to explore the full set of functionality implemented by binaryen.