Search in sources :

Example 16 with BasicBlockList

use of com.android.dx.rop.code.BasicBlockList in project buck by facebook.

the class StdCatchBuilder method getCatchTypes.

/** {@inheritDoc} */
public HashSet<Type> getCatchTypes() {
    HashSet<Type> result = new HashSet<Type>(20);
    BasicBlockList blocks = method.getBlocks();
    int size = blocks.size();
    for (int i = 0; i < size; i++) {
        BasicBlock block = blocks.get(i);
        TypeList catches = block.getLastInsn().getCatches();
        int catchSize = catches.size();
        for (int j = 0; j < catchSize; j++) {
            result.add(catches.getType(j));
        }
    }
    return result;
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) BasicBlock(com.android.dx.rop.code.BasicBlock) BasicBlockList(com.android.dx.rop.code.BasicBlockList) TypeList(com.android.dx.rop.type.TypeList) HashSet(java.util.HashSet)

Example 17 with BasicBlockList

use of com.android.dx.rop.code.BasicBlockList in project J2ME-Loader by nikita36078.

the class BlockAddresses method setupArrays.

/**
 * Sets up the address arrays.
 */
private void setupArrays(RopMethod method) {
    BasicBlockList blocks = method.getBlocks();
    int sz = blocks.size();
    for (int i = 0; i < sz; i++) {
        BasicBlock one = blocks.get(i);
        int label = one.getLabel();
        Insn insn = one.getInsns().get(0);
        starts[label] = new CodeAddress(insn.getPosition());
        SourcePosition pos = one.getLastInsn().getPosition();
        lasts[label] = new CodeAddress(pos);
        ends[label] = new CodeAddress(pos);
    }
}
Also used : Insn(com.android.dx.rop.code.Insn) SourcePosition(com.android.dx.rop.code.SourcePosition) BasicBlock(com.android.dx.rop.code.BasicBlock) BasicBlockList(com.android.dx.rop.code.BasicBlockList)

Example 18 with BasicBlockList

use of com.android.dx.rop.code.BasicBlockList in project J2ME-Loader by nikita36078.

the class Ropper method getRopMethod.

/**
 * Extracts the resulting {@link RopMethod} from the instance.
 *
 * @return {@code non-null;} the method object
 */
private RopMethod getRopMethod() {
    // Construct the final list of blocks.
    int sz = result.size();
    BasicBlockList bbl = new BasicBlockList(sz);
    for (int i = 0; i < sz; i++) {
        bbl.set(i, result.get(i));
    }
    bbl.setImmutable();
    /*
         * Note: The parameter assignment block is always the first
         * that should be executed, hence the second argument to the
         * constructor.
         */
    return new RopMethod(bbl, getSpecialLabel(PARAM_ASSIGNMENT));
}
Also used : RopMethod(com.android.dx.rop.code.RopMethod) BasicBlockList(com.android.dx.rop.code.BasicBlockList)

Example 19 with BasicBlockList

use of com.android.dx.rop.code.BasicBlockList in project J2ME-Loader by nikita36078.

the class RopTranslator method outputInstructions.

/**
 * Performs initial creation of output instructions based on the
 * original blocks.
 */
private void outputInstructions() {
    BasicBlockList blocks = method.getBlocks();
    int[] order = this.order;
    int len = order.length;
    // Process the blocks in output order.
    for (int i = 0; i < len; i++) {
        int nextI = i + 1;
        int nextLabel = (nextI == order.length) ? -1 : order[nextI];
        outputBlock(blocks.labelToBlock(order[i]), nextLabel);
    }
}
Also used : BasicBlockList(com.android.dx.rop.code.BasicBlockList)

Example 20 with BasicBlockList

use of com.android.dx.rop.code.BasicBlockList in project J2ME-Loader by nikita36078.

the class StdCatchBuilder method build.

/**
 * Builds and returns the catch table for a given method.
 *
 * @param method {@code non-null;} method to build the list for
 * @param order {@code non-null;} block output order
 * @param addresses {@code non-null;} address objects for each block
 * @return {@code non-null;} the constructed table
 */
public static CatchTable build(RopMethod method, int[] order, BlockAddresses addresses) {
    int len = order.length;
    BasicBlockList blocks = method.getBlocks();
    ArrayList<CatchTable.Entry> resultList = new ArrayList<CatchTable.Entry>(len);
    CatchHandlerList currentHandlers = CatchHandlerList.EMPTY;
    BasicBlock currentStartBlock = null;
    BasicBlock currentEndBlock = null;
    for (int i = 0; i < len; i++) {
        BasicBlock block = blocks.labelToBlock(order[i]);
        if (!block.canThrow()) {
            /*
                 * There is no need to concern ourselves with the
                 * placement of blocks that can't throw with respect
                 * to the blocks that *can* throw.
                 */
            continue;
        }
        CatchHandlerList handlers = handlersFor(block, addresses);
        if (currentHandlers.size() == 0) {
            // This is the start of a new catch range.
            currentStartBlock = block;
            currentEndBlock = block;
            currentHandlers = handlers;
            continue;
        }
        if (currentHandlers.equals(handlers) && rangeIsValid(currentStartBlock, block, addresses)) {
            /*
                 * The block we are looking at now has the same handlers
                 * as the block that started the currently open catch
                 * range, and adding it to the currently open range won't
                 * cause it to be too long.
                 */
            currentEndBlock = block;
            continue;
        }
        /*
             * The block we are looking at now has incompatible handlers,
             * so we need to finish off the last entry and start a new
             * one. Note: We only emit an entry if it has associated handlers.
             */
        if (currentHandlers.size() != 0) {
            CatchTable.Entry entry = makeEntry(currentStartBlock, currentEndBlock, currentHandlers, addresses);
            resultList.add(entry);
        }
        currentStartBlock = block;
        currentEndBlock = block;
        currentHandlers = handlers;
    }
    if (currentHandlers.size() != 0) {
        // Emit an entry for the range that was left hanging.
        CatchTable.Entry entry = makeEntry(currentStartBlock, currentEndBlock, currentHandlers, addresses);
        resultList.add(entry);
    }
    // Construct the final result.
    int resultSz = resultList.size();
    if (resultSz == 0) {
        return CatchTable.EMPTY;
    }
    CatchTable result = new CatchTable(resultSz);
    for (int i = 0; i < resultSz; i++) {
        result.set(i, resultList.get(i));
    }
    result.setImmutable();
    return result;
}
Also used : ArrayList(java.util.ArrayList) BasicBlock(com.android.dx.rop.code.BasicBlock) BasicBlockList(com.android.dx.rop.code.BasicBlockList)

Aggregations

BasicBlockList (com.android.dx.rop.code.BasicBlockList)22 BasicBlock (com.android.dx.rop.code.BasicBlock)14 RopMethod (com.android.dx.rop.code.RopMethod)4 TypeList (com.android.dx.rop.type.TypeList)4 IntList (com.android.dx.util.IntList)4 Insn (com.android.dx.rop.code.Insn)3 InsnList (com.android.dx.rop.code.InsnList)3 DexTranslationAdvice (com.android.dx.rop.code.DexTranslationAdvice)2 SourcePosition (com.android.dx.rop.code.SourcePosition)2 TranslationAdvice (com.android.dx.rop.code.TranslationAdvice)2 CstType (com.android.dx.rop.cst.CstType)2 Type (com.android.dx.rop.type.Type)2 SsaBasicBlock (com.android.dx.ssa.SsaBasicBlock)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 BytecodeArray (com.android.dx.cf.code.BytecodeArray)1 ConcreteMethod (com.android.dx.cf.code.ConcreteMethod)1 Method (com.android.dx.cf.iface.Method)1 ByteArray (com.android.dx.util.ByteArray)1