IR生成文件即IRGenxx设计

This commit is contained in:
jing
2025-12-29 20:30:16 +08:00
parent e1c1f2a40d
commit bb7f42e06e
7 changed files with 166 additions and 0 deletions

View File

@@ -2,3 +2,28 @@
// - 处理全局变量与局部变量声明
// - 处理数组初始化、空间分配与初值生成等
#include "irgen/IRGen.h"
#include <memory>
#include "ast/AstNodes.h"
#include "ir/IR.h"
void IRGenImpl::GenBlock(const ast::Block& block) {
for (const auto& decl : block.varDecls) {
GenVarDecl(*decl);
}
for (const auto& stmt : block.stmts) {
GenStmt(*stmt);
}
}
void IRGenImpl::GenVarDecl(const ast::VarDecl& decl) {
ir::Value* init = nullptr;
if (decl.init) {
init = GenExpr(*decl.init);
} else {
init = ir::DefaultContext().GetConstInt(0);
}
locals_[decl.name] = init;
}