Binaryen - WebAssembly Compiler and Toolchain

Mar 02, 2020 • ☕️ 1 min read

Binaryen has a simple C API in a single header. It accepts input in WebAssembly-like form but also accepts a general control flow graph for compilers that prefer that.

Binaryen’s internal Intermediate Representation (IR) uses compact data structures and is designed for completely parallel codegen and optimization, using all available CPU cores. Binaryen’s IR also compiles down to WebAssembly extremely easily and quickly because it is essentially a subset of WebAssembly.

Binaryen’s optimizer has many passes that can improve code very significantly, one specific area of focus is on WebAssembly-specific optimizations that general-purpose compilers might not do.

  • Wasm minification
  • Dead code elimination
  • Local coloring to coalesce local variables
  • Precomputing expressions when possible at compile time

Binaryen also provides a set of toolchain utilities that can:

  • Parse and emit WebAssembly
  • Interpret WebAssembly as well as run the WebAssembly spec tests
  • Integrate with Emscripten to provide a complete compiler toolchain from C/C++ to WebAssembly.
  • Polyfill WebAssembly by running it in the interpreter compiled to JavaScript, if the browser does not yet have native support (useful for testing)

Some compilers built using Binaryen include:

  • asm2wasm which compiles asm.js to WebAssembly
  • AssemblyScript which compiles TypeScript to Binaryen IR
  • wasm2js which compiles WebAssembly to JS
  • Asterius which compiles Haskell to WebAssembly

Reading More

On Expectation of Technical Blogging

Starting a technical blog is easy but maintaining it for a long period of time is a pain in the neck

Long-standing CSS Methodologies

The industry darling BEM, the rebellious maverick Atomic CSS, and other incompetent solutions

Web Security Common Threats

Common security threats to know before deploying a serious web app

CSS-in-JS Styling Technique

A different styling technique where CSS is composed using JavaScript instead of defined in external files