BasicBlock toBasicBlock() { InsnList result = new InsnList(instructions.size()); for (int i = 0; i < instructions.size(); i++) { result.set(i, instructions.get(i)); } result.setImmutable(); int primarySuccessorIndex = -1; IntList successors = new IntList(); for (Label catchLabel : catchLabels) { successors.add(catchLabel.id); } if (primarySuccessor != null) { primarySuccessorIndex = primarySuccessor.id; successors.add(primarySuccessorIndex); } if (alternateSuccessor != null) { successors.add(alternateSuccessor.id); } successors.setImmutable(); return new BasicBlock(id, result, successors, primarySuccessorIndex); } }
/** * Gets the element at the given index. It is an error to call * this with the index for an element which was never set; if you * do that, this will throw {@code NullPointerException}. * * @param n {@code >= 0, < size();} which index * @return {@code non-null;} element at that index */ public Insn get(int n) { return (Insn) get0(n); }
/** * Returns an instance that is identical to this one, except that * the registers in each instruction are offset by the given * amount. Mutability of the result is inherited from the * original. * * @param delta the amount to offset register numbers by * @return {@code non-null;} an appropriately-constructed instance */ public InsnList withRegisterOffset(int delta) { int sz = size(); InsnList result = new InsnList(sz); for (int i = 0; i < sz; i++) { Insn one = (Insn) get0(i); if (one != null) { result.set0(i, one.withRegisterOffset(delta)); } } if (isImmutable()) { result.setImmutable(); } return result; } }
sz = insns.size(); for (int i = 0; i < sz; i++) { if (insns.get(i).getOpcode() != Rops.MOVE_RETURN_ADDRESS) { newSz++; InsnList newInsns = new InsnList(newSz); Insn insn = insns.get(i); if (insn.getOpcode() != Rops.MOVE_RETURN_ADDRESS) { newInsns.set(newIndex++, insn); newInsns.setImmutable(); return newInsns;
/** * Gets the last instruction of this block. This is just a * convenient shorthand for {@code getInsns().getLast()}. * * @return {@code non-null;} the last instruction */ public Insn getLastInsn() { return insns.getLast(); }
/** * Visits each instruction of each block in the list, in order. * * @param visitor {@code non-null;} visitor to use */ public void forEachInsn(Insn.Visitor visitor) { int sz = size(); for (int i = 0; i < sz; i++) { BasicBlock one = get(i); InsnList insns = one.getInsns(); insns.forEach(visitor); } }
/** * Sets the instruction at the given index. * * @param n {@code >= 0, < size();} which index * @param insn {@code non-null;} the instruction to set at {@code n} */ public void set(int n, Insn insn) { set0(n, insn); }
/** * Helper method to compare the contents of two blocks. * * @param a {@code non-null;} a block to compare * @param b {@code non-null;} another block to compare * @return {@code true} iff the two blocks' instructions are the same */ private static boolean compareInsns(BasicBlock a, BasicBlock b) { return a.getInsns().contentEquals(b.getInsns()); }
/** * Gets the first instruction of this block. This is just a * convenient shorthand for {@code getInsns().get(0)}. * * @return {@code non-null;} the first instruction */ public Insn getFirstInsn() { return insns.get(0); }
/** * Returns an instance that is identical to this one, except that * the registers in each instruction are offset by the given * amount. Mutability of the result is inherited from the * original. * * @param delta the amount to offset register numbers by * @return {@code non-null;} an appropriately-constructed instance */ public InsnList withRegisterOffset(int delta) { int sz = size(); InsnList result = new InsnList(sz); for (int i = 0; i < sz; i++) { Insn one = (Insn) get0(i); if (one != null) { result.set0(i, one.withRegisterOffset(delta)); } } if (isImmutable()) { result.setImmutable(); } return result; } }
sz = insns.size(); for (int i = 0; i < sz; i++) { if (insns.get(i).getOpcode() != Rops.MOVE_RETURN_ADDRESS) { newSz++; InsnList newInsns = new InsnList(newSz); Insn insn = insns.get(i); if (insn.getOpcode() != Rops.MOVE_RETURN_ADDRESS) { newInsns.set(newIndex++, insn); newInsns.setImmutable(); return newInsns;
/** * Gets the last instruction of this block. This is just a * convenient shorthand for {@code getInsns().getLast()}. * * @return {@code non-null;} the last instruction */ public Insn getLastInsn() { return insns.getLast(); }
/** * Visits each instruction of each block in the list, in order. * * @param visitor {@code non-null;} visitor to use */ public void forEachInsn(Insn.Visitor visitor) { int sz = size(); for (int i = 0; i < sz; i++) { BasicBlock one = get(i); InsnList insns = one.getInsns(); insns.forEach(visitor); } }
/** * Sets the instruction at the given index. * * @param n {@code >= 0, < size();} which index * @param insn {@code non-null;} the instruction to set at {@code n} */ public void set(int n, Insn insn) { set0(n, insn); }
/** * Helper method to compare the contents of two blocks. * * @param a {@code non-null;} a block to compare * @param b {@code non-null;} another block to compare * @return {@code true} iff the two blocks' instructions are the same */ private static boolean compareInsns(BasicBlock a, BasicBlock b) { return a.getInsns().contentEquals(b.getInsns()); }
/** * Gets the first instruction of this block. This is just a * convenient shorthand for {@code getInsns().get(0)}. * * @return {@code non-null;} the first instruction */ public Insn getFirstInsn() { return insns.get(0); }
/** * Returns an instance that is identical to this one, except that * the registers in each instruction are offset by the given * amount. Mutability of the result is inherited from the * original. * * @param delta the amount to offset register numbers by * @return {@code non-null;} an appropriately-constructed instance */ public InsnList withRegisterOffset(int delta) { int sz = size(); InsnList result = new InsnList(sz); for (int i = 0; i < sz; i++) { Insn one = (Insn) get0(i); if (one != null) { result.set0(i, one.withRegisterOffset(delta)); } } if (isImmutable()) { result.setImmutable(); } return result; } }
/** * Converts an insn list to rop form. * * @param ssaInsns {@code non-null;} old instructions * @return {@code non-null;} immutable instruction list */ private InsnList convertInsns(ArrayList<SsaInsn> ssaInsns) { int insnCount = ssaInsns.size(); InsnList result = new InsnList(insnCount); for (int i = 0; i < insnCount; i++) { result.set(i, ssaInsns.get(i).toRopInsn()); } result.setImmutable(); return result; }
sz = insns.size(); for (int i = 0; i < sz; i++) { if (insns.get(i).getOpcode() != Rops.MOVE_RETURN_ADDRESS) { newSz++; InsnList newInsns = new InsnList(newSz); Insn insn = insns.get(i); if (insn.getOpcode() != Rops.MOVE_RETURN_ADDRESS) { newInsns.set(newIndex++, insn); newInsns.setImmutable(); return newInsns;