- 移除SCC_LIR_LEA指令类型,改用SCC_LIR_LOAD_ADDR - 在scc_lir_func_meta_t中添加is_va_arg字段用于标识可变参数函数 - 修改scc_hir2lir函数参数类型,移除const限定符 - 更新比较操作的指令映射逻辑,将条件信息存储在metadata中 - 调整代码结构,在各个switch case分支中统一使用"} break"格式 fix(x86-isel): 修复x86指令选择中的立即数和重定位处理 - 修改emit_direct_call函数以正确处理全局符号重定位 - 更新立即数字段访问从imm到imm0 - 添加新的重定位操作数类型SCC_X86_OPR_RELOC - 实现重定位目标类型的完整处理逻辑,包括基本块和符号 refactor(x86-mir): 重构x86操作数结构以支持重定位机制 - 将内存操作数的disp字段改为结构体形式包含displacement信息 - 移除不再使用的常用操作数构造器函数 - 保留并完善slot操作数构造器 - 更新内存操作数的调试输出格式 feat(ir2mcode): 添加重定位表支持以处理符号引用 - 定义新的重定位结构体scc_reloc_t用于记录重定位信息 - 修改scc_ir2mcode_emit_instr函数签名以传递重定位表 - 实现重定位补丁应用功能scc_ir2mcode_patch - 更新机器码生成流程以收集和处理重定位信息 refactor(ir2sccf): 重构SCEF文件生成以支持重定位处理 - 提取独立的emit_mir_module函数处理MIR模块的机器码生成 - 实现基本块间重定位的地址解析和补丁应用 - 改进符号重定位的处理机制 - 简化机器码段数据的最终处理流程
70 lines
2.9 KiB
C
70 lines
2.9 KiB
C
#ifndef __SCC_X86_ISEL_H__
|
|
#define __SCC_X86_ISEL_H__
|
|
|
|
#include <scc_lir_module.h>
|
|
#include <scc_tree_dump.h>
|
|
|
|
#include "../core_pass/scc_abi_lowering.h"
|
|
#include "scc_x86_mir.h"
|
|
|
|
typedef struct scc_x86_64_isel {
|
|
scc_mir_x86_instr_vec_t instrs;
|
|
scc_mir_func_t *func;
|
|
scc_pos_t pos;
|
|
scc_abi_lowering_t abi_lowering;
|
|
} scc_x86_64_isel_t;
|
|
|
|
void scc_isel_x86_64(scc_mir_module_t *mir_module,
|
|
const scc_lir_module_t *lir_module,
|
|
scc_x86_64_isel_t *isel);
|
|
|
|
// Utils
|
|
void scc_x86_emit_move(scc_x86_64_isel_t *isel, scc_x86_operand_value_t dst,
|
|
scc_x86_operand_value_t src, u8 size);
|
|
scc_x86_operand_value_t scc_x86_lir_val_to_mir_op(scc_x86_64_isel_t *isel,
|
|
const scc_lir_val_t *val);
|
|
static inline void emit_direct_call(scc_x86_64_isel_t *isel,
|
|
const char *callee) {
|
|
scc_mir_x86_instr_t instr = {0};
|
|
scc_x86_operand_value_t op = scc_x86_op_reloc_global_relbr(callee, 0);
|
|
scc_mir_x86_instr_1(&instr, SCC_X86_IFORM_CALL_NEAR_RELBRZ, op,
|
|
scc_pos_create());
|
|
scc_vec_push(isel->instrs, instr);
|
|
}
|
|
|
|
static inline void emit_indirect_call(scc_x86_64_isel_t *isel,
|
|
scc_x86_operand_value_t reg) {
|
|
scc_mir_x86_instr_t instr = {0};
|
|
scc_mir_x86_instr_1(&instr, SCC_X86_IFORM_CALL_NEAR_GPRV, reg,
|
|
scc_pos_create());
|
|
}
|
|
|
|
static inline void emit_ret(scc_x86_64_isel_t *isel) {
|
|
scc_mir_x86_instr_t instr = {0};
|
|
scc_mir_x86_instr_0(&instr, SCC_X86_IFORM_RET_NEAR, scc_pos_create());
|
|
scc_vec_push(isel->instrs, instr);
|
|
}
|
|
|
|
#define add_instr_0(isel, iform) \
|
|
do { \
|
|
scc_mir_x86_instr_t instr; \
|
|
scc_mir_x86_instr_0(&instr, (iform), (isel)->pos); \
|
|
scc_vec_push((isel)->instrs, instr); \
|
|
} while (0)
|
|
|
|
#define add_instr_1(isel, iform, arg1) \
|
|
do { \
|
|
scc_mir_x86_instr_t instr; \
|
|
scc_mir_x86_instr_1(&instr, (iform), (arg1), (isel)->pos); \
|
|
scc_vec_push((isel)->instrs, instr); \
|
|
} while (0)
|
|
|
|
#define add_instr_2(isel, iform, arg1, arg2) \
|
|
do { \
|
|
scc_mir_x86_instr_t instr; \
|
|
scc_mir_x86_instr_2(&instr, (iform), (arg1), (arg2), (isel)->pos); \
|
|
scc_vec_push((isel)->instrs, instr); \
|
|
} while (0)
|
|
|
|
#endif /* __SCC_X86_ISEL_H__ */
|