You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
935 B

#include <exception>
#include <iostream>
#include "frontend/AntlrDriver.h"
#include "frontend/AstBuilder.h"
#include "ir/IR.h"
#include "irgen/IRGen.h"
#include "sem/Sema.h"
#include "utils/CLI.h"
#include "utils/Log.h"
#include "ast/AstNodes.h"
int main(int argc, char** argv) {
try {
auto opts = ParseCLI(argc, argv);
if (opts.show_help) {
PrintHelp(std::cout);
return 0;
}
auto antlr = ParseFileWithAntlr(opts.input);
auto ast = BuildAst(antlr.tree);
ast::PrintAST(*ast); // 调试 AST
ast = RunSema(std::move(ast));
// IR 生成:当前使用 IRGenDriver.cpp 里的最小参考实现,
// 同学们可以在 irgen/ 目录下按提示自行完善或替换实现。
auto module = GenerateIR(*ast);
ir::IRPrinter printer;
printer.Print(*module);
} catch (const std::exception& ex) {
std::cerr << "error: " << ex.what() << "\n";
return 1;
}
return 0;
}