libredex/InstructionLowering.cpp
/*
 * Returns the number of DexInstructions added during lowering (not including
 * the check-cast).
 */
Returns the number of DexInstructions added during lowering (not including
the check-cast).
Returns the number of DexInstructions added during lowering ( not including the check - cast ) .
size_t lower_check_cast(DexMethod*, IRCode* code, IRList::iterator* it_) {
  auto& it = *it_;
  const auto* insn = it->insn;
  size_t extra_instructions{0};
  auto move = ir_list::move_result_pseudo_of(it);
  if (move->dest() != insn->src(0)) {
       move v0, v1
       check-cast v0
     TODO: factor this code a little
    auto move_template = std::make_unique<IRInstruction>(OPCODE_MOVE_OBJECT);
    move_template->set_dest(move->dest());
    move_template->set_src(0, insn->src(0));
    auto* dex_mov = new DexInstruction(select_move_opcode(move_template.get()));
    dex_mov->set_dest(move->dest());
    dex_mov->set_src(0, insn->src(0));
    code->insert_before(it, dex_mov);
    ++extra_instructions;
  }
  auto* dex_insn = new DexOpcodeType(DOPCODE_CHECK_CAST, insn->get_type());
  dex_insn->set_src(0, move->dest());
  it->replace_ir_with_dex(dex_insn);
  remove_move_result_pseudo(++it);
  return extra_instructions;
}
size_t lower_check_cast ( DexMethod * , IRCode * code , IRList :: iterator * it_ ) { auto & it = * it_ ; const auto * insn = it -> insn ; size_t extra_instructions { 0 } ; auto move = ir_list :: move_result_pseudo_of ( it ) ; if ( move -> dest ( ) != insn -> src ( 0 ) ) { auto move_template = std :: make_unique < IRInstruction > ( OPCODE_MOVE_OBJECT ) ; move_template -> set_dest ( move -> dest ( ) ) ; move_template -> set_src ( 0 , insn -> src ( 0 ) ) ; auto * dex_mov = new DexInstruction ( select_move_opcode ( move_template . get ( ) ) ) ; dex_mov -> set_dest ( move -> dest ( ) ) ; dex_mov -> set_src ( 0 , insn -> src ( 0 ) ) ; code -> insert_before ( it , dex_mov ) ; ++ extra_instructions ; } auto * dex_insn = new DexOpcodeType ( DOPCODE_CHECK_CAST , insn -> get_type ( ) ) ; dex_insn -> set_src ( 0 , move -> dest ( ) ) ; it -> replace_ir_with_dex ( dex_insn ) ; remove_move_result_pseudo ( ++ it ) ; return extra_instructions ; }
Returns the number of DexInstructions added during lowering (not including
 the check-cast).
Returns the number of DexInstructions added during lowering ( not including the check - cast ) .
// convert check-cast v1; move-result-pseudo v0 into // //   move v0, v1 //   check-cast v0 // TODO: factor this code a little