IR设计
This commit is contained in:
46
src/main.cpp
46
src/main.cpp
@@ -1,30 +1,30 @@
|
||||
#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 "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));
|
||||
// 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user