Search in sources :

Example 1 with CstLiteralBits

use of com.android.dx.rop.cst.CstLiteralBits 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 2 with CstLiteralBits

use of com.android.dx.rop.cst.CstLiteralBits 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 3 with CstLiteralBits

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

the class Form51l method insnArgString.

/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant();
    return regs.get(0).regString() + ", " + literalBitsString(value);
}
Also used : CstLiteralBits(com.android.dx.rop.cst.CstLiteralBits) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Example 4 with CstLiteralBits

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

the class Form21h method writeTo.

/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits cb = (CstLiteralBits) ((CstInsn) insn).getConstant();
    short bits;
    // Where the high bits are depends on the category of the target.
    if (regs.get(0).getCategory() == 1) {
        bits = (short) (cb.getIntBits() >>> 16);
    } else {
        bits = (short) (cb.getLongBits() >>> 48);
    }
    write(out, opcodeUnit(insn, regs.get(0).getReg()), bits);
}
Also used : CstLiteralBits(com.android.dx.rop.cst.CstLiteralBits) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Example 5 with CstLiteralBits

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

the class Form31i method insnArgString.

/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant();
    return regs.get(0).regString() + ", " + literalBitsString(value);
}
Also used : CstLiteralBits(com.android.dx.rop.cst.CstLiteralBits) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Aggregations

CstLiteralBits (com.android.dx.rop.cst.CstLiteralBits)48 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)42 Constant (com.android.dx.rop.cst.Constant)18 CstInsn (com.android.dx.dex.code.CstInsn)12 ArrayList (java.util.ArrayList)6 RegisterSpec (com.android.dx.rop.code.RegisterSpec)4 TypeBearer (com.android.dx.rop.type.TypeBearer)4 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 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)2 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)2 CstArray (com.android.dx.rop.cst.CstArray)2 CstInteger (com.android.dx.rop.cst.CstInteger)2 CstType (com.android.dx.rop.cst.CstType)2 TypedConstant (com.android.dx.rop.cst.TypedConstant)2 HashSet (java.util.HashSet)2