feat(compiler): 启用 ir2mcode 和 sccf2target 库并实现 x86_64 代码生成

- 在 cbuild.toml 中启用 ir2mcode 和 sccf2target 依赖库
- 修改 justfile 中的构建命令,使用 release 模式并更新 tokei 统计排除 mcode 目录
- 重构 LIR 中的地址操作数类型,将 SCC_LIR_INSTR_KIND_ADDR 重命名为 SCC_LIR_INSTR_KIND_MEM
- 实现完整的 MIR 到 x86_64 机器码转换,包括:
  - 添加 move、compare、binary operation 等指令发射函数
  - 实现条件分支和跳转指令生成
  - 支持算术、逻辑、移位等基本操作
  - 添加调用和返回指令处理
  - 实现栈分配和寄存器分配功能
- 完善 ir2mcode 模块,将 MIR 指令转换为机器码
- 更新 ir2sccf 模块,集成机器码生成功能
- 添加 mcode 库的架构支持和内存管理功能
- 修复 PE 文件生成中的空指针检查问题
This commit is contained in:
zzy
2026-05-05 15:59:31 +08:00
parent 676f3ec82c
commit aa8a1ff8ce
14 changed files with 842 additions and 399 deletions

View File

@@ -18,6 +18,9 @@ typedef struct {
cbool emit_lir;
cbool emit_mir;
cbool emit_flatbin;
cbool emit_sccf;
cbool emit_target;
cbool emit_mir_pass_reg_alloc;
cbool emit_mir_pass_stack_layout;
cbool emit_mir_pass_prolog_epilog;
@@ -43,6 +46,10 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
SCC_HINT_EMIT_HIR,
SCC_HINT_EMIT_LIR,
SCC_HINT_EMIT_MIR,
SCC_HINT_EMIT_FLATBIN,
SCC_HINT_EMIT_SCCF,
SCC_HINT_EMIT_TARGET,
};
static const char *scc_hints_en[] = {
[SCC_HINT_PROG_NAME] = "scc",
@@ -65,6 +72,10 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
[SCC_HINT_EMIT_LIR] = "Generate Low-level IR and exit",
[SCC_HINT_EMIT_MIR] = "Generate Machine IR and exit",
[SCC_HINT_EMIT_FLATBIN] = "Generate flat binary and exit",
[SCC_HINT_EMIT_SCCF] = "Generate SCCF and exit",
[SCC_HINT_EMIT_TARGET] = "Generate target description and exit",
};
static const char *scc_hints_zh[] = {
[SCC_HINT_PROG_NAME] = "scc",
@@ -84,6 +95,10 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
[SCC_HINT_EMIT_HIR] = "生成`高级中间代码`并退出",
[SCC_HINT_EMIT_LIR] = "生成`低级中间代码`并退出",
[SCC_HINT_EMIT_MIR] = "生成`机器中间代码`并退出",
[SCC_HINT_EMIT_FLATBIN] = "生成`flat binary`并退出",
[SCC_HINT_EMIT_SCCF] = "生成`SCCF`并退出",
[SCC_HINT_EMIT_TARGET] = "生成`目标代码`并退出",
};
const char **scc_hints;
@@ -195,6 +210,26 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
scc_hints[SCC_HINT_EMIT_MIR]);
scc_argparse_spec_setup_bool(&opt_mir.spec, &(config->emit_mir));
scc_argparse_cmd_add_opt(root, &opt_mir);
// --emit-flatbin
scc_argparse_opt_t opt_flatbin;
scc_argparse_opt_init(&opt_flatbin, 0, "emit-flatbin",
scc_hints[SCC_HINT_EMIT_FLATBIN]);
scc_argparse_spec_setup_bool(&opt_flatbin.spec, &(config->emit_flatbin));
scc_argparse_cmd_add_opt(root, &opt_flatbin);
// --emit-sccf
scc_argparse_opt_t opt_sccf;
scc_argparse_opt_init(&opt_sccf, 0, "emit-sccf",
scc_hints[SCC_HINT_EMIT_SCCF]);
scc_argparse_spec_setup_bool(&opt_sccf.spec, &(config->emit_sccf));
scc_argparse_cmd_add_opt(root, &opt_sccf);
// --emit-target
scc_argparse_opt_t opt_emit_target;
scc_argparse_opt_init(&opt_emit_target, 0, "emit-target",
scc_hints[SCC_HINT_EMIT_TARGET]);
scc_argparse_spec_setup_string(&opt_emit_target.spec,
&(config->emit_target));
scc_argparse_cmd_add_opt(root, &opt_emit_target);
}
#endif /* __SCC_CONFIG_H___ */