void MethodBlock::load_const(Location& loc, DexType* value) { always_assert(!loc.is_wide()); DexInstruction* load = new DexOpcodeType(OPCODE_CONST_CLASS, value); load->set_dest(reg_num(loc)); loc.type = get_class_type(); push_instruction(load); }
void MethodBlock::load_const(Location& loc, DexString* value) { always_assert(!loc.is_wide()); DexInstruction* load = new DexOpcodeString(OPCODE_CONST_STRING, value); load->set_dest(reg_num(loc)); loc.type = get_string_type(); push_instruction(load); }
void MethodBlock::load_null(Location& loc) { always_assert(!loc.is_wide()); DexInstruction* load = new DexInstruction(OPCODE_CONST_4); load->set_dest(reg_num(loc)); load->set_literal(0); loc.type = get_object_type(); push_instruction(load); }
void MethodBlock::load_const(Location& loc, double value) { always_assert(loc.is_wide()); DexInstruction* load = new DexInstruction(OPCODE_CONST_WIDE); load->set_dest(reg_num(loc)); load->set_literal(value); loc.type = get_double_type(); push_instruction(load); }
void MethodBlock::move(Location src, Location& dst) { always_assert(src.is_compatible(dst.type)); auto ch = type_shorty(dst.type); assert(ch != 'V'); DexOpcode opcode; if (ch == 'L') opcode = OPCODE_MOVE_OBJECT; else if (ch == 'J' || ch == 'D') opcode = OPCODE_MOVE_WIDE; else opcode = OPCODE_MOVE; DexInstruction* move = new DexInstruction(opcode); move->set_dest(reg_num(dst)); move->set_src(0, reg_num(src)); dst.type = src.type; push_instruction(move); }
std::unique_ptr<DexCode>& MethodCreator::to_code() { std::unique_ptr<DexCode> code(new DexCode()); code->set_registers_size(top_reg); code->set_ins_size(ins_count()); code->set_outs_size(out_count); method->set_code(std::move(code)); for (auto& mi : *meth_code->m_fmethod) { if (mi.type == MFLOW_OPCODE) { DexInstruction* insn = mi.insn; if (insn->dests_size()) { insn->set_dest(get_real_reg_num(insn->dest())); } for (int i = 0; i < static_cast<int>(insn->srcs_size()); i++) { insn->set_src(i, get_real_reg_num(insn->src(i))); } } } while (!meth_code->try_sync()) ; return method->get_code(); }