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,17 +1,12 @@
#include <exception>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include "frontend/AntlrDriver.h"
#include "frontend/AstBuilder.h"
#include "ir/IR.h"
#include "irgen/IRGen.h"
#include "mir/MIR.h"
#include "sem/Sema.h"
#include "utils/CLI.h"
#include "utils/Log.h"
#include "ast/AstNodes.h"
int main(int argc, char** argv) {
try {
@@ -20,25 +15,15 @@ int main(int argc, char** argv) {
PrintHelp(std::cout);
return 0;
}
auto antlr = ParseFileWithAntlr(opts.input);
auto ast = BuildAst(antlr.tree);
bool need_blank_line = false;
if (opts.emit_ast) {
ast::PrintAST(*ast); // 调试 AST
if (opts.emit_parse_tree) {
std::cout << antlr.tree->toStringTree(antlr.parser.get()) << "\n";
need_blank_line = true;
}
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 里的最小实现,
// 同学们可以在 irgen/ 目录下按提示自行完善或替换实现。
auto module = GenerateIR(*ast);
auto module = GenerateIR(antlr.tree);
if (opts.emit_ir) {
ir::IRPrinter printer;
if (need_blank_line) {