21 releases (7 breaking)

Uses new Rust 2024

0.8.0-pre.10 Nov 26, 2025
0.8.0-pre.8 Jul 24, 2025
0.4.0 Mar 9, 2025
0.3.0 Dec 28, 2024

#2475 in Web programming


Used in 2 crates

MPL-2.0 license

525KB
11K SLoC

Three-Address Code (TAC) intermediate representation for JavaScript.

This crate provides a TAC representation for JavaScript/ECMAScript code, serving as an intermediate layer between the Control Flow Graph (CFG) and Static Single Assignment (SSA) forms in the compilation pipeline.

Three-Address Code

TAC is a linear intermediate representation where each statement performs at most one operation and uses at most three operands (typically: two sources and one destination). This form makes data flow analysis and optimization easier than working directly with the AST or CFG.

Key Types

  • TFunc: A complete function in TAC form, including its control flow graph
  • TCfg: The control flow graph containing basic blocks and metadata
  • TBlock: A single basic block containing a sequence of statements
  • TStmt: A single statement assigning a value to a left-hand side identifier
  • TTerm: A block terminator (return, jump, conditional branch, etc.)
  • Item: The right-hand side of an assignment (operation, literal, call, etc.)
  • [LId]: A left-hand side identifier (simple variable, member access, or private field)

Example Flow

JavaScript code is transformed through these stages:

  1. Parse to AST (using SWC)
  2. Convert to CFG (using swc-cfg)
  3. Lower to TAC (this crate)
  4. Transform to SSA (using swc-ssa)

Modules

  • consts: Constant evaluation and propagation
  • conv: Conversion from CFG to TAC
  • [lam]: Lambda (function) handling and atom resolution
  • prepa: Preparation and preprocessing passes
  • [rew]: Rewriting and transformation passes
  • splat: Object and array spreading operations

Dependencies

~25–39MB
~545K SLoC