WebAssembly Fundamentals  /  WebAssembly Text Format

WebAssembly Text Format

Now that we have a good overview of WebAssembly and its goals, namely performance, efficiency, portability, and safety, it's time to start coding!

Hold on... WebAssembly is a binary format?! Does that mean we have to write binary? Luckily, the answer is no 🙌.

WebAssembly has two file types:

  • .wasm contains the Wasm bytecode
  • .wat is the human-readable textual representation of the bytecode

The bytecode can be represented in a human-readable, easily editable, and debuggable form called the WebAssembly Text Format (WAT). The text format is another intermediate representation for exposure in IDEs, browsers, or developer tools.

Why would we write it by hand if it's a compilation target?

Being able to write WebAssmebly by hand is actually quite handy. While the majority of tutorials and blog posts focus on specific toolchains, such as Emscripten for C++ or wasm-pack for Rust. However, as mentioned in the beginning, a deep understanding of WebAssembly and how its text format (WAT) fundamentally works is helpful in several ways:

  • It might explain why some code doesn't run as fast as you thought
  • You need to debug WebAssembly code, e.g., when running it in a browser
  • Even the small nature of WebAssembly's binary format produced by compilers such as LLVM isn't quite small enough
  • You want to implement your own compiler that compiles to WebAssembly
  • You already enjoy writing assembly code
  • Most importantly, it's an explorational and educational journey, and hopefully, you'll learn a few things along the way

Let's dive in!

Debugger
    • Not paused
    • Not paused
    • Not paused
  • Not paused