Search in sources :

Example 6 with IntList

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);
        }
    }
}
Also used : BasicBlock(com.android.dx.rop.code.BasicBlock) IntList(com.android.dx.util.IntList)

Example 7 with IntList

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);
        }
    }
}
Also used : IntList(com.android.dx.util.IntList)

Example 8 with IntList

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);
}
Also used : IntList(com.android.dx.util.IntList)

Example 9 with IntList

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;
}
Also used : IntList(com.android.dx.util.IntList)

Example 10 with IntList

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;
}
Also used : SsaBasicBlock(com.android.dx.ssa.SsaBasicBlock) SsaBasicBlock(com.android.dx.ssa.SsaBasicBlock) BasicBlock(com.android.dx.rop.code.BasicBlock) IntList(com.android.dx.util.IntList)

Aggregations

IntList (com.android.dx.util.IntList)56 BasicBlock (com.android.dx.rop.code.BasicBlock)20 CstType (com.android.dx.rop.cst.CstType)7 Insn (com.android.dx.rop.code.Insn)5 RopMethod (com.android.dx.rop.code.RopMethod)5 BasicBlockList (com.android.dx.rop.code.BasicBlockList)4 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)4 PlainInsn (com.android.dx.rop.code.PlainInsn)4 RegisterSpec (com.android.dx.rop.code.RegisterSpec)4 SourcePosition (com.android.dx.rop.code.SourcePosition)4 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)4 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)4 Type (com.android.dx.rop.type.Type)4 TypeList (com.android.dx.rop.type.TypeList)4 DexTranslationAdvice (com.android.dx.rop.code.DexTranslationAdvice)3 InsnList (com.android.dx.rop.code.InsnList)3 TranslationAdvice (com.android.dx.rop.code.TranslationAdvice)3 SsaBasicBlock (com.android.dx.ssa.SsaBasicBlock)3 ArrayList (java.util.ArrayList)3 BitSet (java.util.BitSet)3