Search in sources :

Example 6 with BasicBlockList

use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.

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 : CstType(com.taobao.android.dx.rop.cst.CstType) Type(com.taobao.android.dx.rop.type.Type) BasicBlock(com.taobao.android.dx.rop.code.BasicBlock) BasicBlockList(com.taobao.android.dx.rop.code.BasicBlockList) TypeList(com.taobao.android.dx.rop.type.TypeList) HashSet(java.util.HashSet)

Example 7 with BasicBlockList

use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.

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.taobao.android.dx.rop.code.Insn) SourcePosition(com.taobao.android.dx.rop.code.SourcePosition) BasicBlock(com.taobao.android.dx.rop.code.BasicBlock) BasicBlockList(com.taobao.android.dx.rop.code.BasicBlockList)

Example 8 with BasicBlockList

use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.

the class SsaToRop method convertBasicBlocks.

/**
     * @return rop-form basic block list
     */
private BasicBlockList convertBasicBlocks() {
    ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks();
    // Exit block may be null.
    SsaBasicBlock exitBlock = ssaMeth.getExitBlock();
    ssaMeth.computeReachability();
    int ropBlockCount = ssaMeth.getCountReachableBlocks();
    // Don't count the exit block, if it exists and is reachable.
    ropBlockCount -= (exitBlock != null && exitBlock.isReachable()) ? 1 : 0;
    BasicBlockList result = new BasicBlockList(ropBlockCount);
    // Convert all the reachable blocks except the exit block.
    int ropBlockIndex = 0;
    for (SsaBasicBlock b : blocks) {
        if (b.isReachable() && b != exitBlock) {
            result.set(ropBlockIndex++, convertBasicBlock(b));
        }
    }
    // The exit block, which is discarded, must do nothing.
    if (exitBlock != null && exitBlock.getInsns().size() != 0) {
        throw new RuntimeException("Exit block must have no insns when leaving SSA form");
    }
    return result;
}
Also used : SsaBasicBlock(com.taobao.android.dx.ssa.SsaBasicBlock) BasicBlockList(com.taobao.android.dx.rop.code.BasicBlockList)

Example 9 with BasicBlockList

use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.

the class SsaBasicBlock method newFromRop.

/**
     * Creates a new SSA basic block from a ROP form basic block.
     *
     * @param rmeth original method
     * @param basicBlockIndex index this block will have
     * @param parent method of this block predecessor set will be
     * updated
     * @return new instance
     */
public static SsaBasicBlock newFromRop(RopMethod rmeth, int basicBlockIndex, final SsaMethod parent) {
    BasicBlockList ropBlocks = rmeth.getBlocks();
    BasicBlock bb = ropBlocks.get(basicBlockIndex);
    SsaBasicBlock result = new SsaBasicBlock(basicBlockIndex, bb.getLabel(), parent);
    InsnList ropInsns = bb.getInsns();
    result.insns.ensureCapacity(ropInsns.size());
    for (int i = 0, sz = ropInsns.size(); i < sz; i++) {
        result.insns.add(new NormalSsaInsn(ropInsns.get(i), result));
    }
    result.predecessors = SsaMethod.bitSetFromLabelList(ropBlocks, rmeth.labelToPredecessors(bb.getLabel()));
    result.successors = SsaMethod.bitSetFromLabelList(ropBlocks, bb.getSuccessors());
    result.successorList = SsaMethod.indexListFromLabelList(ropBlocks, bb.getSuccessors());
    if (result.successorList.size() != 0) {
        int primarySuccessor = bb.getPrimarySuccessor();
        result.primarySuccessor = (primarySuccessor < 0) ? -1 : ropBlocks.indexOfLabel(primarySuccessor);
    }
    return result;
}
Also used : BasicBlock(com.taobao.android.dx.rop.code.BasicBlock) InsnList(com.taobao.android.dx.rop.code.InsnList) BasicBlockList(com.taobao.android.dx.rop.code.BasicBlockList)

Example 10 with BasicBlockList

use of com.taobao.android.dx.rop.code.BasicBlockList in project atlas by alibaba.

the class SsaMethod method convertRopToSsaBlocks.

private void convertRopToSsaBlocks(RopMethod rmeth) {
    BasicBlockList ropBlocks = rmeth.getBlocks();
    int sz = ropBlocks.size();
    blocks = new ArrayList<SsaBasicBlock>(sz + 2);
    for (int i = 0; i < sz; i++) {
        SsaBasicBlock sbb = SsaBasicBlock.newFromRop(rmeth, i, this);
        blocks.add(sbb);
    }
    // Add an no-op entry block.
    int origEntryBlockIndex = rmeth.getBlocks().indexOfLabel(rmeth.getFirstLabel());
    SsaBasicBlock entryBlock = blocks.get(origEntryBlockIndex).insertNewPredecessor();
    entryBlockIndex = entryBlock.getIndex();
    // This gets made later.
    exitBlockIndex = -1;
}
Also used : BasicBlockList(com.taobao.android.dx.rop.code.BasicBlockList)

Aggregations

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