← Back to Home

Intermediate Representation (IR)

Flattening the AST into 3-Address Code

Bridging the Gap

Translating a highly nested Abstract Syntax Tree directly into x86-64 assembly is incredibly difficult. Instead, modern compilers translate the AST into an Intermediate Representation (IR). This acts as a universal bridge between the front-end (Parser) and the back-end (Code Generator).

Under the Hood (ir.c Logic)

Your compiler uses a Post-Order Walk (walk_ast) to generate IR. Here is exactly what happens behind the scenes:

Interactive IR Generator

Watch how the compiler traverses the complex AST from the bottom-up. Every time an operator resolves, it emit()s a Quad instruction and replaces the AST branch with a single Temporary Variable!

Target Code: x = (a + b) * (c - d);

AST Collapse (Input)

Generated IR Stream (Output)