WABT – the WebAssembly binary toolkit

WABT's focus is on the manipulation of WebAssembly binary (.wasm) files and text (.wat) files, as well as conversion between the two formats. WABT provides tools to translate Wat to Wasm (wat2wasm) and vice versa (wasm2wat), as well as a tool to convert a Wasm file to a C source and header file (wasm2c). You can view the entire list of tools in the README file of the WABT GitHub repository at https://github.com/WebAssembly/wabt.

One example use case of WABT is the WebAssembly Toolkit for VS Code extension we installed in Chapter 3Setting Up a Development Environment. The extension depends on WABT to view the text format associated with a .wasm file. The repository provides links to wat2wasm and wasm2wat demos, which you can use to test the validity of a Wat program or interact with a compiled binary using JavaScript. The following screenshot contains the Wat and JavaScript instantiation code from the wat2wasm demo:

Wat and JavaScript loading code from wat2wasm's "simple" example

In line 3 of the JS panel, you may have noticed that the addTwo() function from wasmInstance.exports isn't prefixed with a _. Emscripten adds the _ automatically in the compilation process. You could omit the _ by converting the .wasm file to a .wat, updating the function names, and converting it back to .wasm using the WABT, although this wouldn't be very practical. The WABT simplifies the process of transforming text format to binary format and vice versa. If you want to build compilation tooling for WebAssembly, you'd use Binaryen, which we will cover next.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset