$ show WebAssembly/binaryen
Binaryen is a production-grade compiler and toolchain infrastructure library for WebAssembly, written in C++. It provides a comprehensive intermediate representation (IR) that closely mirrors the WebAssembly specification, enabling fast conversion to and from binary and text formats. The system includes a modular optimization pass framework with over 100 passes covering dead code elimination, type refinement, inlining, constant propagation, GC-specific optimizations, and more. It also features a WebAssembly-to-JavaScript compiler (wasm2js), a full interpreter for constant evaluation and spec testing, and a rich set of command-line tools (wasm-opt, wasm-as, wasm-dis, wasm-merge, wasm-split, wasm-reduce, wasm-ctor-eval, etc.). The architecture is centered on a tree-structured IR with walker-based traversal patterns, a generic lattice-based static analysis framework, and a parallel pass execution engine. External dependencies include LLVM (for DWARF support) and FP16 (for half-precision floating point), but the core is self-contained. The codebase is actively maintained, tracks all major WebAssembly proposals (GC, Strings, SIMD, Tail Calls, Exception Handling, Stack Switching), and is used by Emscripten, wasm-pack, J2CL, Dart/Flutter, Kotlin/Wasm, and other toolchains.
The LLM identified 5 files worth highlighting for reuse:
A fixed-capacity vector implementation that stores up to N elements inline without heap allocation, falling back to std::vector for larger sizes. It provides a drop-in replacement for std::vector in performance-critical paths where small sizes are common. The implementation is generic, header-only, and has no dependencies on Binaryen internals, making it directly reusable in any C++ project.
An interned string type (IString) that provides O(1) comparison and hashing by storing strings in a global pool. It supports both static (compile-time) and dynamic (runtime) interning, with a compact representation using a single pointer. The implementation is self-contained and can be extracted for any project requiring efficient string identity operations.
A generic flat lattice implementation for abstract interpretation, representing values as either Top (unknown), Bottom (unreachable), or a concrete element of type T. It provides join, meet, and comparison operations following lattice theory. The template is parameterized on the element type and a comparator, making it reusable for any domain requiring a flat lattice structure.
An implementation of the Valmari-Lehtinen algorithm for minimizing deterministic finite automata (DFA). It takes a partition refinement approach with O(n log n) complexity. The algorithm is generic, operating on any state type via a CRTP interface, and has no dependencies on Binaryen-specific code. It can be extracted for use in any project requiring DFA minimization.
A thread-aware arena allocator that allocates memory in large chunks and provides fast allocation/deallocation for AST nodes. It supports both typed and untyped allocations, with optional thread-local caching for parallel passes. The implementation is self-contained and can be reused in any project needing efficient bulk allocation of short-lived objects.