feat(ast): 更新AST dump功能以使用新的树转储接口
- 将头文件中的tree_dump.h替换为scc_tree_dump.h - 修改函数签名将scc_tree_dump_ctx_t改为scc_tree_dump_t - 移除过时的宏定义和内联函数实现 - 使用新的scc_tree_dump_* API替代旧的PRINT_*宏 - 简化类型、表达式、语句和声明的转储逻辑 - 统一使用新的树转储接口进行节点和值的输出 feat(ast2ir): 实现逻辑运算符和一元运算符的IR转换 - 添加scc_ast2ir_logical_expr函数处理&&和||运算符 - 实现短路求值逻辑,包含分支控制流 - 添加对一元正号运算符的支持 - 实现取地址和间接寻址运算符 - 添加字符字面量解析支持转义序列 fix(ir): 修复字符串常量构建中的长度计算错误 - 修正数组长度计算从len+1改为len-1 - 调整字符串内容复制逻辑跳过引号边界 - 修正内存分配大小与实际数据长度匹配 refactor(ir): 更新IR转储模块使用统一的树转储接口 - 将IR转储上下文中的tree_dump_ctx_t替换为scc_tree_dump_t - 更新初始化函数签名以使用新的转储接口类型
This commit is contained in:
@@ -86,7 +86,7 @@ scc_ir_builder_const_string(scc_ir_builder_t *builder, const char *str,
|
||||
scc_ir_type_t array_type = {
|
||||
.tag = SCC_IR_TYPE_ARRAY,
|
||||
.data.array.base = u8_type,
|
||||
.data.array.len = len + 1, // 包含 null 结尾
|
||||
.data.array.len = len - 1, // 包含 null 结尾
|
||||
};
|
||||
scc_ir_type_ref_t array_type_ref =
|
||||
scc_ir_ctx_get_type(&builder->ctx, &array_type);
|
||||
@@ -103,14 +103,15 @@ scc_ir_builder_const_string(scc_ir_builder_t *builder, const char *str,
|
||||
.type = array_type_ref,
|
||||
.data.const_array.base_type = u8_type,
|
||||
};
|
||||
char *buff = scc_malloc(len + 1);
|
||||
char *buff = scc_malloc(len - 1);
|
||||
Assert(buff);
|
||||
for (usize i = 0; i < len; i++) {
|
||||
buff[i] = str[i];
|
||||
// FIXME content to real string
|
||||
for (usize i = 1; i < len - 1; i++) {
|
||||
buff[i - 1] = str[i];
|
||||
}
|
||||
buff[len] = '\0';
|
||||
buff[len - 2] = '\0';
|
||||
scc_vec_unsafe_from_buffer(const_array_value.data.const_array.elements,
|
||||
buff, len + 1);
|
||||
buff, len - 1);
|
||||
scc_ir_value_ref_t const_array_ref =
|
||||
scc_ir_module_add_value(builder->ctx.module, &const_array_value);
|
||||
Assert(const_array_ref != SCC_IR_REF_NULL);
|
||||
@@ -182,6 +183,7 @@ scc_ir_bblock_ref_t scc_ir_builder_begin_bblock(scc_ir_builder_t *builder,
|
||||
*/
|
||||
void scc_ir_builder_end_bblock(scc_ir_builder_t *builder);
|
||||
|
||||
scc_ir_func_ref_t scc_ir_builder_current_bblock(scc_ir_builder_t *builder);
|
||||
/**
|
||||
* @brief 设置当前基本块
|
||||
*/
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
#define __SCC_IR_DUMP_H__
|
||||
|
||||
#include "ir_prog.h"
|
||||
#include <tree_dump.h>
|
||||
#include <scc_tree_dump.h>
|
||||
|
||||
typedef struct {
|
||||
scc_ir_cprog_t *cprog;
|
||||
scc_tree_dump_ctx_t *dump_ctx;
|
||||
scc_tree_dump_t *dump_ctx;
|
||||
} scc_ir_dump_ctx_t;
|
||||
|
||||
void scc_ir_dump_ctx_init(scc_ir_dump_ctx_t *ctx,
|
||||
scc_tree_dump_ctx_t *tree_dump,
|
||||
void scc_ir_dump_ctx_init(scc_ir_dump_ctx_t *ctx, scc_tree_dump_t *tree_dump,
|
||||
scc_ir_cprog_t *cprog);
|
||||
void scc_ir_dump_value(scc_ir_dump_ctx_t *ctx, scc_ir_value_ref_t node_ref);
|
||||
void scc_ir_dump_type(scc_ir_dump_ctx_t *ctx, scc_ir_type_ref_t type_ref);
|
||||
|
||||
@@ -39,4 +39,11 @@ scc_ir_bblock_t *scc_ir_module_get_bblock(scc_ir_module_t *ctx,
|
||||
scc_ir_func_t *scc_ir_module_get_func(scc_ir_module_t *ctx,
|
||||
scc_ir_func_ref_t ref);
|
||||
|
||||
static inline scc_ir_type_t *
|
||||
scc_ir_module_get_type_by_value(scc_ir_module_t *ctx, scc_ir_value_ref_t ref) {
|
||||
scc_ir_value_t *value = scc_ir_module_get_value(ctx, ref);
|
||||
Assert(value != null);
|
||||
return scc_ir_module_get_type(ctx, value->type);
|
||||
}
|
||||
|
||||
#endif /* __SCC_IR_MODULE_H__ */
|
||||
|
||||
@@ -129,6 +129,10 @@ void scc_ir_builder_set_current_bblock(scc_ir_builder_t *builder,
|
||||
builder->current_bblock = bblock;
|
||||
}
|
||||
|
||||
scc_ir_func_ref_t scc_ir_builder_current_bblock(scc_ir_builder_t *builder) {
|
||||
return builder->current_bblock;
|
||||
}
|
||||
|
||||
void scc_ir_builder_add_instr(scc_ir_builder_t *builder,
|
||||
scc_ir_value_ref_t instr) {
|
||||
scc_ir_bblock_t *current_bblock =
|
||||
@@ -205,6 +209,7 @@ scc_ir_value_ref_t scc_ir_builder_load(scc_ir_builder_t *builder,
|
||||
scc_ir_value_ref_t scc_ir_builder_store(scc_ir_builder_t *builder,
|
||||
scc_ir_value_ref_t target,
|
||||
scc_ir_value_ref_t value) {
|
||||
Assert(target != SCC_IR_REF_NULL && value != SCC_IR_REF_NULL);
|
||||
scc_ir_value_t store_node = {0};
|
||||
store_node.tag = SCC_IR_VALUE_TAG_STORE;
|
||||
store_node.data.store.target = target;
|
||||
|
||||
@@ -112,7 +112,7 @@ static int cmp_type(const void *_key1, const void *_key2) {
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
Panic("Unknown key type %d", key1->tag);
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user