fix(ast): 删掉ast结构
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
// 这是一个“可跑”的最小 IR 生成示例,便于对照/调试。
|
||||
// IR 生成驱动(Driver):
|
||||
// - 驱动 Visitor 遍历 AST,调度各子模块完成翻译
|
||||
// - 统一管理模块级翻译入口与上下文(Module/IRBuilder 等)
|
||||
// - 组织函数/语句/表达式/声明等翻译流程
|
||||
|
||||
#include "irgen/IRGen.h"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "ast/AstNodes.h"
|
||||
#include "SysYParser.h"
|
||||
#include "antlr4-runtime.h"
|
||||
#include "ir/IR.h"
|
||||
|
||||
std::unique_ptr<ir::Module> GenerateIR(const ast::CompUnit& ast) {
|
||||
std::unique_ptr<ir::Module> GenerateIR(antlr4::tree::ParseTree* tree) {
|
||||
if (!tree) {
|
||||
throw std::runtime_error("[irgen] parse tree 为空");
|
||||
}
|
||||
|
||||
auto* cu = dynamic_cast<SysYParser::CompUnitContext*>(tree);
|
||||
if (!cu) {
|
||||
throw std::runtime_error("[irgen] parse tree 根节点不是 compUnit");
|
||||
}
|
||||
|
||||
auto module = std::make_unique<ir::Module>();
|
||||
IRGenImpl gen(*module);
|
||||
gen.Gen(ast);
|
||||
gen.Gen(*cu);
|
||||
return module;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user