use of com.android.dx.util.IntList in project buck by facebook.
the class Ropper method removeBlockAndSpecialSuccessors.
/**
* Helper for {@link #addOrReplaceBlock} which recursively removes
* the given block and all blocks that are (direct and indirect)
* successors of it whose labels indicate that they are not in the
* normally-translated range.
*
* @param idx {@code non-null;} block to remove (etc.)
*/
private void removeBlockAndSpecialSuccessors(int idx) {
int minLabel = getMinimumUnreservedLabel();
BasicBlock block = result.get(idx);
IntList successors = block.getSuccessors();
int sz = successors.size();
result.remove(idx);
resultSubroutines.remove(idx);
for (int i = 0; i < sz; i++) {
int label = successors.get(i);
if (label >= minLabel) {
idx = labelToResultIndex(label);
if (idx < 0) {
throw new RuntimeException("Invalid label " + Hex.u2(label));
}
removeBlockAndSpecialSuccessors(idx);
}
}
}
use of com.android.dx.util.IntList in project buck by facebook.
the class Ropper method forEachNonSubBlockDepthFirst0.
/**
* Visits each block once in depth-first successor order, ignoring
* {@code jsr} targets. Worker for {@link #forEachNonSubBlockDepthFirst}.
*
* @param next next block to visit
* @param v callback interface
* @param visited set of blocks already visited
*/
private void forEachNonSubBlockDepthFirst0(BasicBlock next, BasicBlock.Visitor v, BitSet visited) {
v.visitBlock(next);
visited.set(next.getLabel());
IntList successors = next.getSuccessors();
int sz = successors.size();
for (int i = 0; i < sz; i++) {
int succ = successors.get(i);
if (visited.get(succ)) {
continue;
}
if (isSubroutineCaller(next) && i > 0) {
// ignore jsr targets
continue;
}
/*
* Ignore missing labels: they're successors of
* subroutines that never invoke a ret.
*/
int idx = labelToResultIndex(succ);
if (idx >= 0) {
forEachNonSubBlockDepthFirst0(result.get(idx), v, visited);
}
}
}
use of com.android.dx.util.IntList in project buck by facebook.
the class Frame method subFrameForLabel.
/**
* Returns a Frame instance representing the frame state that should
* be used when returning from a subroutine. The stack state of all
* subroutine invocations is identical, but the locals state may differ.
*
* @param startLabel {@code >=0;} The label of the returning subroutine's
* start block
* @param subLabel {@code >=0;} A calling label of a subroutine
* @return {@code null-ok;} an appropriatly-constructed instance, or null
* if label is not in the set
*/
public Frame subFrameForLabel(int startLabel, int subLabel) {
LocalsArray subLocals = null;
if (locals instanceof LocalsArraySet) {
subLocals = ((LocalsArraySet) locals).subArrayForLabel(subLabel);
}
IntList newSubroutines;
try {
newSubroutines = subroutines.mutableCopy();
if (newSubroutines.pop() != startLabel) {
throw new RuntimeException("returning from invalid subroutine");
}
newSubroutines.setImmutable();
} catch (IndexOutOfBoundsException ex) {
throw new RuntimeException("returning from invalid subroutine");
} catch (NullPointerException ex) {
throw new NullPointerException("can't return from non-subroutine");
}
return (subLocals == null) ? null : new Frame(subLocals, stack, newSubroutines);
}
use of com.android.dx.util.IntList in project buck by facebook.
the class Frame method mergeSubroutineLists.
/**
* Merges this frame's subroutine lists with another. The result
* is the deepest common nesting (effectively, the common prefix of the
* two lists).
*
* @param otherSubroutines label list of subroutine start blocks, from
* least-nested to most-nested.
* @return {@code non-null;} merged subroutine nest list as described above
*/
private IntList mergeSubroutineLists(IntList otherSubroutines) {
if (subroutines.equals(otherSubroutines)) {
return subroutines;
}
IntList resultSubroutines = new IntList();
int szSubroutines = subroutines.size();
int szOthers = otherSubroutines.size();
for (int i = 0; i < szSubroutines && i < szOthers && (subroutines.get(i) == otherSubroutines.get(i)); i++) {
resultSubroutines.add(i);
}
resultSubroutines.setImmutable();
return resultSubroutines;
}
use of com.android.dx.util.IntList in project buck by facebook.
the class SsaToRop method convertBasicBlock.
/**
* Converts a single basic block to rop form.
*
* @param block SSA block to process
* @return {@code non-null;} ROP block
*/
private BasicBlock convertBasicBlock(SsaBasicBlock block) {
IntList successorList = block.getRopLabelSuccessorList();
int primarySuccessorLabel = block.getPrimarySuccessorRopLabel();
// Filter out any reference to the SSA form's exit block.
// Exit block may be null.
SsaBasicBlock exitBlock = ssaMeth.getExitBlock();
int exitRopLabel = (exitBlock == null) ? -1 : exitBlock.getRopLabel();
if (successorList.contains(exitRopLabel)) {
if (successorList.size() > 1) {
throw new RuntimeException("Exit predecessor must have no other successors" + Hex.u2(block.getRopLabel()));
} else {
successorList = IntList.EMPTY;
primarySuccessorLabel = -1;
verifyValidExitPredecessor(block);
}
}
successorList.setImmutable();
BasicBlock result = new BasicBlock(block.getRopLabel(), convertInsns(block.getInsns()), successorList, primarySuccessorLabel);
return result;
}
Aggregations