Search in sources :

Example 1 with Constant

use of com.android.dx.rop.cst.Constant in project RocooFix by dodola.

the class ClassReferenceListBuilder method addDependencies.

private void addDependencies(ConstantPool pool) {
    for (Constant constant : pool.getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType());
        } else if (constant instanceof CstMethodRef) {
            Prototype proto = ((CstMethodRef) constant).getPrototype();
            checkDescriptor(proto.getReturnType());
            StdTypeList args = proto.getParameterTypes();
            for (int i = 0; i < args.size(); i++) {
                checkDescriptor(args.get(i));
            }
        }
    }
}
Also used : Prototype(com.android.dx.rop.type.Prototype) StdTypeList(com.android.dx.rop.type.StdTypeList) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) CstMethodRef(com.android.dx.rop.cst.CstMethodRef)

Example 2 with Constant

use of com.android.dx.rop.cst.Constant in project buck by facebook.

the class ClassDataItem method makeStaticValuesConstant.

/**
     * Gets a {@link CstArray} corresponding to {@link #staticValues} if
     * it contains any non-zero non-{@code null} values.
     *
     * @return {@code null-ok;} the corresponding constant or {@code null} if
     * there are no values to encode
     */
private CstArray makeStaticValuesConstant() {
    // First sort the statics into their final order.
    Collections.sort(staticFields);
    /*
         * Get the size of staticValues minus any trailing zeros/nulls (both
         * nulls per se as well as instances of CstKnownNull).
         */
    int size = staticFields.size();
    while (size > 0) {
        EncodedField field = staticFields.get(size - 1);
        Constant cst = staticValues.get(field);
        if (cst instanceof CstLiteralBits) {
            // Note: CstKnownNull extends CstLiteralBits.
            if (((CstLiteralBits) cst).getLongBits() != 0) {
                break;
            }
        } else if (cst != null) {
            break;
        }
        size--;
    }
    if (size == 0) {
        return null;
    }
    // There is something worth encoding, so build up a result.
    CstArray.List list = new CstArray.List(size);
    for (int i = 0; i < size; i++) {
        EncodedField field = staticFields.get(i);
        Constant cst = staticValues.get(field);
        if (cst == null) {
            cst = Zeroes.zeroFor(field.getRef().getType());
        }
        list.set(i, cst);
    }
    list.setImmutable();
    return new CstArray(list);
}
Also used : CstArray(com.android.dx.rop.cst.CstArray) CstLiteralBits(com.android.dx.rop.cst.CstLiteralBits) Constant(com.android.dx.rop.cst.Constant) ArrayList(java.util.ArrayList)

Example 3 with Constant

use of com.android.dx.rop.cst.Constant in project buck by facebook.

the class RopToDop method dopFor.

/**
     * Returns the dalvik opcode appropriate for the given register-based
     * instruction.
     *
     * @param insn {@code non-null;} the original instruction
     * @return the corresponding dalvik opcode; one of the constants in
     * {@link Dops}
     */
public static Dop dopFor(Insn insn) {
    Rop rop = insn.getOpcode();
    /*
         * First, just try looking up the rop in the MAP of easy
         * cases.
         */
    Dop result = MAP.get(rop);
    if (result != null) {
        return result;
    }
    switch(rop.getOpcode()) {
        case RegOps.MOVE_EXCEPTION:
            return Dops.MOVE_EXCEPTION;
        case RegOps.INVOKE_STATIC:
            return Dops.INVOKE_STATIC;
        case RegOps.INVOKE_VIRTUAL:
            return Dops.INVOKE_VIRTUAL;
        case RegOps.INVOKE_SUPER:
            return Dops.INVOKE_SUPER;
        case RegOps.INVOKE_DIRECT:
            return Dops.INVOKE_DIRECT;
        case RegOps.INVOKE_INTERFACE:
            return Dops.INVOKE_INTERFACE;
        case RegOps.NEW_ARRAY:
            return Dops.NEW_ARRAY;
        case RegOps.FILLED_NEW_ARRAY:
            return Dops.FILLED_NEW_ARRAY;
        case RegOps.FILL_ARRAY_DATA:
            return Dops.FILL_ARRAY_DATA;
        case RegOps.MOVE_RESULT:
            {
                RegisterSpec resultReg = insn.getResult();
                if (resultReg == null) {
                    return Dops.NOP;
                } else {
                    switch(resultReg.getBasicType()) {
                        case Type.BT_INT:
                        case Type.BT_FLOAT:
                        case Type.BT_BOOLEAN:
                        case Type.BT_BYTE:
                        case Type.BT_CHAR:
                        case Type.BT_SHORT:
                            return Dops.MOVE_RESULT;
                        case Type.BT_LONG:
                        case Type.BT_DOUBLE:
                            return Dops.MOVE_RESULT_WIDE;
                        case Type.BT_OBJECT:
                            return Dops.MOVE_RESULT_OBJECT;
                        default:
                            {
                                throw new RuntimeException("Unexpected basic type");
                            }
                    }
                }
            }
        case RegOps.GET_FIELD:
            {
                CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
                int basicType = ref.getBasicType();
                switch(basicType) {
                    case Type.BT_BOOLEAN:
                        return Dops.IGET_BOOLEAN;
                    case Type.BT_BYTE:
                        return Dops.IGET_BYTE;
                    case Type.BT_CHAR:
                        return Dops.IGET_CHAR;
                    case Type.BT_SHORT:
                        return Dops.IGET_SHORT;
                    case Type.BT_INT:
                        return Dops.IGET;
                }
                break;
            }
        case RegOps.PUT_FIELD:
            {
                CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
                int basicType = ref.getBasicType();
                switch(basicType) {
                    case Type.BT_BOOLEAN:
                        return Dops.IPUT_BOOLEAN;
                    case Type.BT_BYTE:
                        return Dops.IPUT_BYTE;
                    case Type.BT_CHAR:
                        return Dops.IPUT_CHAR;
                    case Type.BT_SHORT:
                        return Dops.IPUT_SHORT;
                    case Type.BT_INT:
                        return Dops.IPUT;
                }
                break;
            }
        case RegOps.GET_STATIC:
            {
                CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
                int basicType = ref.getBasicType();
                switch(basicType) {
                    case Type.BT_BOOLEAN:
                        return Dops.SGET_BOOLEAN;
                    case Type.BT_BYTE:
                        return Dops.SGET_BYTE;
                    case Type.BT_CHAR:
                        return Dops.SGET_CHAR;
                    case Type.BT_SHORT:
                        return Dops.SGET_SHORT;
                    case Type.BT_INT:
                        return Dops.SGET;
                }
                break;
            }
        case RegOps.PUT_STATIC:
            {
                CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
                int basicType = ref.getBasicType();
                switch(basicType) {
                    case Type.BT_BOOLEAN:
                        return Dops.SPUT_BOOLEAN;
                    case Type.BT_BYTE:
                        return Dops.SPUT_BYTE;
                    case Type.BT_CHAR:
                        return Dops.SPUT_CHAR;
                    case Type.BT_SHORT:
                        return Dops.SPUT_SHORT;
                    case Type.BT_INT:
                        return Dops.SPUT;
                }
                break;
            }
        case RegOps.CONST:
            {
                Constant cst = ((ThrowingCstInsn) insn).getConstant();
                if (cst instanceof CstType) {
                    return Dops.CONST_CLASS;
                } else if (cst instanceof CstString) {
                    return Dops.CONST_STRING;
                }
                break;
            }
    }
    throw new RuntimeException("unknown rop: " + rop);
}
Also used : Rop(com.android.dx.rop.code.Rop) ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) CstString(com.android.dx.rop.cst.CstString) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 4 with Constant

use of com.android.dx.rop.cst.Constant in project buck by facebook.

the class Form11n method isCompatible.

/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    if (!((insn instanceof CstInsn) && (regs.size() == 1) && unsignedFitsInNibble(regs.get(0).getReg()))) {
        return false;
    }
    CstInsn ci = (CstInsn) insn;
    Constant cst = ci.getConstant();
    if (!(cst instanceof CstLiteralBits)) {
        return false;
    }
    CstLiteralBits cb = (CstLiteralBits) cst;
    return cb.fitsInInt() && signedFitsInNibble(cb.getIntBits());
}
Also used : CstInsn(com.android.dx.dex.code.CstInsn) CstLiteralBits(com.android.dx.rop.cst.CstLiteralBits) Constant(com.android.dx.rop.cst.Constant) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Example 5 with Constant

use of com.android.dx.rop.cst.Constant in project buck by facebook.

the class Form35c method isCompatible.

/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }
    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();
    if (!unsignedFitsInShort(cpi)) {
        return false;
    }
    Constant cst = ci.getConstant();
    if (!((cst instanceof CstMethodRef) || (cst instanceof CstType))) {
        return false;
    }
    RegisterSpecList regs = ci.getRegisters();
    return (wordCount(regs) >= 0);
}
Also used : CstInsn(com.android.dx.dex.code.CstInsn) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstMethodRef(com.android.dx.rop.cst.CstMethodRef) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Aggregations

Constant (com.android.dx.rop.cst.Constant)46 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)17 CstType (com.android.dx.rop.cst.CstType)16 CstString (com.android.dx.rop.cst.CstString)14 CstInsn (com.android.dx.dex.code.CstInsn)12 RegisterSpec (com.android.dx.rop.code.RegisterSpec)10 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)10 TypedConstant (com.android.dx.rop.cst.TypedConstant)10 CstLiteralBits (com.android.dx.rop.cst.CstLiteralBits)9 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)7 CstInteger (com.android.dx.rop.cst.CstInteger)6 NameValuePair (com.android.dx.rop.annotation.NameValuePair)4 Insn (com.android.dx.rop.code.Insn)4 PlainInsn (com.android.dx.rop.code.PlainInsn)4 Type (com.android.dx.rop.type.Type)4 TypeBearer (com.android.dx.rop.type.TypeBearer)4 Rop (com.android.dx.rop.code.Rop)3 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)3 ArrayList (java.util.ArrayList)3 ParseException (com.android.dx.cf.iface.ParseException)2