feat(ir2mcode): 实现AMD64代码生成器支持控制流和函数调用
- 实现了条件分支、无条件跳转和函数调用的机器码生成 - 添加了跳转目标地址回填机制,处理条件分支和跳转指令的偏移量 - 改进了寄存器分配逻辑,支持函数调用返回值的处理 - 重构了位置解析函数,从返回指针改为传入引用参数 fix(ast2ir): 移除无用的注释代码 - 删除了关于一元操作符映射的注释代码 test: 更新测试框架和测试用例 - 修改测试框架以支持新的可执行文件输出格式 - 添加了条件分支、循环和函数调用的测试用例 - 使用TOML配置文件管理期望的返回值 - 替换标准库头文件为自定义头文件以减少依赖
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void test_example(const char *input, cbool need_sema) {
|
||||
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),
|
||||
@@ -42,7 +42,10 @@ void test_example(const char *input, cbool need_sema) {
|
||||
const sccf_t *sccf = sccf_builder_to_sccf(&mcode_ctx.builder);
|
||||
scc_pe_builder_t pe_builder;
|
||||
sccf2pe(&pe_builder, sccf);
|
||||
scc_pe_dump_to_file(&pe_builder, __FILE__ "/../../test.exe");
|
||||
|
||||
char fname[1024] = {0};
|
||||
scc_snprintf(fname, sizeof(fname), "%s%s%s", __FILE__, "/../../", name);
|
||||
scc_pe_dump_to_file(&pe_builder, fname);
|
||||
}
|
||||
|
||||
int main() {
|
||||
@@ -54,6 +57,31 @@ int main() {
|
||||
" a = a - b + 1;\n"
|
||||
" return a;\n"
|
||||
"}\n",
|
||||
true);
|
||||
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_call.exe");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user