Search in sources :

Example 91 with RegisterSpec

use of com.android.dx.rop.code.RegisterSpec 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 92 with RegisterSpec

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

the class LocalSnapshot method listingString0.

/** {@inheritDoc} */
@Override
protected String listingString0(boolean noteIndices) {
    int sz = locals.size();
    int max = locals.getMaxSize();
    StringBuffer sb = new StringBuffer(100 + sz * 40);
    sb.append("local-snapshot");
    for (int i = 0; i < max; i++) {
        RegisterSpec spec = locals.get(i);
        if (spec != null) {
            sb.append("\n  ");
            sb.append(LocalStart.localString(spec));
        }
    }
    return sb.toString();
}
Also used : RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 93 with RegisterSpec

use of com.android.dx.rop.code.RegisterSpec 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)

Example 94 with RegisterSpec

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

the class RopperMachine method getSources.

/**
     * Helper for {@link #run}, which gets the list of sources for the.
     * instruction.
     *
     * @param opcode the opcode being translated
     * @param stackPointer {@code >= 0;} the stack pointer after the
     * instruction's arguments have been popped
     * @return {@code non-null;} the sources
     */
private RegisterSpecList getSources(int opcode, int stackPointer) {
    int count = argCount();
    if (count == 0) {
        // We get an easy out if there aren't any sources.
        return RegisterSpecList.EMPTY;
    }
    int localIndex = getLocalIndex();
    RegisterSpecList sources;
    if (localIndex >= 0) {
        // The instruction is operating on a local variable.
        sources = new RegisterSpecList(1);
        sources.set(0, RegisterSpec.make(localIndex, arg(0)));
    } else {
        sources = new RegisterSpecList(count);
        int regAt = stackPointer;
        for (int i = 0; i < count; i++) {
            RegisterSpec spec = RegisterSpec.make(regAt, arg(i));
            sources.set(i, spec);
            regAt += spec.getCategory();
        }
        switch(opcode) {
            case ByteOps.IASTORE:
                {
                    /*
                     * The Java argument order for array stores is
                     * (array, index, value), but the rop argument
                     * order is (value, array, index). The following
                     * code gets the right arguments in the right
                     * places.
                     */
                    if (count != 3) {
                        throw new RuntimeException("shouldn't happen");
                    }
                    RegisterSpec array = sources.get(0);
                    RegisterSpec index = sources.get(1);
                    RegisterSpec value = sources.get(2);
                    sources.set(0, value);
                    sources.set(1, array);
                    sources.set(2, index);
                    break;
                }
            case ByteOps.PUTFIELD:
                {
                    /*
                     * Similar to above: The Java argument order for
                     * putfield is (object, value), but the rop
                     * argument order is (value, object).
                     */
                    if (count != 2) {
                        throw new RuntimeException("shouldn't happen");
                    }
                    RegisterSpec obj = sources.get(0);
                    RegisterSpec value = sources.get(1);
                    sources.set(0, value);
                    sources.set(1, obj);
                    break;
                }
        }
    }
    sources.setImmutable();
    return sources;
}
Also used : RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 95 with RegisterSpec

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

the class Form35c method compatibleRegs.

/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();
    BitSet bits = new BitSet(sz);
    for (int i = 0; i < sz; i++) {
        RegisterSpec reg = regs.get(i);
        /*
             * The check below adds (category - 1) to the register, to
             * account for the fact that the second half of a
             * category-2 register has to be represented explicitly in
             * the result.
             */
        bits.set(i, unsignedFitsInNibble(reg.getReg() + reg.getCategory() - 1));
    }
    return bits;
}
Also used : BitSet(java.util.BitSet) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Aggregations

RegisterSpec (com.android.dx.rop.code.RegisterSpec)135 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)50 PlainInsn (com.android.dx.rop.code.PlainInsn)24 Constant (com.android.dx.rop.cst.Constant)20 TypedConstant (com.android.dx.rop.cst.TypedConstant)16 TypeBearer (com.android.dx.rop.type.TypeBearer)16 ArrayList (java.util.ArrayList)16 Insn (com.android.dx.rop.code.Insn)14 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)14 Rop (com.android.dx.rop.code.Rop)14 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)14 CstType (com.android.dx.rop.cst.CstType)14 BitSet (java.util.BitSet)11 LocalItem (com.android.dx.rop.code.LocalItem)10 RegisterSpecSet (com.android.dx.rop.code.RegisterSpecSet)10 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)10 CstString (com.android.dx.rop.cst.CstString)10 HashSet (java.util.HashSet)10 SourcePosition (com.android.dx.rop.code.SourcePosition)8 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)8