fix(abi): 修复void类型的ABI计算缺少break语句

在scc_type_abi.c文件中,void类型的case分支缺少break语句,
导致执行流程错误地进入下一个case分支。

feat(ast): 为参数声明添加索引字段

在ast_def.h头文件中为参数声明结构体添加param_idx字段,
用于跟踪参数在函数参数列表中的位置索引。

feat(ast): 更新参数初始化函数以支持索引参数

修改scc_ast.h中的scc_ast_decl_param_init函数签名,
添加参数索引idx参数,并将该值存储到参数声明结构体中。

feat(ast2ir): 添加IR转换上下文的值使用提示选项

在ast2ir.h中为scc_ast2ir_ctx_t结构体添加hint_using_value字段,
控制参数转换时是使用值还是分配内存的方式。

fix(ast2ir): 正确处理void类型到IR的转换

当遇到大小为0的类型(如void)时,直接返回void类型,
而不是尝试匹配其他大小分支。

refactor(ast2ir): 统一基本块引用类型为value_ref

将逻辑表达式、条件语句、循环语句中的基本块引用类型
从bblock_ref_t改为value_ref_t,保持类型一致性。

fix(ast2ir): 修正函数引用空值检查

使用SCC_IR_REF_nullptr常量替代0进行函数引用的空值检查,
提高代码的可读性和正确性。

refactor(ast2ir): 简化参数处理逻辑

移除不必要的函数参数获取和命名设置逻辑,
通过递归调用scc_ast2ir_decl来处理参数声明。

feat(ast2ir): 实现参数声明到IR的转换

为参数声明添加完整的IR转换逻辑,包括类型转换、
参数引用创建和内存分配处理。

refactor(ast2ir): 更新哈希表初始化接口

适配新的哈希表初始化函数签名,添加userdata参数支持,
并初始化hint_using_value字段为false。

refactor(ir): 移除函数参数的预分配逻辑

删除IR构建器中函数参数的预分配和循环添加逻辑,
简化函数开始构建的处理流程。

refactor(ir): 更新类型哈希表键值处理

修改类型哈希表的哈希和比较函数以接受模块参数,
正确处理空引用情况并支持新的键值传递方式。

fix(ir): 修复IR转储中的字符串格式

移除IR函数转储时多余的换行符,确保输出格式正确。

refactor(ir): 更新模块哈希表初始化

适配哈希表初始化接口变更,添加userdata参数,
并为各种向量预留UID 0作为无效引用。

fix(ir): 修复模块清理中的循环起始索引

将模块清理循环的起始索引从0改为1,跳过预留的
无效引用项,避免访问空指针。

refactor(ir): 调整向量和哈希表操作顺序

调整模块中向量push和哈希表set的操作顺序,
确保数据一致性和正确的UID分配。

chore(build): 移除ir2mcode模块相关文件

移除ir2mcode相关的头文件和源文件,这些组件
将在后续重构中重新设计或替换。
This commit is contained in:
zzy
2026-04-15 14:52:11 +08:00
parent 8054f20375
commit 5a9f816ccf
38 changed files with 260 additions and 1497 deletions

View File

@@ -1,110 +0,0 @@
#include <scc_ast2ir.h>
#include <scc_ir2mcode.h>
#include <scc_lexer.h>
#include <scc_parser.h>
#include <sccf2pe.h>
#include <stdio.h>
void test_example(const char *input, cbool need_sema, const char *name) {
int res = 0;
scc_sstream_t mem_stream;
res = scc_sstream_init_by_buffer(&mem_stream, input, scc_strlen(input),
false, 16);
Assert(res == 0);
scc_lexer_t lexer;
scc_lexer_init(&lexer, scc_sstream_to_ring(&mem_stream));
scc_lexer_tok_ring_t *tok_ring = scc_lexer_to_ring(&lexer, 64, false);
scc_parser_t parser;
if (need_sema) {
scc_sema_callbacks_t sema_callbacks;
scc_sema_init(&sema_callbacks);
scc_parser_init(&parser, tok_ring, &sema_callbacks);
} else {
scc_parser_init(&parser, tok_ring, nullptr);
}
scc_ast_translation_unit_t *tu = scc_parse_translation_unit(&parser);
scc_ast2ir_ctx_t ast2ir_ctx;
#include <abi/win_x64_type_abi.h>
scc_ir_cprog_t cprog;
scc_ir_cprog_init(&cprog);
scc_ast2ir_ctx_init(&ast2ir_ctx, scc_win_x64_type_abi, &cprog);
scc_ast2ir_translation_unit(&ast2ir_ctx, tu);
scc_ast2ir_ctx_drop(&ast2ir_ctx);
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);
const sccf_t *sccf = sccf_builder_to_sccf(&sccf_builder);
scc_pe_builder_t pe_builder;
sccf2pe(&pe_builder, sccf);
char fname[1024] = {0};
scc_snprintf(fname, sizeof(fname), "%s%s%s", __FILE__, "/../../", name);
scc_pe_dump_to_file(&pe_builder, fname);
}
int main() {
test_example("int main() {\n"
" int a;\n"
" int b;\n"
" a = 1 + 2 * 3;\n"
" b = 7;\n"
" a = a - b + 1;\n"
" return a;\n"
"}\n",
true, "02_decl_expr.exe");
test_example("int main(void) {\n"
" int a;\n"
" a = 1;\n"
" if (a) {\n"
" a = 1;\n"
" } else {\n"
" a = 2;\n"
" }\n"
" return a;\n"
"}\n",
true, "04_if.exe");
test_example("int main() {\n"
" int i = 0;\n"
" while (i < 10) i = i + 1;\n"
" return i;\n"
"}\n",
true, "07_while.exe");
test_example("int add(int a, int b) {\n"
" return a + b;\n"
"}\n"
"\n"
"int main(void) {\n"
" return add(1, 2);\n"
"}\n",
true, "10_main.exe");
test_example("int factorial(int);\n"
"\n"
"int main() {\n"
" int num = 5;\n"
" int result = factorial(num);\n"
" // printf(\"%d\", result);\n"
" return result;\n"
"}\n"
"\n"
"int factorial(int num) {\n"
" if (num == 0) {\n"
" return 1;\n"
" } else {\n"
" return num * factorial(num - 1);\n"
" }\n"
"}\n",
true, "11_recursion.exe");
return 0;
}