阶段 D 步骤 9:CLI 接线收尾(--machine 仅编译/反汇编必填)。
- 打印模式(无 -o)不再要求 --machine(恢复 12.3 行为) - 编译路径与 --disasm 必填 --machine,加载/校验失败报错退出 - 验证:打印/编译/disasm/缺参四种模式行为正确;ctest 12/12
This commit is contained in:
+29
-20
@@ -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 <machine.toml>\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 <machine.toml>\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<std::string> 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 <machine.toml>\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<compiler::SourceUnit> units;
|
||||
for (const std::string& f : files) {
|
||||
|
||||
Reference in New Issue
Block a user