Java Code Examples for com.android.dx.rop.code.BasicBlock#getSecondarySuccessor()

The following examples show how to use com.android.dx.rop.code.BasicBlock#getSecondarySuccessor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RopTranslator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Helper for {@link #outputInstructions}, which does the processing
 * and output of one block.
 *
 * @param block {@code non-null;} the block to process and output
 * @param nextLabel {@code >= -1;} the next block that will be processed, or
 * {@code -1} if there is no next block
 */
private void outputBlock(BasicBlock block, int nextLabel) {
    // Append the code address for this block.
    CodeAddress startAddress = addresses.getStart(block);
    output.add(startAddress);

    // Append the local variable state for the block.
    if (locals != null) {
        RegisterSpecSet starts = locals.getStarts(block);
        output.add(new LocalSnapshot(startAddress.getPosition(),
                                     starts));
    }

    /*
     * Choose and append an output instruction for each original
     * instruction.
     */
    translationVisitor.setBlock(block, addresses.getLast(block));
    block.getInsns().forEach(translationVisitor);

    // Insert the block end code address.
    output.add(addresses.getEnd(block));

    // Set up for end-of-block activities.

    int succ = block.getPrimarySuccessor();
    Insn lastInsn = block.getLastInsn();

    /*
     * Check for (and possibly correct for) a non-optimal choice of
     * which block will get output next.
     */

    if ((succ >= 0) && (succ != nextLabel)) {
        /*
         * The block has a "primary successor" and that primary
         * successor isn't the next block to be output.
         */
        Rop lastRop = lastInsn.getOpcode();
        if ((lastRop.getBranchingness() == Rop.BRANCH_IF) &&
                (block.getSecondarySuccessor() == nextLabel)) {
            /*
             * The block ends with an "if" of some sort, and its
             * secondary successor (the "then") is in fact the
             * next block to output. So, reverse the sense of
             * the test, so that we can just emit the next block
             * without an interstitial goto.
             */
            output.reverseBranch(1, addresses.getStart(succ));
        } else {
            /*
             * Our only recourse is to add a goto here to get the
             * flow to be correct.
             */
            TargetInsn insn =
                new TargetInsn(Dops.GOTO, lastInsn.getPosition(),
                        RegisterSpecList.EMPTY,
                        addresses.getStart(succ));
            output.add(insn);
        }
    }
}
 
Example 2
Source File: RopTranslator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Helper for {@link #outputInstructions}, which does the processing
 * and output of one block.
 *
 * @param block {@code non-null;} the block to process and output
 * @param nextLabel {@code >= -1;} the next block that will be processed, or
 * {@code -1} if there is no next block
 */
private void outputBlock(BasicBlock block, int nextLabel) {
    // Append the code address for this block.
    CodeAddress startAddress = addresses.getStart(block);
    output.add(startAddress);

    // Append the local variable state for the block.
    if (locals != null) {
        RegisterSpecSet starts = locals.getStarts(block);
        output.add(new LocalSnapshot(startAddress.getPosition(),
                                     starts));
    }

    /*
     * Choose and append an output instruction for each original
     * instruction.
     */
    translationVisitor.setBlock(block, addresses.getLast(block));
    block.getInsns().forEach(translationVisitor);

    // Insert the block end code address.
    output.add(addresses.getEnd(block));

    // Set up for end-of-block activities.

    int succ = block.getPrimarySuccessor();
    Insn lastInsn = block.getLastInsn();

    /*
     * Check for (and possibly correct for) a non-optimal choice of
     * which block will get output next.
     */

    if ((succ >= 0) && (succ != nextLabel)) {
        /*
         * The block has a "primary successor" and that primary
         * successor isn't the next block to be output.
         */
        Rop lastRop = lastInsn.getOpcode();
        if ((lastRop.getBranchingness() == Rop.BRANCH_IF) &&
                (block.getSecondarySuccessor() == nextLabel)) {
            /*
             * The block ends with an "if" of some sort, and its
             * secondary successor (the "then") is in fact the
             * next block to output. So, reverse the sense of
             * the test, so that we can just emit the next block
             * without an interstitial goto.
             */
            output.reverseBranch(1, addresses.getStart(succ));
        } else {
            /*
             * Our only recourse is to add a goto here to get the
             * flow to be correct.
             */
            TargetInsn insn =
                new TargetInsn(Dops.GOTO, lastInsn.getPosition(),
                        RegisterSpecList.EMPTY,
                        addresses.getStart(succ));
            output.add(insn);
        }
    }
}
 
Example 3
Source File: RopTranslator.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Helper for {@link #outputInstructions}, which does the processing
 * and output of one block.
 *
 * @param block {@code non-null;} the block to process and output
 * @param nextLabel {@code >= -1;} the next block that will be processed, or
 * {@code -1} if there is no next block
 */
private void outputBlock(BasicBlock block, int nextLabel) {
    // Append the code address for this block.
    CodeAddress startAddress = addresses.getStart(block);
    output.add(startAddress);

    // Append the local variable state for the block.
    if (locals != null) {
        RegisterSpecSet starts = locals.getStarts(block);
        output.add(new LocalSnapshot(startAddress.getPosition(),
                                     starts));
    }

    /*
     * Choose and append an output instruction for each original
     * instruction.
     */
    translationVisitor.setBlock(block, addresses.getLast(block));
    block.getInsns().forEach(translationVisitor);

    // Insert the block end code address.
    output.add(addresses.getEnd(block));

    // Set up for end-of-block activities.

    int succ = block.getPrimarySuccessor();
    Insn lastInsn = block.getLastInsn();

    /*
     * Check for (and possibly correct for) a non-optimal choice of
     * which block will get output next.
     */

    if ((succ >= 0) && (succ != nextLabel)) {
        /*
         * The block has a "primary successor" and that primary
         * successor isn't the next block to be output.
         */
        Rop lastRop = lastInsn.getOpcode();
        if ((lastRop.getBranchingness() == Rop.BRANCH_IF) &&
                (block.getSecondarySuccessor() == nextLabel)) {
            /*
             * The block ends with an "if" of some sort, and its
             * secondary successor (the "then") is in fact the
             * next block to output. So, reverse the sense of
             * the test, so that we can just emit the next block
             * without an interstitial goto.
             */
            output.reverseBranch(1, addresses.getStart(succ));
        } else {
            /*
             * Our only recourse is to add a goto here to get the
             * flow to be correct.
             */
            TargetInsn insn =
                new TargetInsn(Dops.GOTO, lastInsn.getPosition(),
                        RegisterSpecList.EMPTY,
                        addresses.getStart(succ));
            output.add(insn);
        }
    }
}
 
Example 4
Source File: RopTranslator.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Helper for {@link #outputInstructions}, which does the processing
 * and output of one block.
 *
 * @param block {@code non-null;} the block to process and output
 * @param nextLabel {@code >= -1;} the next block that will be processed, or
 * {@code -1} if there is no next block
 */
private void outputBlock(BasicBlock block, int nextLabel) {
    // Append the code address for this block.
    CodeAddress startAddress = addresses.getStart(block);
    output.add(startAddress);

    // Append the local variable state for the block.
    if (locals != null) {
        RegisterSpecSet starts = locals.getStarts(block);
        output.add(new LocalSnapshot(startAddress.getPosition(),
                                     starts));
    }

    /*
     * Choose and append an output instruction for each original
     * instruction.
     */
    translationVisitor.setBlock(block, addresses.getLast(block));
    block.getInsns().forEach(translationVisitor);

    // Insert the block end code address.
    output.add(addresses.getEnd(block));

    // Set up for end-of-block activities.

    int succ = block.getPrimarySuccessor();
    Insn lastInsn = block.getLastInsn();

    /*
     * Check for (and possibly correct for) a non-optimal choice of
     * which block will get output next.
     */

    if ((succ >= 0) && (succ != nextLabel)) {
        /*
         * The block has a "primary successor" and that primary
         * successor isn't the next block to be output.
         */
        Rop lastRop = lastInsn.getOpcode();
        if ((lastRop.getBranchingness() == Rop.BRANCH_IF) &&
                (block.getSecondarySuccessor() == nextLabel)) {
            /*
             * The block ends with an "if" of some sort, and its
             * secondary successor (the "then") is in fact the
             * next block to output. So, reverse the sense of
             * the test, so that we can just emit the next block
             * without an interstitial goto.
             */
            output.reverseBranch(1, addresses.getStart(succ));
        } else {
            /*
             * Our only recourse is to add a goto here to get the
             * flow to be correct.
             */
            TargetInsn insn =
                new TargetInsn(Dops.GOTO, lastInsn.getPosition(),
                        RegisterSpecList.EMPTY,
                        addresses.getStart(succ));
            output.add(insn);
        }
    }
}