From a5f49caa94cab0a00c2556eccb6f62649b056d2e Mon Sep 17 00:00:00 2001 From: chentianya Date: Fri, 21 Aug 2026 22:30:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B6=E6=AE=B5=20D=20=E6=AD=A5=E9=AA=A4=209?= =?UTF-8?q?=EF=BC=9ACLI=20=E6=8E=A5=E7=BA=BF=E6=94=B6=E5=B0=BE=EF=BC=88--m?= =?UTF-8?q?achine=20=E4=BB=85=E7=BC=96=E8=AF=91/=E5=8F=8D=E6=B1=87?= =?UTF-8?q?=E7=BC=96=E5=BF=85=E5=A1=AB=EF=BC=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 打印模式(无 -o)不再要求 --machine(恢复 12.3 行为) - 编译路径与 --disasm 必填 --machine,加载/校验失败报错退出 - 验证:打印/编译/disasm/缺参四种模式行为正确;ctest 12/12 --- compiler/src/main.cpp | 49 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/compiler/src/main.cpp b/compiler/src/main.cpp index 27d5169..05ed636 100644 --- a/compiler/src/main.cpp +++ b/compiler/src/main.cpp @@ -105,10 +105,13 @@ int main(int argc, char** argv) { // 参数收集 std::string machine_path; + std::string out_path; bool disasm_mode = false; for (int i = 2; i + 1 < argc; ++i) { if (std::strcmp(argv[i], "--machine") == 0) { machine_path = argv[i + 1]; + } else if (std::strcmp(argv[i], "-o") == 0) { + out_path = argv[i + 1]; } } for (int i = 1; i < argc; ++i) { @@ -117,38 +120,32 @@ int main(int argc, char** argv) { } } - // 机器定义(编译与反汇编都需要;加载/校验失败报错退出) - if (machine_path.empty()) { - std::fprintf(stderr, "error: missing --machine \n"); - usage(); - return 1; - } - compiler::MachineConfig cfg; - std::string err; - if (!cfg.load(machine_path, &err)) { - std::fprintf(stderr, "error: %s\n", err.c_str()); - return 1; - } - + // --disasm:需要机器定义(反汇编按 machine.toml 的 format 输出) if (disasm_mode) { + if (machine_path.empty()) { + std::fprintf(stderr, "error: missing --machine \n"); + usage(); + return 1; + } + compiler::MachineConfig cfg; + std::string err; + if (!cfg.load(machine_path, &err)) { + std::fprintf(stderr, "error: %s\n", err.c_str()); + return 1; + } return dump_image(argv[1], cfg); } const std::string toml_path = argv[1]; - std::string out_path; - for (int i = 2; i + 1 < argc; ++i) { - if (std::strcmp(argv[i], "-o") == 0) { - out_path = argv[i + 1]; - } - } - compiler::Project proj; + std::string err; if (!compiler::parse_project(toml_path, &proj, &err)) { std::fprintf(stderr, "error: %s\n", err.c_str()); return 1; } const std::vector files = compiler::compile_files(proj); + // 打印模式(无 -o):不需要机器定义 if (out_path.empty()) { uint64_t hash = 0; if (!compiler::compute_project_hash(proj, &hash, &err)) { @@ -164,6 +161,18 @@ int main(int argc, char** argv) { return 0; } + // 编译路径:机器定义必填(编码/类型/FB 布局来自 machine.toml) + if (machine_path.empty()) { + std::fprintf(stderr, "error: missing --machine \n"); + usage(); + return 1; + } + compiler::MachineConfig cfg; + if (!cfg.load(machine_path, &err)) { + std::fprintf(stderr, "error: %s\n", err.c_str()); + return 1; + } + // 完整管线:读 .st → 链接 → 类型检查 → 寄存器码 std::vector units; for (const std::string& f : files) {