@Override public void visitSelect(Select ins) { isBranch = true; // Add non-default switch edges. InstructionHandle[] targets = ins.getTargets(); for (InstructionHandle target : targets) { targetList.add(new Target(target, SWITCH_EDGE)); } // Add default switch edge. InstructionHandle defaultTarget = ins.getTarget(); if (defaultTarget == null) { throw new IllegalStateException(); } targetList.add(new Target(defaultTarget, SWITCH_DEFAULT_EDGE)); }
InstructionHandle[] itargets = ((Select)bi).getTargets(); InstructionHandle[] ctargets = ((Select)bc).getTargets();
/** * 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); } } } }
/** * Read needed data (e.g. index) from file. */ @Override protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException { super.initFromFile(bytes, wide); // reads padding final int _match_length = bytes.readInt(); setMatch_length(_match_length); final short _fixed_length = (short) (9 + _match_length * 8); setFixed_length(_fixed_length); final short _length = (short) (_match_length + super.getPadding()); super.setLength(_length); super.setMatches(new int[_match_length]); super.setIndices(new int[_match_length]); super.setTargets(new InstructionHandle[_match_length]); for (int i = 0; i < _match_length; i++) { super.setMatch(i, bytes.readInt()); super.setIndices(i, bytes.readInt()); } }
/** * Dump instruction as byte code to stream out. * @param out Output stream */ @Override public void dump( final DataOutputStream out ) throws IOException { super.dump(out); final int _match_length = getMatch_length(); final int low = (_match_length > 0) ? super.getMatch(0) : 0; out.writeInt(low); final int high = (_match_length > 0) ? super.getMatch(_match_length - 1) : 0; out.writeInt(high); for (int i = 0; i < _match_length; i++) { out.writeInt(setIndices(i, getTargetOffset(super.getTarget(i)))); } }
int[] indices = s.getIndices(); throw new ClassGenException("Couldn't find target for switch: " + bi); s.setTarget(j, ih); // Update target
/** * Dump instruction as byte code to stream out. * @param out Output stream */ public void dump(DataOutputStream out) throws IOException { super.dump(out); out.writeInt(match_length); // npairs for(int i=0; i < match_length; i++) { out.writeInt(match[i]); // match-offset pairs out.writeInt(indices[i] = getTargetOffset(targets[i])); } }
/** * Dump instruction as byte code to stream out. * @param out Output stream */ public void dump(DataOutputStream out) throws IOException { out.writeByte(opcode); for(int i=0; i < padding; i++) // Padding bytes out.writeByte(0); index = getTargetOffset(); // Write default target offset out.writeInt(index); }
/** * Read needed data (e.g. index) from file. */ protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException { super.initFromFile(bytes, wide); // reads padding match_length = bytes.readInt(); fixed_length = (short)(9 + match_length * 8); length = (short)(fixed_length + padding); match = new int[match_length]; indices = new int[match_length]; targets = new InstructionHandle[match_length]; for(int i=0; i < match_length; i++) { match[i] = bytes.readInt(); indices[i] = bytes.readInt(); } }
branches.add(bi); final StringBuilder args = new StringBuilder("new int[] { "); final int[] matchs = s.getMatchs(); for (int i = 0; i < matchs.length; i++) { args.append(matchs[i]);
private void updateBranchTargets() { for(Iterator i = branches.iterator(); i.hasNext(); ) { BranchInstruction bi = (BranchInstruction)i.next(); BranchHandle bh = (BranchHandle)branch_map.get(bi); int pos = bh.getPosition(); String name = bi.getName() + "_" + pos; int t_pos = bh.getTarget().getPosition(); _out.println(" " + name + ".setTarget(ih_" + t_pos + ");"); if(bi instanceof Select) { InstructionHandle[] ihs = ((Select)bi).getTargets(); for(int j = 0; j < ihs.length; j++) { t_pos = ihs[j].getPosition(); _out.println(" " + name + ".setTarget(" + j + ", ih_" + t_pos + ");"); } } } }
/** * 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); } } } } } }
/** * Read needed data (e.g. index) from file. */ @Override protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException { super.initFromFile(bytes, wide); final int low = bytes.readInt(); final int high = bytes.readInt(); final int _match_length = high - low + 1; setMatch_length(_match_length); final short _fixed_length = (short) (13 + _match_length * 4); setFixed_length(_fixed_length); super.setLength((short) (_fixed_length + super.getPadding())); super.setMatches(new int[_match_length]); super.setIndices(new int[_match_length]); super.setTargets(new InstructionHandle[_match_length]); for (int i = 0; i < _match_length; i++) { super.setMatch(i, low + i); super.setIndices(i, bytes.readInt()); } }
/** * Dump instruction as byte code to stream out. * @param out Output stream */ @Override public void dump( final DataOutputStream out ) throws IOException { super.dump(out); final int _match_length = getMatch_length(); out.writeInt(_match_length); // npairs for (int i = 0; i < _match_length; i++) { out.writeInt(super.getMatch(i)); // match-offset pairs out.writeInt(setIndices(i, getTargetOffset(super.getTarget(i)))); } }
final int[] indices = s.getIndices(); for (int j = 0; j < indices.length; j++) { target = bi.getPosition() + indices[j]; throw new ClassGenException("Couldn't find target for switch: " + bi); s.setTarget(j, ih); // Update target
/** * Dump instruction as byte code to stream out. * @param out Output stream */ public void dump(DataOutputStream out) throws IOException { super.dump(out); int low = (match_length > 0)? match[0] : 0; out.writeInt(low); int high = (match_length > 0)? match[match_length - 1] : 0; out.writeInt(high); for(int i=0; i < match_length; i++) // jump offsets out.writeInt(indices[i] = getTargetOffset(targets[i])); }
/** * Dump instruction as byte code to stream out. * @param out Output stream */ @Override public void dump( final DataOutputStream out ) throws IOException { out.writeByte(super.getOpcode()); for (int i = 0; i < padding; i++) { out.writeByte(0); } super.setIndex(getTargetOffset()); // Write default target offset out.writeInt(super.getIndex()); }
/** * Read needed data (e.g. index) from file. */ protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException { super.initFromFile(bytes, wide); int low = bytes.readInt(); int high = bytes.readInt(); match_length = high - low + 1; fixed_length = (short)(13 + match_length * 4); length = (short)(fixed_length + padding); match = new int[match_length]; indices = new int[match_length]; targets = new InstructionHandle[match_length]; for(int i=low; i <= high; i++) match[i - low] = i; for(int i=0; i < match_length; i++) { indices[i] = bytes.readInt(); } }
int[] matchs = s.getMatchs();
@Override public void visitSelect(Select ins) { isBranch = true; // Add non-default switch edges. InstructionHandle[] targets = ins.getTargets(); for (InstructionHandle target : targets) { targetList.add(new Target(target, SWITCH_EDGE)); } // Add default switch edge. InstructionHandle defaultTarget = ins.getTarget(); if (defaultTarget == null) { throw new IllegalStateException(); } targetList.add(new Target(defaultTarget, SWITCH_DEFAULT_EDGE)); }