Search in sources :

Example 6 with ThrowingCstInsn

use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.

the class Code method cast.

/**
 * Performs either a numeric cast or a type cast.
 *
 * <h3>Numeric Casts</h3>
 * Converts a primitive to a different representation. Numeric casts may
 * be lossy. For example, converting the double {@code 1.8d} to an integer
 * yields {@code 1}, losing the fractional part. Converting the integer
 * {@code 0x12345678} to a short yields {@code 0x5678}, losing the high
 * bytes. The following numeric casts are supported:
 *
 * <p><table border="1" summary="Supported Numeric Casts">
 * <tr><th>From</th><th>To</th></tr>
 * <tr><td>int</td><td>byte, char, short, long, float, double</td></tr>
 * <tr><td>long</td><td>int, float, double</td></tr>
 * <tr><td>float</td><td>int, long, double</td></tr>
 * <tr><td>double</td><td>int, long, float</td></tr>
 * </table>
 *
 * <p>For some primitive conversions it will be necessary to chain multiple
 * cast operations. For example, to go from float to short one would first
 * cast float to int and then int to short.
 *
 * <p>Numeric casts never throw {@link ClassCastException}.
 *
 * <h3>Type Casts</h3>
 * Checks that a reference value is assignable to the target type. If it is
 * assignable it is copied to the target local. If it is not assignable a
 * {@link ClassCastException} is thrown.
 */
public void cast(Local<?> target, Local<?> source) {
    if (source.getType().ropType.isReference()) {
        addInstruction(new ThrowingCstInsn(Rops.CHECK_CAST, sourcePosition, RegisterSpecList.make(source.spec()), catches, target.type.constant));
        moveResult(target, true);
    } else {
        addInstruction(new PlainInsn(getCastRop(source.type.ropType, target.type.ropType), sourcePosition, target.spec(), source.spec()));
    }
}
Also used : PlainInsn(com.android.dx.rop.code.PlainInsn) ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn)

Example 7 with ThrowingCstInsn

use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.

the class Code method iget.

// instructions: fields
/**
 * Copies the value in instance field {@code fieldId} of {@code instance} to
 * {@code target}.
 */
public <D, V> void iget(FieldId<D, ? extends V> fieldId, Local<V> target, Local<D> instance) {
    addInstruction(new ThrowingCstInsn(Rops.opGetField(target.type.ropType), sourcePosition, RegisterSpecList.make(instance.spec()), catches, fieldId.constant));
    moveResult(target, true);
}
Also used : ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn)

Example 8 with ThrowingCstInsn

use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.

the class Code method instanceOfType.

// instructions: types
/**
 * Tests if the value in {@code source} is assignable to {@code type}. If it
 * is, {@code target} is assigned to 1; otherwise {@code target} is assigned
 * to 0.
 */
public void instanceOfType(Local<?> target, Local<?> source, TypeId<?> type) {
    addInstruction(new ThrowingCstInsn(Rops.INSTANCE_OF, sourcePosition, RegisterSpecList.make(source.spec()), catches, type.constant));
    moveResult(target, true);
}
Also used : ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn)

Example 9 with ThrowingCstInsn

use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.

the class Code method loadConstant.

// instructions: locals
/**
 * Copies the constant value {@code value} to {@code target}. The constant
 * must be a primitive, String, Class, TypeId, or null.
 */
public <T> void loadConstant(Local<T> target, T value) {
    Rop rop = value == null ? Rops.CONST_OBJECT_NOTHROW : Rops.opConst(target.type.ropType);
    if (rop.getBranchingness() == BRANCH_NONE) {
        addInstruction(new PlainCstInsn(rop, sourcePosition, target.spec(), RegisterSpecList.EMPTY, Constants.getConstant(value)));
    } else {
        addInstruction(new ThrowingCstInsn(rop, sourcePosition, RegisterSpecList.EMPTY, catches, Constants.getConstant(value)));
        moveResult(target, true);
    }
}
Also used : PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) Rop(com.android.dx.rop.code.Rop) ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn)

Example 10 with ThrowingCstInsn

use of com.android.dx.rop.code.ThrowingCstInsn in project dexmaker by linkedin.

the class Code method sget.

/**
 * Copies the value in the static field {@code fieldId} to {@code target}.
 */
public <V> void sget(FieldId<?, ? extends V> fieldId, Local<V> target) {
    addInstruction(new ThrowingCstInsn(Rops.opGetStatic(target.type.ropType), sourcePosition, RegisterSpecList.EMPTY, catches, fieldId.constant));
    moveResult(target, true);
}
Also used : ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn)

Aggregations

ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)17 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)9 PlainInsn (com.android.dx.rop.code.PlainInsn)9 Rop (com.android.dx.rop.code.Rop)9 RegisterSpec (com.android.dx.rop.code.RegisterSpec)8 Insn (com.android.dx.rop.code.Insn)6 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)6 CstType (com.android.dx.rop.cst.CstType)6 FillArrayDataInsn (com.android.dx.rop.code.FillArrayDataInsn)4 SourcePosition (com.android.dx.rop.code.SourcePosition)4 Constant (com.android.dx.rop.cst.Constant)4 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)4 Type (com.android.dx.rop.type.Type)4 BasicBlock (com.android.dx.rop.code.BasicBlock)2 InsnList (com.android.dx.rop.code.InsnList)2 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)2 SwitchInsn (com.android.dx.rop.code.SwitchInsn)2 CstInteger (com.android.dx.rop.cst.CstInteger)2 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)2 CstString (com.android.dx.rop.cst.CstString)2