From 5123a3fc9e67b8eb2d8090477573425d96e8b238 Mon Sep 17 00:00:00 2001 From: Lane0218 Date: Sat, 27 Dec 2025 17:01:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(misc):=20=E6=B7=BB=E5=8A=A0=E6=9C=80?= =?UTF-8?q?=E5=B0=8F=20main=20=E5=85=A5=E5=8F=A3=E4=BB=A5=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CMakeLists.txt | 5 +---- src/main.cpp | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e1d73b..373ab50 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,10 +8,7 @@ add_subdirectory(frontend) add_subdirectory(irgen) add_subdirectory(mir) -# 当前仓库仍是“骨架阶段”,`src/main.cpp` 暂无可链接的 main。 -# 为了让默认 `cmake --build` 能成功(先把各模块库编译通过),将可执行文件从 ALL 中排除; -# 需要构建可执行文件时可显式执行:cmake --build --target compiler -add_executable(compiler EXCLUDE_FROM_ALL +add_executable(compiler main.cpp ) target_link_libraries(compiler PRIVATE diff --git a/src/main.cpp b/src/main.cpp index e9e3ea1..bfbc3fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,30 @@ -// 编译器入口: -// - 解析命令行参数(输入源文件、输出路径、输出类型、优化级别等) -// - 驱动完整流水线:Frontend -> Middle-end -> Backend -// - 统一管理阶段产物输出(例如 .ll/.s 的输出开关) +#include +#include +static void PrintUsage(const char* argv0) { + std::cerr << "用法: " << (argv0 ? argv0 : "compiler") << " [options]\n"; + std::cerr << "说明: 当前为工程骨架阶段,暂不执行完整编译流程,仅用于验证可编译/可链接。\n"; +} + +int main(int argc, char** argv) { + if (argc <= 1) { + PrintUsage(argv[0]); + return 0; + } + + 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; +}