refactor(ast): 统一记录类型结构并移除成员访问操作符
- 移除了枚举类型的独立结构定义,统一使用record结构 - 移除了成员访问操作符SCC_AST_OP_MEMBER_ACCESS和SCC_AST_OP_PTR_MEMBER_ACCESS - 更新了for循环语句中init字段的类型从scc_ast_type_t*到scc_ast_node_t* - 修改了声明初始化函数以支持统一的记录类型处理 fix(ast2ir): 完善二元表达式处理和for循环代码生成 - 重构了赋值操作符的处理逻辑,通过临时表达式实现复合赋值 - 添加了对for循环语句的完整IR代码生成功能 - 修复了if-else语句中错误的基本块跳转问题 - 改进了标识符未找到时的错误提示信息 chore: 清理代码和修复潜在问题 - 移除了未使用的自动标签生成功能 - 统一了IR基本块标签格式化输出 - 修复了机器码生成中的寄存器存储控制流问题 - 改进了词法分析器中十六进制数字的处理逻辑
This commit is contained in:
@@ -83,23 +83,18 @@ scc_ir_func_ref_t scc_ir_builder_current_func(scc_ir_builder_t *builder) {
|
||||
scc_ir_bblock_ref_t scc_ir_builder_bblock(scc_ir_builder_t *builder,
|
||||
const char *label) {
|
||||
scc_ir_bblock_t bblock = {0};
|
||||
|
||||
if (label) {
|
||||
bblock.label = label;
|
||||
} else {
|
||||
// TODO 自动生成标签
|
||||
char *auto_label = scc_malloc(sizeof(char) * 64);
|
||||
if (auto_label)
|
||||
LOG_FATAL("allocate memory failed");
|
||||
static int auto_counter = 0;
|
||||
scc_snprintf(auto_label, sizeof(auto_label), ".BB%d", auto_counter++);
|
||||
bblock.label = auto_label;
|
||||
}
|
||||
|
||||
scc_vec_init(bblock.instrs);
|
||||
|
||||
scc_ir_bblock_ref_t bblock_ref =
|
||||
scc_ir_ctx_new_bblock(&builder->ctx, &bblock);
|
||||
|
||||
scc_ir_func_t *current_func =
|
||||
scc_ir_ctx_get_func(&builder->ctx, builder->current_func);
|
||||
if (current_func) {
|
||||
scc_vec_push(current_func->bblocks, bblock_ref);
|
||||
}
|
||||
return bblock_ref;
|
||||
}
|
||||
|
||||
@@ -107,14 +102,6 @@ scc_ir_bblock_ref_t scc_ir_builder_begin_bblock(scc_ir_builder_t *builder,
|
||||
const char *label) {
|
||||
|
||||
builder->current_bblock = scc_ir_builder_bblock(builder, label);
|
||||
|
||||
// 将基本块添加到当前函数
|
||||
scc_ir_func_t *current_func =
|
||||
scc_ir_ctx_get_func(&builder->ctx, builder->current_func);
|
||||
if (current_func) {
|
||||
scc_vec_push(current_func->bblocks, builder->current_bblock);
|
||||
}
|
||||
|
||||
return builder->current_bblock;
|
||||
}
|
||||
|
||||
|
||||
@@ -679,11 +679,11 @@ void scc_ir_dump_node_linear(scc_ir_dump_ctx_t *ctx,
|
||||
char cond_buf[64];
|
||||
format_node_ref_or_value(ctx, cond_buf, sizeof(cond_buf),
|
||||
node->data.branch.cond);
|
||||
p += scc_snprintf(p, remaining, "br %s, label %%%u, label %%%u",
|
||||
p += scc_snprintf(p, remaining, "br %s, label %%L%u, label %%L%u",
|
||||
cond_buf, node->data.branch.true_bblock,
|
||||
node->data.branch.false_bblock);
|
||||
} else {
|
||||
p += scc_snprintf(p, remaining, "br label %%%u",
|
||||
p += scc_snprintf(p, remaining, "br label %%L%u",
|
||||
node->data.branch.true_bblock);
|
||||
}
|
||||
break;
|
||||
@@ -694,6 +694,7 @@ void scc_ir_dump_node_linear(scc_ir_dump_ctx_t *ctx,
|
||||
break;
|
||||
|
||||
case SCC_IR_NODE_CALL: {
|
||||
char node_name[256] = "";
|
||||
char args_buf[256] = "";
|
||||
char *args_p = args_buf;
|
||||
usize args_remaining = sizeof(args_buf);
|
||||
@@ -712,8 +713,10 @@ void scc_ir_dump_node_linear(scc_ir_dump_ctx_t *ctx,
|
||||
args_remaining = sizeof(args_buf) - (args_p - args_buf);
|
||||
}
|
||||
|
||||
p += scc_snprintf(p, remaining, "call @%%%u(%s)",
|
||||
node->data.call.callee, args_buf);
|
||||
format_node_ref_or_value(ctx, node_name, sizeof(node_name),
|
||||
node->data.call.callee);
|
||||
|
||||
p += scc_snprintf(p, remaining, "call @%s(%s)", node_name, args_buf);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -751,9 +754,11 @@ void scc_ir_dump_bblock_linear(scc_ir_dump_ctx_t *ctx,
|
||||
// 打印基本块标签
|
||||
static char label_buff[128];
|
||||
if (bblock->label && bblock->label[0] != '\0') {
|
||||
scc_snprintf(label_buff, sizeof(label_buff), "%%%s:", bblock->label);
|
||||
scc_snprintf(label_buff, sizeof(label_buff), "%%L%d %s:", bblock_ref,
|
||||
bblock->label);
|
||||
} else {
|
||||
scc_snprintf(label_buff, sizeof(label_buff), "<unnamed>:");
|
||||
scc_snprintf(label_buff, sizeof(label_buff),
|
||||
"%%L%d <unnamed>:", bblock_ref);
|
||||
}
|
||||
PRINT_NODE(ctx->dump_ctx, label_buff);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user