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); } }
/** * Makes a frame for a subroutine start block, given that this is the * ending frame of one of the subroutine's calling blocks. Subroutine * calls may be nested and thus may have nested locals state, so we * start with an initial state as seen by the subroutine, but keep track * of the individual locals states that will be expected when the individual * subroutine calls return. * * @param subLabel label of subroutine start block * @param callerLabel {@code >=0;} label of the caller block where this frame * came from. * @return a new instance to begin a called subroutine. */ public Frame makeNewSubroutineStartFrame(int subLabel, int callerLabel) { IntList newSubroutines = subroutines.mutableCopy(); newSubroutines.add(subLabel); Frame newFrame = new Frame(locals.getPrimary(), stack, IntList.makeImmutable(subLabel)); return newFrame.mergeWithSubroutineCaller(this, subLabel, callerLabel); }
/** {@inheritDoc} */ @Override public void add(int value) { int index = ints.binarysearch(value); if (index < 0) { ints.insert(-(index + 1), value); } }
/** * Adds an element to the end of the list. This will increase the * list's capacity if necessary. * * @param value the value to add */ public void add(int value) { throwIfImmutable(); growIfNeeded(); values[size++] = value; if (sorted && (size > 1)) { sorted = (value >= values[size - 2]); } }
/** {@inheritDoc} */ public void remove(int value) { int index = ints.indexOf(value); if (index >= 0) { ints.removeIndex(index); } }
/** * Replaces one of a block's successors with a different label. Constructs * an updated BasicBlock instance and places it in {@code newBlocks}. * * @param block block to replace * @param oldLabel label of successor to replace * @param newLabel label of new successor */ private void replaceSucc(BasicBlock block, int oldLabel, int newLabel) { IntList newSuccessors = block.getSuccessors().mutableCopy(); int newPrimarySuccessor; newSuccessors.set(newSuccessors.indexOf(oldLabel), newLabel); newPrimarySuccessor = block.getPrimarySuccessor(); if (newPrimarySuccessor == oldLabel) { newPrimarySuccessor = newLabel; } newSuccessors.setImmutable(); BasicBlock newBB = new BasicBlock(block.getLabel(), block.getInsns(), newSuccessors, newPrimarySuccessor); newBlocks.set(newBlocks.indexOfLabel(block.getLabel()), newBB); } }
/** {@inheritDoc} */ @Override public boolean has(int value) { return ints.indexOf(value) >= 0; }
/** * Constructs a new instance that is a copy of the old instance. * * @param old instance to copy */ public LabeledList(LabeledList old) { super(old.size()); labelToIndex = old.labelToIndex.mutableCopy(); int sz = old.size(); for (int i = 0; i < sz; i++) { Object one = old.get0(i); if (one != null) { set0(i, one); } } }
/** {@inheritDoc} */ @Override public void setImmutable() { values.setImmutable(); targets.setImmutable(); super.setImmutable(); }
/** * Returns the index of the given value, or -1 if the value does not * appear in the list. This will do a binary search if the list is * sorted or a linear search if not. * * @param value value to find * @return index of value or -1 */ public int indexOf(int value) { int ret = binarysearch(value); return ret >= 0 ? ret : -1; }
/** * Gets the default target. This is just a shorthand for * {@code getTarget(size())}. * * @return {@code >= 0;} the default target */ public int getDefaultTarget() { return targets.get(size); }
/** * Inserts element into specified index, moving elements at and above * that index up one. May not be used to insert at an index beyond the * current size (that is, insertion as a last element is legal but * no further). * * @param n {@code >= 0, <=size();} index of where to insert * @param value value to insert */ public void insert(int n, int value) { if (n > size) { throw new IndexOutOfBoundsException("n > size()"); } growIfNeeded(); System.arraycopy (values, n, values, n+1, size - n); values[n] = value; size++; sorted = sorted && (n == 0 || value > values[n-1]) && (n == (size - 1) || value < values[n+1]); }
@Override public void visitBlock(BasicBlock b) { if (isSubroutineCaller(b)) { reachableSubroutineCallerLabels.add(b.getLabel()); } } });
/** * Creates a new OneToOneRegisterMapper. * * @param countOldRegisters the number of registers in the old name space */ public BasicRegisterMapper(int countOldRegisters) { oldToNew = new IntList(countOldRegisters); }
/** * Makes a frame for a subroutine start block, given that this is the * ending frame of one of the subroutine's calling blocks. Subroutine * calls may be nested and thus may have nested locals state, so we * start with an initial state as seen by the subroutine, but keep track * of the individual locals states that will be expected when the individual * subroutine calls return. * * @param subLabel label of subroutine start block * @param callerLabel {@code >=0;} label of the caller block where this frame * came from. * @return a new instance to begin a called subroutine. */ public Frame makeNewSubroutineStartFrame(int subLabel, int callerLabel) { IntList newSubroutines = subroutines.mutableCopy(); newSubroutines.add(subLabel); Frame newFrame = new Frame(locals.getPrimary(), stack, IntList.makeImmutable(subLabel)); return newFrame.mergeWithSubroutineCaller(this, subLabel, callerLabel); }
/** {@inheritDoc} */ @Override public void add(int value) { int index = ints.binarysearch(value); if (index < 0) { ints.insert(-(index + 1), value); } }