Search in sources :

Example 36 with BasicBlock

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

the class IdenticalBlockCombiner method combineBlocks.

/**
 * Combines blocks proven identical into one alpha block, re-writing
 * all of the successor links that point to the beta blocks to point
 * to the alpha block instead.
 *
 * @param alphaLabel block that will replace all the beta block
 * @param betaLabels label list of blocks to combine
 */
private void combineBlocks(int alphaLabel, IntList betaLabels) {
    int szBetas = betaLabels.size();
    for (int i = 0; i < szBetas; i++) {
        int betaLabel = betaLabels.get(i);
        BasicBlock bb = blocks.labelToBlock(betaLabel);
        IntList preds = ropMethod.labelToPredecessors(bb.getLabel());
        int szPreds = preds.size();
        for (int j = 0; j < szPreds; j++) {
            BasicBlock predBlock = newBlocks.labelToBlock(preds.get(j));
            replaceSucc(predBlock, betaLabel, alphaLabel);
        }
    }
}
Also used : BasicBlock(com.android.dx.rop.code.BasicBlock) IntList(com.android.dx.util.IntList)

Example 37 with BasicBlock

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

the class IdenticalBlockCombiner method replaceSucc.

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

Example 38 with BasicBlock

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

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

BasicBlock (com.android.dx.rop.code.BasicBlock)38 IntList (com.android.dx.util.IntList)20 BasicBlockList (com.android.dx.rop.code.BasicBlockList)14 Insn (com.android.dx.rop.code.Insn)13 InsnList (com.android.dx.rop.code.InsnList)13 SourcePosition (com.android.dx.rop.code.SourcePosition)12 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)10 PlainInsn (com.android.dx.rop.code.PlainInsn)10 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)10 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)10 RegisterSpec (com.android.dx.rop.code.RegisterSpec)6 CstType (com.android.dx.rop.cst.CstType)6 TypeList (com.android.dx.rop.type.TypeList)6 RopMethod (com.android.dx.rop.code.RopMethod)4 StdTypeList (com.android.dx.rop.type.StdTypeList)4 Type (com.android.dx.rop.type.Type)4 ArrayList (java.util.ArrayList)4 DexTranslationAdvice (com.android.dx.rop.code.DexTranslationAdvice)2 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)2 Rop (com.android.dx.rop.code.Rop)2