/** * @param verbose toggle output format * @return String containing all instructions in this list. */ public String toString(boolean verbose) { StringBuilder buf = new StringBuilder(); for (InstructionHandle ih = start; ih != null; ih = ih.next) { buf.append(ih.toString(verbose)).append("\n"); } return buf.toString(); }
/** * Remove from instruction `prev' to instruction `next' both contained in this list. Throws * TargetLostException when one of the removed instruction handles is still being targeted. * * @param prev where to start deleting (predecessor, exclusive) * @param next where to end deleting (successor, exclusive) */ private void remove(InstructionHandle prev, InstructionHandle next) throws TargetLostException { InstructionHandle first, last; // First and last deleted instruction if ((prev == null) && (next == null)) { first = start; last = end; start = end = null; } else { if (prev == null) { // At start of list first = start; start = next; } else { first = prev.next; prev.next = next; } if (next == null) { // At end of list last = end; end = prev; } else { last = next.prev; next.prev = prev; } } first.prev = null; // Completely separated from rest of list last.next = null; List<InstructionHandle> target_vec = new ArrayList<InstructionHandle>(); for (InstructionHandle ih = first; ih != null; ih = ih.next) { ih.getInstruction().dispose(); // e.g. BranchInstructions release their targets } StringBuilder buf = new StringBuilder("{ "); for (InstructionHandle ih = first; ih != null; ih = next) { next = ih.next; length--; if (ih.hasTargeters()) { // Still got targeters? target_vec.add(ih); buf.append(ih.toString(true) + " "); ih.next = ih.prev = null; } else { ih.dispose(); } } buf.append("}"); if (!target_vec.isEmpty()) { InstructionHandle[] targeted = new InstructionHandle[target_vec.size()]; target_vec.toArray(targeted); throw new TargetLostException(targeted, buf.toString()); } }