- 移除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模块的机器码生成 - 实现基本块间重定位的地址解析和补丁应用 - 改进符号重定位的处理机制 - 简化机器码段数据的最终处理流程
101 lines
3.9 KiB
C
101 lines
3.9 KiB
C
#ifndef __SCC_X86_MIR_H__
|
||
#define __SCC_X86_MIR_H__
|
||
|
||
#include "../scc_mir.h"
|
||
#include <scc_cfg.h>
|
||
#include <scc_pos.h>
|
||
#include <x86/scc_x86_encode.h>
|
||
#include <x86/scc_x86_iform.h>
|
||
#include <x86/scc_x86_reg.h>
|
||
|
||
typedef struct {
|
||
int opcode;
|
||
uint8_t num_operands;
|
||
scc_x86_operand_value_t operands[6];
|
||
scc_pos_t src_loc;
|
||
} scc_x86_instr_t;
|
||
|
||
// x86 后端指令:首字段 int opcode(正 = scc_x86_iform_t,负 = 伪指令)
|
||
typedef union scc_mir_x86_instr {
|
||
scc_mir_instr_t instr;
|
||
scc_x86_instr_t x86_instr;
|
||
} scc_mir_x86_instr_t;
|
||
|
||
typedef SCC_VEC(scc_mir_x86_instr_t) scc_mir_x86_instr_vec_t;
|
||
|
||
// ── 基本块 values 强制转换 ──────────────────────────────────────────────
|
||
|
||
#define SCC_MIR_X86_BBLOCK_INSTRS(bb) ((scc_mir_x86_instr_vec_t *)&bb->values)
|
||
#define SCC_MIR_X86_BBLOCK_INSTRS_C(bb) \
|
||
((const scc_mir_x86_instr_vec_t *)&bb->values)
|
||
|
||
// ── vreg 编码 ──────────────────────────────────────────────────────────
|
||
static inline bool scc_x86_op_is_vreg(const scc_x86_operand_value_t *op) {
|
||
return op->kind == SCC_X86_OPR_REG &&
|
||
(int)op->reg >= (int)SCC_X86_REG_COUNT;
|
||
}
|
||
static inline int scc_x86_op_get_vreg(const scc_x86_operand_value_t *op) {
|
||
return (int)op->reg - (int)SCC_X86_REG_COUNT;
|
||
}
|
||
static inline void scc_x86_op_set_preg(scc_x86_operand_value_t *op,
|
||
scc_x86_reg_t preg) {
|
||
op->kind = SCC_X86_OPR_REG;
|
||
op->reg = preg;
|
||
}
|
||
|
||
// slot_id 编码为 base=INVALID, disp=slot_id
|
||
static inline scc_x86_operand_value_t scc_x86_op_slot(int slot_id) {
|
||
scc_x86_operand_value_t o = {.kind = SCC_X86_OPR_MEM};
|
||
o.mem.base = SCC_X86_REG_INVALID;
|
||
o.mem.index = SCC_X86_REG_INVALID;
|
||
o.mem.scale = 1;
|
||
o.mem.disp.displacement = slot_id;
|
||
o.mem.disp.displacement_bits = 0;
|
||
return o;
|
||
}
|
||
static inline bool scc_x86_op_is_slot(const scc_x86_operand_value_t *op) {
|
||
return op->kind == SCC_X86_OPR_MEM && op->mem.base == SCC_X86_REG_INVALID;
|
||
}
|
||
static inline int scc_x86_op_slot_id(const scc_x86_operand_value_t *op) {
|
||
return op->mem.disp.displacement;
|
||
}
|
||
|
||
static inline void scc_mir_x86_instr_0(scc_mir_x86_instr_t *out, int opcode,
|
||
scc_pos_t pos) {
|
||
out->x86_instr.opcode = opcode;
|
||
out->x86_instr.num_operands = 0;
|
||
out->x86_instr.src_loc = pos;
|
||
}
|
||
static inline void scc_mir_x86_instr_1(scc_mir_x86_instr_t *out, int opcode,
|
||
scc_x86_operand_value_t op0,
|
||
scc_pos_t pos) {
|
||
out->x86_instr.opcode = opcode;
|
||
out->x86_instr.num_operands = 1;
|
||
out->x86_instr.operands[0] = op0;
|
||
out->x86_instr.src_loc = pos;
|
||
}
|
||
static inline void scc_mir_x86_instr_2(scc_mir_x86_instr_t *out, int opcode,
|
||
scc_x86_operand_value_t op0,
|
||
scc_x86_operand_value_t op1,
|
||
scc_pos_t pos) {
|
||
out->x86_instr.opcode = opcode;
|
||
out->x86_instr.num_operands = 2;
|
||
out->x86_instr.operands[0] = op0;
|
||
out->x86_instr.operands[1] = op1;
|
||
out->x86_instr.src_loc = pos;
|
||
}
|
||
static inline void scc_mir_x86_instr_3(scc_mir_x86_instr_t *out, int opcode,
|
||
scc_x86_operand_value_t op0,
|
||
scc_x86_operand_value_t op1,
|
||
scc_x86_operand_value_t op2,
|
||
scc_pos_t pos) {
|
||
out->x86_instr.opcode = opcode;
|
||
out->x86_instr.num_operands = 3;
|
||
out->x86_instr.operands[0] = op0;
|
||
out->x86_instr.operands[1] = op1;
|
||
out->x86_instr.operands[2] = op2;
|
||
out->x86_instr.src_loc = pos;
|
||
}
|
||
|
||
#endif /* __SCC_X86_MIR_H__ */
|