/** * @param old_ih old target * @param new_ih new target */ public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { boolean targeted = false; if(target == old_ih) { targeted = true; setTarget(new_ih); } for(int i=0; i < targets.length; i++) { if(targets[i] == old_ih) { targeted = true; setTarget(i, new_ih); } } if(!targeted) throw new ClassGenException("Not targeting " + old_ih); }
/** * @param old_ih old target * @param new_ih new target */ @Override public void updateTarget( final InstructionHandle old_ih, final InstructionHandle new_ih ) { boolean targeted = false; if (super.getTarget() == old_ih) { targeted = true; setTarget(new_ih); } for (int i = 0; i < targets.length; i++) { if (targets[i] == old_ih) { targeted = true; setTarget(i, new_ih); } } if (!targeted) { throw new ClassGenException("Not targeting " + old_ih); } }
/** * (Match, target) pairs for switch. * `Match' and `targets' must have the same length of course. * * @param match array of matching values * @param targets instruction targets * @param defaultTarget default instruction target */ Select(final short opcode, final int[] match, final InstructionHandle[] targets, final InstructionHandle defaultTarget) { // don't set default target before instuction is built super(opcode, null); this.match = match; this.targets = targets; // now it's safe to set default target setTarget(defaultTarget); for (final InstructionHandle target2 : targets) { notifyTarget(null, target2, this); } if ((match_length = match.length) != targets.length) { throw new ClassGenException("Match and target array have not the same length: Match length: " + match.length + " Target length: " + targets.length); } indices = new int[match_length]; }
/** * Redirect all references from old_target to new_target, i.e., update targets * of branch instructions. * * @param old_target the old target instruction handle * @param new_target the new target instruction handle */ public void redirectBranches(InstructionHandle old_target, InstructionHandle new_target) { for(InstructionHandle ih = start; ih != null; ih = ih.next) { Instruction i = ih.getInstruction(); if(i instanceof BranchInstruction) { BranchInstruction b = (BranchInstruction)i; InstructionHandle target = b.getTarget(); if(target == old_target) b.setTarget(new_target); if(b instanceof Select) { // Either LOOKUPSWITCH or TABLESWITCH InstructionHandle[] targets = ((Select)b).getTargets(); for(int j=0; j < targets.length; j++) // Update targets if(targets[j] == old_target) ((Select)b).setTarget(j, new_target); } } } }
/** * Redirect all references from old_target to new_target, i.e., update targets of branch instructions. * * @param old_target * the old target instruction handle * @param new_target * the new target instruction handle */ public void redirectBranches(final InstructionHandle old_target, final InstructionHandle new_target) { for (InstructionHandle ih = start; ih != null; ih = ih.getNext()) { final Instruction i = ih.getInstruction(); if (i instanceof BranchInstruction) { final BranchInstruction b = (BranchInstruction) i; final InstructionHandle target = b.getTarget(); if (target == old_target) { b.setTarget(new_target); } if (b instanceof Select) { // Either LOOKUPSWITCH or TABLESWITCH final InstructionHandle[] targets = ((Select) b).getTargets(); for (int j = 0; j < targets.length; j++) { if (targets[j] == old_target) { ((Select) b).setTarget(j, new_target); } } } } } }
throw new ClassGenException("Couldn't find target for switch: " + bi); s.setTarget(j, ih); // Update target
throw new ClassGenException("Couldn't find target for switch: " + bi); s.setTarget(j, ih); // Update target