fix(frontend): 修复部分实现

This commit is contained in:
jing
2026-03-09 15:37:36 +08:00
parent 8aec500b5b
commit e01995a33d
21 changed files with 321 additions and 165 deletions

View File

@@ -1,10 +1,13 @@
#include <exception>
#include <iostream>
#include <stdexcept>
#include "frontend/AntlrDriver.h"
#include "frontend/SyntaxTreePrinter.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"
@@ -19,10 +22,16 @@ int main(int argc, char** argv) {
auto antlr = ParseFileWithAntlr(opts.input);
bool need_blank_line = false;
if (opts.emit_parse_tree) {
std::cout << antlr.tree->toStringTree(antlr.parser.get()) << "\n";
PrintSyntaxTree(antlr.tree, antlr.parser.get(), std::cout);
need_blank_line = true;
}
auto* comp_unit = dynamic_cast<SysYParser::CompUnitContext*>(antlr.tree);
if (!comp_unit) {
throw std::runtime_error("[main] 语法树根节点不是 compUnit");
}
RunSema(*comp_unit);
auto module = GenerateIR(antlr.tree);
if (opts.emit_ir) {
ir::IRPrinter printer;