IR生成文件即IRGenxx设计
This commit is contained in:
@@ -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_));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user