feat(argparse): 添加枚举类型选项支持
添加了对命令行参数枚举类型的支持,允许用户从预定义的选项中进行选择, 并在解析时进行验证。同时修复了空值检查问题。 refactor(mir): 重构pass管理系统 将原有的pass管理器系统简化为直接的pass执行函数,移除了复杂的 依赖管理和流水线构建机制,使系统更加简洁明了。 chore(ir): 添加Windows x64 ABI实现 实现了Windows x64平台的ABI约定,包括参数传递、寄存器使用和 栈帧布局的处理逻辑。 feat(config): 统一编译阶段控制配置 将多个独立的布尔类型编译阶段控制改为统一的枚举类型,便于 管理和扩展新的编译阶段。
This commit is contained in:
48
src/main.c
48
src/main.c
@@ -89,8 +89,7 @@ int main(int argc, const char **argv, const char **envp) {
|
||||
.verbose = 0,
|
||||
.output_file = nullptr,
|
||||
.entry_point_symbol = nullptr,
|
||||
.emit_ast = false,
|
||||
.emit_hir = false,
|
||||
.emit_stage = SCC_EMIT_STAGE_DEFAULT,
|
||||
.target_description = "x86_64-pc-windows-msvc",
|
||||
};
|
||||
scc_vec_init(config.include_paths);
|
||||
@@ -129,7 +128,7 @@ int main(int argc, const char **argv, const char **envp) {
|
||||
|
||||
scc_lexer_t lexer;
|
||||
scc_lexer_init(&lexer, scc_sstream_to_ring(&sstream));
|
||||
if (config.emit_lex) {
|
||||
if (config.emit_stage == SCC_EMIT_STAGE_LEX) {
|
||||
scc_lexer_tok_ring_t *tok_ring =
|
||||
scc_lexer_to_ring(&lexer, 8, fp == nullptr ? false : true);
|
||||
if (fp == nullptr) {
|
||||
@@ -173,7 +172,7 @@ int main(int argc, const char **argv, const char **envp) {
|
||||
scc_pproc_add_object_macro(&pproc.macro_table,
|
||||
&pproc_predefined_macros[i], &pproc_tok_vec);
|
||||
}
|
||||
if (config.emit_pp) {
|
||||
if (config.emit_stage == SCC_EMIT_STAGE_PP) {
|
||||
scc_lexer_tok_ring_t *tok_ring =
|
||||
scc_pproc_to_ring(&pproc, 8, true, true);
|
||||
if (fp == nullptr) {
|
||||
@@ -211,7 +210,7 @@ sstream_drop:
|
||||
return error_code;
|
||||
}
|
||||
|
||||
if (config.emit_ast) {
|
||||
if (config.emit_stage == SCC_EMIT_STAGE_AST) {
|
||||
scc_tree_dump_t tree_dump;
|
||||
if (fp == nullptr) {
|
||||
scc_tree_dump_init(&tree_dump, true);
|
||||
@@ -232,7 +231,7 @@ sstream_drop:
|
||||
scc_ast2ir_run(&ast2ir_ctx, translation_unit);
|
||||
scc_ast2ir_ctx_drop(&ast2ir_ctx);
|
||||
|
||||
if (config.emit_hir) {
|
||||
if (config.emit_stage == SCC_EMIT_STAGE_HIR) {
|
||||
scc_hir_dump_t ir_dump_ctx;
|
||||
scc_tree_dump_t tree_dump;
|
||||
if (fp == nullptr) {
|
||||
@@ -252,7 +251,7 @@ sstream_drop:
|
||||
scc_lir_module_t lir_module;
|
||||
scc_lir_module_init(&lir_module);
|
||||
scc_hir2lir(&lir_module, &cprog);
|
||||
if (config.emit_lir) {
|
||||
if (config.emit_stage == SCC_EMIT_STAGE_LIR) {
|
||||
scc_lir_dump_ctx_t lir_dump_ctx;
|
||||
scc_tree_dump_t tree_dump;
|
||||
if (fp == nullptr) {
|
||||
@@ -272,7 +271,7 @@ sstream_drop:
|
||||
scc_mir_module_t mir_module;
|
||||
scc_mir_module_init(&mir_module);
|
||||
scc_lir2mir(&mir_module, &lir_module);
|
||||
if (config.emit_mir) {
|
||||
if (config.emit_stage == SCC_EMIT_STAGE_MIR) {
|
||||
scc_mir_dump_ctx_t mir_dump_ctx;
|
||||
scc_tree_dump_t tree_dump;
|
||||
if (fp == nullptr) {
|
||||
@@ -288,7 +287,7 @@ sstream_drop:
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (config.emit_flatbin) {
|
||||
if (config.emit_stage == SCC_EMIT_STAGE_FLATBIN) {
|
||||
scc_mcode_t mcode = {0};
|
||||
scc_mcode_init(&mcode, SCC_MCODE_ARCH_X86_64);
|
||||
scc_ir2mcode(&mcode, &mir_module);
|
||||
@@ -311,18 +310,31 @@ sstream_drop:
|
||||
scc_ir2sccf(&sccf_builder, &mir_module);
|
||||
sccf_builder_set_entry_symbol_name(&sccf_builder,
|
||||
config.entry_point_symbol);
|
||||
if (config.emit_sccf) {
|
||||
const sccf_t *sccf = sccf_builder_to_sccf(&sccf_builder);
|
||||
if (config.emit_stage == SCC_EMIT_STAGE_SCCF) {
|
||||
sccf_buffer_t buffer;
|
||||
scc_vec_init(buffer);
|
||||
sccf_builder_to_buffer(&sccf_builder, &buffer);
|
||||
if (fp == nullptr) {
|
||||
scc_printf("output exe at %s\n", config.output_file);
|
||||
} else {
|
||||
sccf_builder_to_file(&sccf_builder, config.output_file);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const sccf_t *sccf = sccf_builder_to_sccf(&sccf_builder);
|
||||
scc_pe_builder_t pe_builder;
|
||||
sccf2pe(&pe_builder, sccf);
|
||||
if (fp == nullptr) {
|
||||
scc_printf("output exe at %s\n", config.output_file);
|
||||
} else {
|
||||
scc_pe_dump_to_file(&pe_builder, config.output_file);
|
||||
if (config.emit_stage == SCC_EMIT_STAGE_DEFAULT ||
|
||||
config.emit_stage == SCC_EMIT_STAGE_TARGET) {
|
||||
scc_pe_builder_t pe_builder;
|
||||
sccf2pe(&pe_builder, sccf);
|
||||
if (fp == nullptr) {
|
||||
scc_printf("output exe at %s\n", config.output_file);
|
||||
} else {
|
||||
scc_pe_dump_to_file(&pe_builder, config.output_file);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
Panic("unknown emit stage");
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user