Appendix C: Further Reading
#The specificationC.1
The WebAssembly specification, at webassembly.github.io/spec, is
unusually readable for a standard. Its structure section defines the
abstract syntax; validation gives the typing rules as inference rules
(Chapter 6's stack typing, precisely); execution defines what each
instruction does; and the binary and text format sections are the
definitive references for Part IV. The JavaScript API and Web API
specifications, beside it, define everything in Part V.
Proposals each have a repository under github.com/WebAssembly, with an
overview document explaining the design and its motivation. The
overviews for exception handling, GC, tail calls, threads and relaxed SIMD
are the best introductions to those features after this book.
webassembly.org/features tracks which engines support which proposals.
The tool conventions repository, WebAssembly/tool-conventions,
documents what is not part of the standard but is shared by toolchains:
the C ABI, the linking and relocation format of object files, the
producers section, DWARF usage, and the dynamic linking convention.
#PapersC.2
- Andreas Haas, Andreas Rossberg, Derek L. Schuff, Ben L. Titzer, Michael Holman, Dan Gohman, Luke Wagner, Alon Zakai and JF Bastien, Bringing the Web up to Speed with WebAssembly, PLDI 2017. The design paper: why the format looks as it does, including structured control flow and validation.
- Conrad Watt, Mechanising and Verifying the WebAssembly Specification, CPP 2018. The formal proof of the type system's soundness, which caught real bugs in the specification.
- Alon Zakai, Emscripten: an LLVM-to-JavaScript Compiler, SPLASH 2011. Introduces the Relooper.
- Norman Ramsey, Beyond Relooper: Recursive Translation of Unstructured Control Flow to Structured Control Flow, ICFP 2022. The algorithm of Chapter 7, explained clearly.
- Abhinav Jangda, Bobby Powers, Emery D. Berger and Arjun Guha, Not So Fast: Analyzing the Performance of WebAssembly vs. Native Code, USENIX ATC 2019. Where the overhead comes from.
#Compilers to readC.3
The best way to learn how to target WebAssembly is to read the output of
existing compilers, with wasm2wat or wasm-objdump -d, for small
programs in their source languages:
- Clang and LLVM (C, C++, and the basis of Rust, Zig, Odin and
others): the
WebAssemblybackend, especiallyWebAssemblyCFGStackifyfor control flow and the frame lowering for the shadow stack. - Emscripten: the complete toolchain around LLVM, including the JavaScript runtime, and the place to see the boundary patterns of Chapter 16 at full scale.
- Binaryen: a model of a WebAssembly-specific optimiser, with an IR close to the format.
- Kotlin/Wasm, Dart and J2Wasm: production compilers targeting WasmGC.
- Wasmtime and Cranelift: an engine whose source is easier to read than a browser's, for seeing how modules are compiled to machine code.
- V8's blog (
v8.dev/blog): articles on Liftoff, TurboFan's WebAssembly pipeline, tiering, WasmGC, and the JS-to-Wasm call path.
#BooksC.4
- Robert Nystrom, Crafting Interpreters. Not about WebAssembly, but the clearest account there is of building a language implementation step by step, and a model for structuring a compiler project.
- Andrew Appel, Modern Compiler Implementation. Classic coverage of the middle of a compiler (IR, SSA, dominators, register allocation) that Chapter 7 and Chapter 24 lean on.
- Keith Cooper and Linda Torczon, Engineering a Compiler. The same ground with more on optimisation.