feat(mir): 添加x86架构相关头文件并重构MIR指令表示
- 创建scc_x86_mir.h头文件,定义x86后端MIR指令结构和操作数构造器 - 创建scc_x86_isel.h头文件,定义x86_64指令选择器和相关工具函数 - 创建scc_x86_reg_alloc.h头文件,定义x86寄存器分配架构特定接口 - 移除旧的x86_64_isel.h和x86_64_reg_alloc.h文件 - 重构scc_mir.h中的指令表示,使用联合体存储伪指令数据 - 更新ABI lowering回调参数,使用void指针保持类型无关 - 扩展寄存器分配操作接口,添加指令信息查询和伪指令处理功能 - 更新目标文件包含路径以使用新的头文件命名
This commit is contained in:
@@ -2,52 +2,30 @@
|
||||
#include <scc_mcode.h>
|
||||
#include <scc_mir_module.h>
|
||||
|
||||
#include <arch/scc_x86_mir.h>
|
||||
#include <x86/scc_x86_encode.h>
|
||||
#include <x86/scc_x86_iform.h>
|
||||
#include <x86/scc_x86_reg.h>
|
||||
|
||||
void mir_x86_to_mcode(scc_mcode_t *mcode, const scc_mir_instr_t *ins) {
|
||||
void mir_x86_to_mcode(scc_mcode_t *mcode, const scc_mir_x86_instr_t *_ins) {
|
||||
scc_x86_instr_t *ins = (void *)_ins;
|
||||
if (ins->opcode < 0 || ins->opcode >= SCC_X86_IFORM_COUNT) {
|
||||
return;
|
||||
}
|
||||
scc_x86_operand_value_t ops[8] = {0};
|
||||
for (int i = 0; i < ins->num_operands; i += 1) {
|
||||
switch (ins->operands[i].kind) {
|
||||
case SCC_MIR_OP_VREG:
|
||||
for (int i = 0; i < ins->num_operands; i++) {
|
||||
if (scc_x86_op_is_vreg(&ins->operands[i]))
|
||||
Panic("can't convert vreg to mcode");
|
||||
break;
|
||||
case SCC_MIR_OP_PREG:
|
||||
ops[i].kind = SCC_X86_OPR_REG;
|
||||
ops[i].reg = ins->operands[i].preg;
|
||||
break;
|
||||
case SCC_MIR_OP_STACK_SLOT:
|
||||
Panic("can't convert mem to mcode");
|
||||
break;
|
||||
case SCC_MIR_OP_STACK_OFFSET:
|
||||
// TODO
|
||||
ops[i].kind = SCC_X86_OPR_MEM;
|
||||
ops[i].mem.base = SCC_X86_REG_RSP;
|
||||
ops[i].mem.index = SCC_X86_REG_INVALID;
|
||||
ops[i].mem.scale = 1;
|
||||
ops[i].mem.disp = -ins->operands[i].stack_offset; // 注意符号
|
||||
break;
|
||||
case SCC_MIR_OP_IMM:
|
||||
ops[i].kind = SCC_X86_OPR_IMM;
|
||||
ops[i].imm = ins->operands[i].imm;
|
||||
break;
|
||||
case SCC_MIR_OP_SYMBOL:
|
||||
case SCC_MIR_OP_BLOCK:
|
||||
ops[i].kind = SCC_X86_OPR_RELBR;
|
||||
ops[i].imm = 0;
|
||||
break;
|
||||
default:
|
||||
Panic("unsupported operand kind");
|
||||
};
|
||||
if (scc_x86_op_is_slot(&ins->operands[i]))
|
||||
Panic("can't convert unresolved slot to mcode");
|
||||
ops[i] = ins->operands[i];
|
||||
}
|
||||
scc_x86_encode_inst(mcode, ins->opcode, ops);
|
||||
}
|
||||
|
||||
void scc_ir2mcode_emit_instr(scc_mcode_t *mcode,
|
||||
const scc_mir_instr_t *mir_instr) {
|
||||
// TODO
|
||||
mir_x86_to_mcode(mcode, mir_instr);
|
||||
mir_x86_to_mcode(mcode, (const scc_mir_x86_instr_t *)mir_instr);
|
||||
}
|
||||
|
||||
void scc_ir2mcode(scc_mcode_t *mcode, const scc_mir_module_t *mir_module) {
|
||||
@@ -59,9 +37,11 @@ void scc_ir2mcode(scc_mcode_t *mcode, const scc_mir_module_t *mir_module) {
|
||||
scc_cfg_bblock_id_t id = scc_vec_at(func->bblocks, i);
|
||||
const scc_cfg_bblock_t *bb =
|
||||
scc_cfg_module_unsafe_get_bblock(&mir_module->cfg_module, id);
|
||||
scc_mir_instr_vec_t *instrs = SCC_MIR_BBLOCK_VALUES(bb);
|
||||
const scc_mir_x86_instr_vec_t *instrs =
|
||||
SCC_MIR_BBLOCK_VALUES_PTR(bb);
|
||||
scc_vec_foreach(*instrs, i) {
|
||||
const scc_mir_instr_t *ins = &scc_vec_at(*instrs, i);
|
||||
const scc_mir_instr_t *ins =
|
||||
scc_vec_sized_at_ptr(*instrs, mir_module->instr_size, i);
|
||||
scc_ir2mcode_emit_instr(mcode, ins);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,9 +88,10 @@ void scc_ir2sccf(sccf_builder_t *builder, scc_mir_module_t *mir_module) {
|
||||
scc_cfg_bblock_id_t id = scc_vec_at(func->bblocks, i);
|
||||
const scc_cfg_bblock_t *bb =
|
||||
scc_cfg_module_unsafe_get_bblock(&mir_module->cfg_module, id);
|
||||
scc_mir_instr_vec_t *instrs = SCC_MIR_BBLOCK_VALUES(bb);
|
||||
scc_mir_instr_vec_t *instrs = SCC_MIR_BBLOCK_VALUES_PTR(bb);
|
||||
scc_vec_foreach(*instrs, i) {
|
||||
const scc_mir_instr_t *ins = &scc_vec_at(*instrs, i);
|
||||
const scc_mir_instr_t *ins =
|
||||
scc_vec_sized_at_ptr(*instrs, mir_module->instr_size, i);
|
||||
// FIXME reloc symbol needed
|
||||
scc_ir2mcode_emit_instr(&mcode, ins);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user