feat(frontend): 命令行添加IR和AST选择输出

This commit is contained in:
jing
2026-02-28 23:40:05 +08:00
parent d08b23276a
commit 66659524c8
7 changed files with 75 additions and 16 deletions

View File

@@ -21,7 +21,9 @@ int main(int argc, char** argv) {
}
auto antlr = ParseFileWithAntlr(opts.input);
auto ast = BuildAst(antlr.tree);
ast::PrintAST(*ast); // 调试 AST
if (opts.emit_ast) {
ast::PrintAST(*ast); // 调试 AST
}
if (!opts.ast_dot_output.empty()) {
std::ofstream dot_out(opts.ast_dot_output);
if (!dot_out) {
@@ -34,8 +36,10 @@ int main(int argc, char** argv) {
// 同学们可以在 irgen/ 目录下按提示自行完善或替换实现。
auto module = GenerateIR(*ast);
ir::IRPrinter printer;
printer.Print(*module);
if (opts.emit_ir) {
ir::IRPrinter printer;
printer.Print(*module);
}
} catch (const std::exception& ex) {
std::cerr << "error: " << ex.what() << "\n";
return 1;