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:
zzy
2026-04-03 20:10:51 +08:00
parent 78e7c800ba
commit ca187c78f1
42 changed files with 1264 additions and 1212 deletions

View File

@@ -1,8 +0,0 @@
#include "scc_stdio.h"
int main(void) {
puts("hello world");
const char *str = "hello world";
puts(str);
return 0;
}

9
tests/simple/12_logic.c Normal file
View File

@@ -0,0 +1,9 @@
int check(int i) { return i >= 0 && i < 10; }
int main() {
int num = 0;
for (int i = 0; check(i); i += 1) {
num = num + 1;
}
return num;
}

8
tests/simple/13_array.c Normal file
View File

@@ -0,0 +1,8 @@
int main(void) {
char buff[] = "hello buffer";
int res = 0;
for (char *ptr = buff; *ptr != 0; ptr += 1) {
res += *ptr;
}
return res;
}

View File

@@ -1,4 +1,5 @@
[return_val_cases]
# windows: echo $LASTEXITCODE
"./01_return.c" = 65536
"./02_decl_expr.c" = 1
"./03_decl_init.c" = 11
@@ -10,4 +11,6 @@
"./09_for.c" = 10
"./10_main.c" = 3
"./11_recursive.c" = 120
"./12_logic.c" = 10
"./13_array.c" = 1198
[stdout_val_cases]

View File

@@ -2,5 +2,6 @@
#define __SCC_STDIO_H__
extern int puts(const char *str);
extern char *gets(char *buff);
#endif