void test_emit_add_imm(void) { assert_emit_insn_3(0x83, 0xc0, 0x04, imm_reg_insn(INSN_ADD_IMM_REG, 0x04, &VAR_EAX)); assert_emit_insn_3(0x83, 0xc3, 0x08, imm_reg_insn(INSN_ADD_IMM_REG, 0x08, &VAR_EBX)); assert_emit_insn_6(0x81, 0xc3, 0x80, 0x00, 0x00, 0x00, imm_reg_insn(INSN_ADD_IMM_REG, 0x80, &VAR_EBX)); assert_emit_insn_6(0x81, 0xc0, 0xef, 0xbe, 0xad, 0xde, imm_reg_insn(INSN_ADD_IMM_REG, 0xdeadbeef, &VAR_EAX)); }
void test_emit_mov_imm(void) { assert_emit_insn_5(0xb8, 0x04, 0x00, 0x00, 0x00, imm_reg_insn(INSN_MOV_IMM_REG, 0x04, &VAR_EAX)); assert_emit_insn_5(0xb8, 0xef, 0xbe, 0xad, 0xde, imm_reg_insn(INSN_MOV_IMM_REG, 0xdeadbeef, &VAR_EAX)); assert_emit_insn_5(0xbb, 0xbe, 0xba, 0xfe, 0xca, imm_reg_insn(INSN_MOV_IMM_REG, 0xcafebabe, &VAR_EBX)); assert_emit_insn_5(0xb9, 0xbe, 0xba, 0xfe, 0xca, imm_reg_insn(INSN_MOV_IMM_REG, 0xcafebabe, &VAR_ECX)); assert_emit_insn_5(0xba, 0xbe, 0xba, 0xfe, 0xca, imm_reg_insn(INSN_MOV_IMM_REG, 0xcafebabe, &VAR_EDX)); }
static void assert_emit_target_for_backward_branches(unsigned char expected_prefix, unsigned char expected_opc, enum insn_type insn_type) { struct basic_block *target_bb; struct compilation_unit *cu; struct var_info *eax, *ebx; cu = compilation_unit_alloc(&method); eax = get_fixed_var(cu, MACH_REG_EAX); ebx = get_fixed_var(cu, MACH_REG_EBX); target_bb = get_basic_block(cu, 0, 1); bb_add_insn(target_bb, imm_reg_insn(INSN_ADD_IMM_REG, 0x01, eax)); assert_emits_branch_target(expected_prefix, expected_opc, 0xf8, 0xff, 0xff, 0xff, target_bb, insn_type); bb_add_insn(target_bb, imm_reg_insn(INSN_ADD_IMM_REG, 0x02, ebx)); assert_emits_branch_target(expected_prefix, expected_opc, 0xf5, 0xff, 0xff, 0xff, target_bb, insn_type); free_compilation_unit(cu); }
static void assert_backpatches_unresolved_branches_when_emitting_target( unsigned char expected_prefix, unsigned char expected_opc, enum insn_type insn_type) { struct basic_block *target_bb, *branch_bb; struct compilation_unit *cu; struct var_info *eax; cu = compilation_unit_alloc(&method); eax = get_fixed_var(cu, MACH_REG_EAX); branch_bb = get_basic_block(cu, 0, 1); target_bb = get_basic_block(cu, 1, 2); bb_add_insn(branch_bb, branch_insn(insn_type, target_bb)); assert_backpatches_branches(expected_prefix, expected_opc, 0x00, branch_bb, target_bb); bb_add_insn(branch_bb, imm_reg_insn(INSN_ADD_IMM_REG, 0x01, eax)); assert_backpatches_branches(expected_prefix, expected_opc, 0x03, branch_bb, target_bb); free_compilation_unit(cu); }
void test_emit_cmp_imm_reg(void) { assert_emit_insn_3(0x83, 0xf8, 0x04, imm_reg_insn(INSN_CMP_IMM_REG, 0x04, &VAR_EAX)); assert_emit_insn_3(0x83, 0xfb, 0x08, imm_reg_insn(INSN_CMP_IMM_REG, 0x08, &VAR_EBX)); assert_emit_insn_6(0x81, 0xfb, 0xef, 0xbe, 0xad, 0xde, imm_reg_insn(INSN_CMP_IMM_REG, 0xdeadbeef, &VAR_EBX)); }
void test_emit_sar_imm_reg(void) { assert_emit_insn_3(0xc1, 0xf8, 0x04, imm_reg_insn(INSN_SAR_IMM_REG, 0x04, &VAR_EAX)); assert_emit_insn_3(0xc1, 0xfb, 0x05, imm_reg_insn(INSN_SAR_IMM_REG, 0x05, &VAR_EBX)); }
void test_imm_reg_defines_target(void) { assert_defines_r0(imm_reg_insn(INSN_ADD_IMM_REG, 0xdeadbeef, &r0)); assert_uses_r0(imm_reg_insn(INSN_CMP_IMM_REG, 0xdeadbeef, &r0)); assert_defines_r0(imm_reg_insn(INSN_MOV_IMM_REG, 0xdeadbeef, &r0)); }