Search in sources :

Example 36 with Type

use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.

the class Rops method opNewArray.

/**
 * Returns the appropriate {@code new-array} rop for the given
 * type. The result is a shared instance.
 *
 * @param arrayType {@code non-null;} array type of array being created
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opNewArray(TypeBearer arrayType) {
    Type type = arrayType.getType();
    Type elementType = type.getComponentType();
    switch(elementType.getBasicType()) {
        case Type.BT_INT:
            return NEW_ARRAY_INT;
        case Type.BT_LONG:
            return NEW_ARRAY_LONG;
        case Type.BT_FLOAT:
            return NEW_ARRAY_FLOAT;
        case Type.BT_DOUBLE:
            return NEW_ARRAY_DOUBLE;
        case Type.BT_BOOLEAN:
            return NEW_ARRAY_BOOLEAN;
        case Type.BT_BYTE:
            return NEW_ARRAY_BYTE;
        case Type.BT_CHAR:
            return NEW_ARRAY_CHAR;
        case Type.BT_SHORT:
            return NEW_ARRAY_SHORT;
        case Type.BT_OBJECT:
            {
                return new Rop(RegOps.NEW_ARRAY, type, StdTypeList.INT, Exceptions.LIST_Error_NegativeArraySizeException, "new-array-object");
            }
    }
    return throwBadType(type);
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType)

Example 37 with Type

use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.

the class Rops method opFilledNewArray.

/**
 * Returns the appropriate {@code filled-new-array} rop for the given
 * type. The result may be a shared instance.
 *
 * @param arrayType {@code non-null;} type of array being created
 * @param count {@code count >= 0;} number of elements that the array should have
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opFilledNewArray(TypeBearer arrayType, int count) {
    Type type = arrayType.getType();
    Type elementType = type.getComponentType();
    if (elementType.isCategory2()) {
        return throwBadType(arrayType);
    }
    if (count < 0) {
        throw new IllegalArgumentException("count < 0");
    }
    StdTypeList sourceTypes = new StdTypeList(count);
    for (int i = 0; i < count; i++) {
        sourceTypes.set(i, elementType);
    }
    // Note: The resulting rop is considered call-like.
    return new Rop(RegOps.FILLED_NEW_ARRAY, sourceTypes, Exceptions.LIST_Error);
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) StdTypeList(com.android.dx.rop.type.StdTypeList)

Example 38 with Type

use of com.android.dx.rop.type.Type in project buck by facebook.

the class EscapeAnalysis method replaceDef.

/**
     * Replaces the instructions that define an array with equivalent registers.
     * For each entry in the array, a register is created, initialized to zero.
     * A mapping between this register and the corresponding array index is
     * added.
     *
     * @param def {@code non-null;} move result instruction for array
     * @param prev {@code non-null;} instruction for instantiating new array
     * @param length size of the new array
     * @param newRegs {@code non-null;} mapping of array indices to new
     * registers to be populated
     */
private void replaceDef(SsaInsn def, SsaInsn prev, int length, ArrayList<RegisterSpec> newRegs) {
    Type resultType = def.getResult().getType();
    // Create new zeroed out registers for each element in the array
    for (int i = 0; i < length; i++) {
        Constant newZero = Zeroes.zeroFor(resultType.getComponentType());
        TypedConstant typedZero = (TypedConstant) newZero;
        RegisterSpec newReg = RegisterSpec.make(ssaMeth.makeNewSsaReg(), typedZero);
        newRegs.add(newReg);
        insertPlainInsnBefore(def, RegisterSpecList.EMPTY, newReg, RegOps.CONST, newZero);
    }
}
Also used : Type(com.android.dx.rop.type.Type) CstType(com.android.dx.rop.cst.CstType) TypedConstant(com.android.dx.rop.cst.TypedConstant) Constant(com.android.dx.rop.cst.Constant) TypedConstant(com.android.dx.rop.cst.TypedConstant) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 39 with Type

use of com.android.dx.rop.type.Type in project buck by facebook.

the class RegisterSpec method intersect.

/**
     * Returns an instance that is the intersection between this instance
     * and the given one, if any. The intersection is defined as follows:
     *
     * <ul>
     *   <li>If {@code other} is {@code null}, then the result
     *     is {@code null}.
     *   <li>If the register numbers don't match, then the intersection
     *     is {@code null}. Otherwise, the register number of the
     *     intersection is the same as the one in the two instances.</li>
     *   <li>If the types returned by {@code getType()} are not
     *     {@code equals()}, then the intersection is null.</li>
     *   <li>If the type bearers returned by {@code getTypeBearer()}
     *     are {@code equals()}, then the intersection's type bearer
     *     is the one from this instance. Otherwise, the intersection's
     *     type bearer is the {@code getType()} of this instance.</li>
     *   <li>If the locals are {@code equals()}, then the local info
     *     of the intersection is the local info of this instance. Otherwise,
     *     the local info of the intersection is {@code null}.</li>
     * </ul>
     *
     * @param other {@code null-ok;} instance to intersect with (or {@code null})
     * @param localPrimary whether local variables are primary to the
     * intersection; if {@code true}, then the only non-null
     * results occur when registers being intersected have equal local
     * infos (or both have {@code null} local infos)
     * @return {@code null-ok;} the intersection
     */
public RegisterSpec intersect(RegisterSpec other, boolean localPrimary) {
    if (this == other) {
        // Easy out.
        return this;
    }
    if ((other == null) || (reg != other.getReg())) {
        return null;
    }
    LocalItem resultLocal = ((local == null) || !local.equals(other.getLocalItem())) ? null : local;
    boolean sameName = (resultLocal == local);
    if (localPrimary && !sameName) {
        return null;
    }
    Type thisType = getType();
    Type otherType = other.getType();
    // Note: Types are always interned.
    if (thisType != otherType) {
        return null;
    }
    TypeBearer resultTypeBearer = type.equals(other.getTypeBearer()) ? type : thisType;
    if ((resultTypeBearer == type) && sameName) {
        // It turns out that the intersection is "this" after all.
        return this;
    }
    return (resultLocal == null) ? make(reg, resultTypeBearer) : make(reg, resultTypeBearer, resultLocal);
}
Also used : Type(com.android.dx.rop.type.Type) TypeBearer(com.android.dx.rop.type.TypeBearer)

Example 40 with Type

use of com.android.dx.rop.type.Type in project buck by facebook.

the class RegisterSpec method toString0.

/**
     * Helper for {@link #toString} and {@link #toHuman}.
     *
     * @param human whether to be human-oriented
     * @return {@code non-null;} the string form
     */
private String toString0(boolean human) {
    StringBuffer sb = new StringBuffer(40);
    sb.append(regString());
    sb.append(":");
    if (local != null) {
        sb.append(local.toString());
    }
    Type justType = type.getType();
    sb.append(justType);
    if (justType != type) {
        sb.append("=");
        if (human && (type instanceof CstString)) {
            sb.append(((CstString) type).toQuoted());
        } else if (human && (type instanceof Constant)) {
            sb.append(type.toHuman());
        } else {
            sb.append(type);
        }
    }
    return sb.toString();
}
Also used : Type(com.android.dx.rop.type.Type) Constant(com.android.dx.rop.cst.Constant) CstString(com.android.dx.rop.cst.CstString)

Aggregations

Type (com.android.dx.rop.type.Type)62 CstType (com.android.dx.rop.cst.CstType)36 StdTypeList (com.android.dx.rop.type.StdTypeList)10 TypeBearer (com.android.dx.rop.type.TypeBearer)10 Constant (com.android.dx.rop.cst.Constant)8 CstString (com.android.dx.rop.cst.CstString)8 RegisterSpec (com.android.dx.rop.code.RegisterSpec)6 TypeList (com.android.dx.rop.type.TypeList)6 BasicBlock (com.android.dx.rop.code.BasicBlock)4 Insn (com.android.dx.rop.code.Insn)4 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)4 PlainInsn (com.android.dx.rop.code.PlainInsn)4 SourcePosition (com.android.dx.rop.code.SourcePosition)4 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)4 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)4 CstInteger (com.android.dx.rop.cst.CstInteger)4 IntList (com.android.dx.util.IntList)4 ByteArrayByteInput (com.android.dex.util.ByteArrayByteInput)2 ByteInput (com.android.dex.util.ByteInput)2 AttInnerClasses (com.android.dx.cf.attrib.AttInnerClasses)2