fix(ast): 删掉ast结构

This commit is contained in:
jing
2026-03-09 12:42:12 +08:00
parent d4f4b77b1e
commit 03bd6d88e3
20 changed files with 147 additions and 594 deletions

View File

@@ -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;
}