-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathir.rs
More file actions
44 lines (37 loc) · 1.37 KB
/
ir.rs
File metadata and controls
44 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2025-2026 Neil Henderson
//
//! The `ir` module is responsible for lowering the C AST into the "BlueTac" intermediate representation (IR).
//!
//! BlueTac is a custom three-address code (TAC) IR for the BlueC compiler.
//! In the future, we'll add a lower-level IR in SSA form.
mod bluetac;
mod label_maker;
mod printer;
mod translator;
#[cfg(test)]
mod tests;
use crate::codegen;
use crate::compiler_driver;
use crate::parser;
use crate::sema::constant_table::ConstantTable;
use crate::sema::symbol_table::SymbolTable;
pub use bluetac::{
BtBinaryOp, BtConstantValue, BtDefinition, BtFunctionDefn, BtInstruction, BtLabelIdentifier, BtRoot,
BtStaticConstant, BtStaticStorageInitializer, BtStaticStorageVariable, BtSwitchCase, BtType, BtUnaryOp, BtValue,
};
/// Lowers the C AST produced by the parser into BlueTac intermediate representation (IR), and then passes
/// the generated IR to the codegen stage.
pub fn translate(
driver: &mut compiler_driver::Driver,
ast: parser::AstRoot,
metadata: parser::AstMetadata,
symbols: SymbolTable,
constants: ConstantTable,
) {
let (bt_root, symbols, constants) = translator::translate_ast_to_ir(ast, metadata, symbols, constants, driver);
if driver.options().print_ir {
printer::print(&bt_root, &symbols, &constants);
return;
}
codegen::codegen(driver, bt_root, symbols, constants);
}