fix(ast): 删掉ast结构
This commit is contained in:
@@ -1,26 +1,28 @@
|
||||
// 函数翻译模块:
|
||||
// - 处理函数定义、参数列表与返回值翻译
|
||||
// - 创建并填充对应的 IR Function 对象
|
||||
|
||||
#include "irgen/IRGen.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "ast/AstNodes.h"
|
||||
#include "SysYParser.h"
|
||||
#include "ir/IR.h"
|
||||
|
||||
IRGenImpl::IRGenImpl(ir::Module& module)
|
||||
: module_(module),
|
||||
func_(module_.CreateFunction("main", ir::Type::Int32())),
|
||||
builder_(func_->entry()) {}
|
||||
: module_(module), func_(nullptr), builder_(nullptr) {}
|
||||
|
||||
void IRGenImpl::Gen(const ast::CompUnit& ast) {
|
||||
if (!ast.func || !ast.func->body) {
|
||||
throw std::runtime_error("[irgen] AST 不完整:缺少 main 定义");
|
||||
void IRGenImpl::Gen(SysYParser::CompUnitContext& cu) {
|
||||
if (!cu.funcDef()) {
|
||||
throw std::runtime_error("[irgen] 缺少 main 定义");
|
||||
}
|
||||
GenBlock(*ast.func->body);
|
||||
GenFuncDef(*cu.funcDef());
|
||||
}
|
||||
|
||||
std::unique_ptr<ir::Module> IRGenImpl::TakeModule() {
|
||||
return std::make_unique<ir::Module>(std::move(module_));
|
||||
void IRGenImpl::GenFuncDef(SysYParser::FuncDefContext& func) {
|
||||
if (!func.block()) {
|
||||
throw std::runtime_error("[irgen] 函数体为空");
|
||||
}
|
||||
|
||||
func_ = module_.CreateFunction("main", ir::Type::Int32());
|
||||
builder_.SetInsertPoint(func_->entry());
|
||||
locals_.clear();
|
||||
|
||||
GenBlock(*func.block());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user