Overview
Lowering converts structured AST nodes into a flat sequence of three-address instructions, performing variable allocation and control flow linearization. Input:hir::TranslationUnit<'db> (via lower_program)Output:
tacky::Program<'db> (TAC IR)Modules:
crates/mcc/src/lowering/mod.rs, crates/mcc/src/lowering/tacky.rs
Entry Point
Pipeline Integration
Three-Address Code (TAC)
TAC is defined inlowering/tacky.rs:
Program Structure
Instructions
Values and Variables
Operators
Function Context
Lowering is stateful, managed byFunctionContext:
Body Lowering
return 0 ensures all control paths return.
Declaration Lowering
Expression Lowering
Expressions are lowered recursively, returning aVal:
Literals
Unary Expressions
Binary Expressions
&& and || requires special handling (see below).
Assignment
Control Flow Lowering
If Statements
Ternary Operator
Similar structure to if-else:Short-Circuit Logical Operators
Logical AND (&&):
||): Similar, but jumps to true case if left is non-zero.
Temporary Generation
Example
Input:Related Stages
- Previous: Typechecking – Produces HIR input
- Next: Code Generation – Converts TAC to assembly IR
- TAC Definition:
crates/mcc/src/lowering/tacky.rs