Search in sources :

Example 6 with RegisterSpecSet

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

the class RegisterMapper method map.

/**
 * @param sources old register set
 * @return new mapped register set, or old if nothing has changed.
 */
public final RegisterSpecSet map(RegisterSpecSet sources) {
    int sz = sources.getMaxSize();
    RegisterSpecSet newSources = new RegisterSpecSet(getNewRegisterCount());
    for (int i = 0; i < sz; i++) {
        RegisterSpec registerSpec = sources.get(i);
        if (registerSpec != null) {
            newSources.put(map(registerSpec));
        }
    }
    newSources.setImmutable();
    // Return the old sources if nothing has changed.
    return newSources.equals(sources) ? sources : newSources;
}
Also used : RegisterSpecSet(com.android.dx.rop.code.RegisterSpecSet) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 7 with RegisterSpecSet

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

the class RopTranslator method outputBlock.

/**
 * 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();
    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);
        }
    }
}
Also used : ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn) ThrowingInsn(com.android.dx.rop.code.ThrowingInsn) PlainInsn(com.android.dx.rop.code.PlainInsn) InvokePolymorphicInsn(com.android.dx.rop.code.InvokePolymorphicInsn) FillArrayDataInsn(com.android.dx.rop.code.FillArrayDataInsn) Insn(com.android.dx.rop.code.Insn) SwitchInsn(com.android.dx.rop.code.SwitchInsn) PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) Rop(com.android.dx.rop.code.Rop) RegisterSpecSet(com.android.dx.rop.code.RegisterSpecSet)

Example 8 with RegisterSpecSet

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

the class LocalVariableInfo method mergeStarts.

/**
     * Merges the given register set into the set for the block with the
     * given index. If there was not already an associated set, then this
     * is the same as calling {@link #setStarts}. Otherwise, this will
     * merge the two sets and call {@link #setStarts} on the result of the
     * merge.
     *
     * @param index {@code >= 0;} the block index
     * @param specs {@code non-null;} the register set to merge into the start set
     * for the block
     * @return {@code true} if the merge resulted in an actual change
     * to the associated set (including storing one for the first time) or
     * {@code false} if there was no change
     */
public boolean mergeStarts(int index, RegisterSpecSet specs) {
    RegisterSpecSet start = getStarts0(index);
    boolean changed = false;
    if (start == null) {
        setStarts(index, specs);
        return true;
    }
    RegisterSpecSet newStart = start.mutableCopy();
    newStart.intersect(specs, true);
    if (start.equals(newStart)) {
        return false;
    }
    newStart.setImmutable();
    setStarts(index, newStart);
    return true;
}
Also used : RegisterSpecSet(com.android.dx.rop.code.RegisterSpecSet)

Example 9 with RegisterSpecSet

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

the class LocalList method make.

/**
     * Constructs an instance for the given method, based on the given
     * block order and intermediate local information.
     *
     * @param insns {@code non-null;} instructions to convert
     * @return {@code non-null;} the constructed list
     */
public static LocalList make(DalvInsnList insns) {
    int sz = insns.size();
    /*
         * Go through the insn list, looking for all the local
         * variable pseudoinstructions, splitting out LocalSnapshots
         * into separate per-variable starts, adding explicit ends
         * wherever a variable is replaced or moved, and collecting
         * these and all the other local variable "activity"
         * together into an output list (without the other insns).
         *
         * Note: As of this writing, this method won't be handed any
         * insn lists that contain local ends, but I (danfuzz) expect
         * that to change at some point, when we start feeding that
         * info explicitly into the rop layer rather than only trying
         * to infer it. So, given that expectation, this code is
         * written to deal with them.
         */
    MakeState state = new MakeState(sz);
    for (int i = 0; i < sz; i++) {
        DalvInsn insn = insns.get(i);
        if (insn instanceof LocalSnapshot) {
            RegisterSpecSet snapshot = ((LocalSnapshot) insn).getLocals();
            state.snapshot(insn.getAddress(), snapshot);
        } else if (insn instanceof LocalStart) {
            RegisterSpec local = ((LocalStart) insn).getLocal();
            state.startLocal(insn.getAddress(), local);
        }
    }
    LocalList result = state.finish();
    if (DEBUG) {
        debugVerify(result);
    }
    return result;
}
Also used : RegisterSpecSet(com.android.dx.rop.code.RegisterSpecSet) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 10 with RegisterSpecSet

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

the class OutputFinisher method addConstants.

/**
     * Helper for {@link #getAllConstants} which adds all the info for
     * a single instruction.
     *
     * @param result {@code non-null;} result set to add to
     * @param insn {@code non-null;} instruction to scrutinize
     */
private static void addConstants(HashSet<Constant> result, DalvInsn insn) {
    if (insn instanceof CstInsn) {
        Constant cst = ((CstInsn) insn).getConstant();
        result.add(cst);
    } else if (insn instanceof LocalSnapshot) {
        RegisterSpecSet specs = ((LocalSnapshot) insn).getLocals();
        int size = specs.size();
        for (int i = 0; i < size; i++) {
            addConstants(result, specs.get(i));
        }
    } else if (insn instanceof LocalStart) {
        RegisterSpec spec = ((LocalStart) insn).getLocal();
        addConstants(result, spec);
    }
}
Also used : RegisterSpecSet(com.android.dx.rop.code.RegisterSpecSet) Constant(com.android.dx.rop.cst.Constant) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Aggregations

RegisterSpecSet (com.android.dx.rop.code.RegisterSpecSet)14 RegisterSpec (com.android.dx.rop.code.RegisterSpec)10 FillArrayDataInsn (com.android.dx.rop.code.FillArrayDataInsn)2 Insn (com.android.dx.rop.code.Insn)2 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)2 PlainInsn (com.android.dx.rop.code.PlainInsn)2 Rop (com.android.dx.rop.code.Rop)2 SwitchInsn (com.android.dx.rop.code.SwitchInsn)2 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)2 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)2 Constant (com.android.dx.rop.cst.Constant)2 IntList (com.android.dx.util.IntList)2 InvokePolymorphicInsn (com.android.dx.rop.code.InvokePolymorphicInsn)1