feat(cbuild): 添加 lir 库依赖并注释掉未使用的模块
- 添加 { name = "lir", path = "./libs/lir" } 依赖项
- 注释掉 ir2mcode 和 sccf2target 模块以暂时禁用
refactor(ast2ir): 修复类型转换问题并简化哈希表初始化
- 修复 compute_type_layout 函数中的类型转换警告
- 在表达式处理末尾添加 UNREACHABLE() 断言
- 移除 begin_func 中的 param_names 参数
- 使用 scc_hashtable_usize_init 替代自定义比较函数
refactor(ir): 简化函数构建器接口并修复返回值处理
- 移除 scc_ir_builder_begin_func 中的 param_names 参数
- 修改 scc_ir_builder_ret_void 以正确处理 void 返回值
- 初始化返回值节点而不是直接设置为 0
refactor(ir): 简化模块初始化中的哈希表配置
- 移除自定义 hash_key 和 cmp_key 函数
- 使用 scc_hashtable_usize_init 统一初始化哈希表
feat(lir): 添加低层中间表示库基础结构
- 创建 lir 库的包配置文件
- 定义 LIR 的基本数据结构、指令类型和操作枚举
- 实现 LIR 构建器和模块管理功能
- 添加 LIR 转换器头文件和转储功能
This commit is contained in:
12
src/config.h
12
src/config.h
@@ -15,6 +15,7 @@ typedef struct {
|
||||
cbool emit_pp;
|
||||
cbool emit_ast;
|
||||
cbool emit_ir;
|
||||
cbool emit_lir;
|
||||
} scc_config_t;
|
||||
|
||||
static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
|
||||
@@ -35,6 +36,7 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
|
||||
SCC_HINT_EMIT_PP,
|
||||
SCC_HINT_EMIT_AST,
|
||||
SCC_HINT_EMIT_IR,
|
||||
SCC_HINT_EMIT_LIR,
|
||||
};
|
||||
static const char *scc_hints_en[] = {
|
||||
[SCC_HINT_PROG_NAME] = "scc",
|
||||
@@ -54,6 +56,8 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
|
||||
[SCC_HINT_EMIT_PP] = "Generate preprocessed tokens and exit",
|
||||
[SCC_HINT_EMIT_AST] = "Generate AST and exit",
|
||||
[SCC_HINT_EMIT_IR] = "Generate IR and exit",
|
||||
[SCC_HINT_EMIT_LIR] = "Generate LIR and exit",
|
||||
|
||||
};
|
||||
static const char *scc_hints_zh[] = {
|
||||
[SCC_HINT_PROG_NAME] = "scc",
|
||||
@@ -71,6 +75,7 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
|
||||
[SCC_HINT_EMIT_PP] = "生成`预处理后的词法单元`并退出",
|
||||
[SCC_HINT_EMIT_AST] = "生成`抽象语法树`并退出",
|
||||
[SCC_HINT_EMIT_IR] = "生成`中间代码`并退出",
|
||||
[SCC_HINT_EMIT_LIR] = "生成`低级中间代码`并退出",
|
||||
};
|
||||
|
||||
const char **scc_hints;
|
||||
@@ -167,6 +172,13 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
|
||||
scc_argparse_opt_init(&opt_ir, 'R', "emit-ir", scc_hints[SCC_HINT_EMIT_IR]);
|
||||
scc_argparse_spec_setup_bool(&opt_ir.spec, &(config->emit_ir));
|
||||
scc_argparse_cmd_add_opt(root, &opt_ir);
|
||||
|
||||
// -L, --emit-lir
|
||||
scc_argparse_opt_t opt_lir;
|
||||
scc_argparse_opt_init(&opt_lir, 'L', "emit-lir",
|
||||
scc_hints[SCC_HINT_EMIT_LIR]);
|
||||
scc_argparse_spec_setup_bool(&opt_lir.spec, &(config->emit_lir));
|
||||
scc_argparse_cmd_add_opt(root, &opt_lir);
|
||||
}
|
||||
|
||||
#endif /* __SCC_CONFIG_H___ */
|
||||
|
||||
62
src/main.c
62
src/main.c
@@ -6,8 +6,11 @@
|
||||
#include <ast_dump.h>
|
||||
#include <ir_dump.h>
|
||||
#include <scc_ast2ir.h>
|
||||
#include <scc_ir2mcode.h>
|
||||
#include <sccf2pe.h>
|
||||
|
||||
#include <scc_ir2lir.h>
|
||||
#include <scc_lir_dump.h>
|
||||
// #include <scc_ir2mcode.h>
|
||||
// #include <sccf2pe.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@@ -238,24 +241,47 @@ sstream_drop:
|
||||
return 0;
|
||||
}
|
||||
|
||||
scc_ir2mcode_ctx_t ir2mcode_ctx;
|
||||
sccf_builder_t sccf_builder;
|
||||
scc_ir2mcode_init(&ir2mcode_ctx, &cprog, &sccf_builder,
|
||||
SCC_MCODE_ARCH_AMD64);
|
||||
scc_ir2mcode(&ir2mcode_ctx);
|
||||
scc_ir2mcode_drop(&ir2mcode_ctx);
|
||||
scc_lir_builder_t lir_builder;
|
||||
scc_lir_module_t lir_module;
|
||||
scc_lir_module_init(&lir_module);
|
||||
scc_lir_builder_init(&lir_builder, &lir_module);
|
||||
scc_ir2lir(&lir_builder, &cprog);
|
||||
if (config.emit_lir) {
|
||||
scc_lir_dump_ctx_t lir_dump_ctx;
|
||||
scc_tree_dump_t tree_dump;
|
||||
if (fp == nullptr) {
|
||||
scc_tree_dump_init(&tree_dump, true);
|
||||
} else {
|
||||
scc_tree_dump_init(&tree_dump, false);
|
||||
}
|
||||
scc_lir_dump_init(&lir_dump_ctx, &tree_dump);
|
||||
// scc_ir_dump_cprog(&ir_dump_ctx);
|
||||
scc_lir_dump_module(&lir_dump_ctx, &lir_module);
|
||||
|
||||
sccf_builder_set_entry_symbol_name(&sccf_builder,
|
||||
config.entry_point_symbol);
|
||||
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);
|
||||
scc_tree_dump_flush(&tree_dump, tree_dump_output,
|
||||
fp == nullptr ? scc_stdout : fp);
|
||||
scc_tree_dump_drop(&tree_dump);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// scc_ir2mcode_ctx_t ir2mcode_ctx;
|
||||
// sccf_builder_t sccf_builder;
|
||||
// scc_ir2mcode_init(&ir2mcode_ctx, &cprog, &sccf_builder,
|
||||
// SCC_MCODE_ARCH_AMD64);
|
||||
// scc_ir2mcode(&ir2mcode_ctx);
|
||||
// scc_ir2mcode_drop(&ir2mcode_ctx);
|
||||
|
||||
// sccf_builder_set_entry_symbol_name(&sccf_builder,
|
||||
// config.entry_point_symbol);
|
||||
// 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);
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user