可以处理生成加法的IR

This commit is contained in:
jing
2025-12-28 18:44:48 +08:00
parent 77bee889d7
commit e941cced9b
42 changed files with 919 additions and 158 deletions

View File

@@ -1,30 +1,29 @@
#include <exception>
#include <iostream>
#include <string>
static void PrintUsage(const char* argv0) {
std::cerr << "用法: " << (argv0 ? argv0 : "compiler") << " <input.sy> [options]\n";
std::cerr << "说明: 当前为工程骨架阶段,暂不执行完整编译流程,仅用于验证可编译/可链接。\n";
}
#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) {
if (argc <= 1) {
PrintUsage(argv[0]);
return 0;
try {
auto opts = ParseCLI(argc, argv);
auto antlr = ParseFileWithAntlr(opts.input);
auto ast = BuildAst(antlr.tree);
ast::PrintAST(*ast); // 调试 AST
ast = RunSema(std::move(ast));
auto module = GenerateIR(*ast);
ir::IRPrinter printer;
printer.Print(*module);
} catch (const std::exception& ex) {
LOG_ERROR(ex.what());
return 1;
}
std::string input_path = argv[1];
if (input_path == "-h" || input_path == "--help") {
PrintUsage(argv[0]);
return 0;
}
// TODO: 后续在此接入完整流水线:
// 1) frontend: ANTLR 解析 + AST 构建
// 2) sem: 语义分析
// 3) irgen: AST -> IR
// 4) ir passes: 可选优化
// 5) mir/backend: AArch64 指令选择、寄存器分配、栈帧、汇编输出
(void)input_path;
return 0;
}