fix(ast): 规范AST输出

This commit is contained in:
jing
2026-02-28 21:03:40 +08:00
parent cd235e60cc
commit d08b23276a
6 changed files with 184 additions and 38 deletions

View File

@@ -1,5 +1,7 @@
#include <exception>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include "frontend/AntlrDriver.h"
#include "frontend/AstBuilder.h"
@@ -20,8 +22,15 @@ int main(int argc, char** argv) {
auto antlr = ParseFileWithAntlr(opts.input);
auto ast = BuildAst(antlr.tree);
ast::PrintAST(*ast); // 调试 AST
if (!opts.ast_dot_output.empty()) {
std::ofstream dot_out(opts.ast_dot_output);
if (!dot_out) {
throw std::runtime_error("无法写入 AST DOT 文件: " + opts.ast_dot_output);
}
ast::PrintASTDot(*ast, dot_out);
}
ast = RunSema(std::move(ast));
// IR 生成:当前使用 IRGenDriver.cpp 里的最小参考实现,
// IR 生成:当前使用 IRGenDriver.cpp 里的最小实现,
// 同学们可以在 irgen/ 目录下按提示自行完善或替换实现。
auto module = GenerateIR(*ast);