feat(ir): 实现函数调用和参数处理功能

- 在AST定义中移除函数调用结构体中的冗余name字段
- 实现完整的函数声明和定义处理流程,支持符号表查找
- 添加函数参数引用节点类型,支持参数传递和访问
- 实现函数调用的IR生成,包括参数处理和符号解析
- 添加断言确保节点有效性,提升代码健壮性

fix(ast2ir): 优化类型转换处理逻辑

- 移除多余的注释说明
- 简化参数为空检查逻辑,提高代码简洁性
- 修复函数调用时的符号表查找机制

refactor(ir): 改进IR构建器接口设计

- 修改函数构建相关API,使接口更加清晰
- 添加函数声明集合管理
- 重构内置类型缓存机制

feat(ir2mcode): 完善AMD64代码生成

- 实现函数参数到寄存器的映射
- 添加函数调用约定支持(最多4个参数)
- 实现函数符号和重定位处理
- 添加栈帧管理机制
- 修正栈偏移计算

chore(ir): 清理和优化IR dump输出

- 更新节点类型描述信息
- 改进函数声明和定义的输出格式
- 修正格式化输出中的符号显示问题

style: 代码格式化和命名规范化

- 统一重定位类型枚举命名
- 优化函数参数验证和错误处理
This commit is contained in:
zzy
2026-03-23 16:02:23 +08:00
parent 097dbdcc2a
commit 741171dbba
17 changed files with 356 additions and 152 deletions

View File

@@ -167,7 +167,7 @@ void sccf2pe(scc_pe_builder_t *builder, const sccf_t *sccf) {
scc_pe_buffer_t idata_buffer =
scc_pe_construct_idata(&idata_builder, &idata_range);
u32 entry_point_offset = 0;
u32 entry_point_offset = sccf->header.entry_point;
u64 base_address = 0x140000000;
u32 entry_point = code_range.virual_address + entry_point_offset;
scc_pe_config_t config = (scc_pe_config_t){
@@ -197,6 +197,9 @@ void sccf2pe(scc_pe_builder_t *builder, const sccf_t *sccf) {
scc_vec_foreach(relocs, i) {
sccf_reloc_t *reloc = &scc_vec_at(relocs, i);
if (reloc->reloc_type == SCCF_RELOC_TYPE_EMPTY) {
continue;
}
sccf_sym_t *sym = &scc_vec_at(symtab, reloc->sym_idx);
const char *name = &scc_vec_at(strtab, sym->name_offset);
@@ -212,7 +215,7 @@ void sccf2pe(scc_pe_builder_t *builder, const sccf_t *sccf) {
}
Assert(rva != 0);
if (reloc->type == SCCF_RELOC_ABS) {
if (reloc->reloc_type == SCCF_RELOC_TYPE_ABS) {
TODO();
}
Assert(reloc->sect_type == SCCF_SECT_CODE);

View File

@@ -51,16 +51,18 @@ int main() {
.sccf_sym_type = SCCF_SYM_TYPE_EXTERN,
.sccf_sym_vis = SCCF_SYM_VIS_DEFAULT,
});
sccf_builder_add_reloc(&builder, (sccf_reloc_t){.addend = 4,
.offset = 7,
.sect_type = SCCF_SECT_CODE,
.sym_idx = str_idx,
.type = SCCF_RELOC_REL});
sccf_builder_add_reloc(&builder, (sccf_reloc_t){.addend = 4,
.offset = 13,
.sect_type = SCCF_SECT_CODE,
.sym_idx = puts_idx,
.type = SCCF_RELOC_REL});
sccf_builder_add_reloc(&builder,
(sccf_reloc_t){.addend = 4,
.offset = 7,
.sect_type = SCCF_SECT_CODE,
.sym_idx = str_idx,
.reloc_type = SCCF_RELOC_TYPE_REL});
sccf_builder_add_reloc(&builder,
(sccf_reloc_t){.addend = 4,
.offset = 13,
.sect_type = SCCF_SECT_CODE,
.sym_idx = puts_idx,
.reloc_type = SCCF_RELOC_TYPE_REL});
const sccf_t *sccf = sccf_builder_to_sccf(&builder);
scc_pe_builder_t pe_builder;