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,25 @@
// - 处理函数定义、参数列表与返回值翻译
// - 创建并填充对应的 IR Function 对象
#include "irgen/IRGen.h"
#include <stdexcept>
#include "ast/AstNodes.h"
#include "ir/IR.h"
IRGenImpl::IRGenImpl(ir::Module& module)
: module_(module),
func_(module_.CreateFunction("main", ir::Type::Int32())),
builder_(func_->entry()) {}
void IRGenImpl::Gen(const ast::CompUnit& ast) {
if (!ast.func || !ast.func->body) {
throw std::runtime_error("AST 不完整:缺少 main 定义");
}
GenBlock(*ast.func->body);
}
std::unique_ptr<ir::Module> IRGenImpl::TakeModule() {
return std::make_unique<ir::Module>(std::move(module_));
}