Java Code Examples for com.android.dx.rop.type.Type#BT_INT

The following examples show how to use com.android.dx.rop.type.Type#BT_INT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code aget} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} element type of array being accessed
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opAget(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return AGET_INT;
        case Type.BT_LONG:    return AGET_LONG;
        case Type.BT_FLOAT:   return AGET_FLOAT;
        case Type.BT_DOUBLE:  return AGET_DOUBLE;
        case Type.BT_OBJECT:  return AGET_OBJECT;
        case Type.BT_BOOLEAN: return AGET_BOOLEAN;
        case Type.BT_BYTE:    return AGET_BYTE;
        case Type.BT_CHAR:    return AGET_CHAR;
        case Type.BT_SHORT:   return AGET_SHORT;
    }

    return throwBadType(type);
}
 
Example 2
Source File: Rops.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code get-static} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the field in question
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opGetStatic(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return GET_STATIC_INT;
        case Type.BT_LONG:    return GET_STATIC_LONG;
        case Type.BT_FLOAT:   return GET_STATIC_FLOAT;
        case Type.BT_DOUBLE:  return GET_STATIC_DOUBLE;
        case Type.BT_OBJECT:  return GET_STATIC_OBJECT;
        case Type.BT_BOOLEAN: return GET_STATIC_BOOLEAN;
        case Type.BT_BYTE:    return GET_STATIC_BYTE;
        case Type.BT_CHAR:    return GET_STATIC_CHAR;
        case Type.BT_SHORT:   return GET_STATIC_SHORT;
    }

    return throwBadType(type);
}
 
Example 3
Source File: Rops.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code put-field} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the field in question
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opPutField(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return PUT_FIELD_INT;
        case Type.BT_LONG:    return PUT_FIELD_LONG;
        case Type.BT_FLOAT:   return PUT_FIELD_FLOAT;
        case Type.BT_DOUBLE:  return PUT_FIELD_DOUBLE;
        case Type.BT_OBJECT:  return PUT_FIELD_OBJECT;
        case Type.BT_BOOLEAN: return PUT_FIELD_BOOLEAN;
        case Type.BT_BYTE:    return PUT_FIELD_BYTE;
        case Type.BT_CHAR:    return PUT_FIELD_CHAR;
        case Type.BT_SHORT:   return PUT_FIELD_SHORT;
    }

    return throwBadType(type);
}
 
Example 4
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code aget} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} element type of array being accessed
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opAget(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return AGET_INT;
        case Type.BT_LONG:    return AGET_LONG;
        case Type.BT_FLOAT:   return AGET_FLOAT;
        case Type.BT_DOUBLE:  return AGET_DOUBLE;
        case Type.BT_OBJECT:  return AGET_OBJECT;
        case Type.BT_BOOLEAN: return AGET_BOOLEAN;
        case Type.BT_BYTE:    return AGET_BYTE;
        case Type.BT_CHAR:    return AGET_CHAR;
        case Type.BT_SHORT:   return AGET_SHORT;
    }

    return throwBadType(type);
}
 
Example 5
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code get-static} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the field in question
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opGetStatic(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return GET_STATIC_INT;
        case Type.BT_LONG:    return GET_STATIC_LONG;
        case Type.BT_FLOAT:   return GET_STATIC_FLOAT;
        case Type.BT_DOUBLE:  return GET_STATIC_DOUBLE;
        case Type.BT_OBJECT:  return GET_STATIC_OBJECT;
        case Type.BT_BOOLEAN: return GET_STATIC_BOOLEAN;
        case Type.BT_BYTE:    return GET_STATIC_BYTE;
        case Type.BT_CHAR:    return GET_STATIC_CHAR;
        case Type.BT_SHORT:   return GET_STATIC_SHORT;
    }

    return throwBadType(type);
}
 
Example 6
Source File: Zeroes.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the "zero" (or {@code null}) value for the given type.
 *
 * @param type {@code non-null;} the type in question
 * @return {@code non-null;} its "zero" value
 */
public static Constant zeroFor(Type type) {
    switch (type.getBasicType()) {
        case Type.BT_BOOLEAN: return CstBoolean.VALUE_FALSE;
        case Type.BT_BYTE:    return CstByte.VALUE_0;
        case Type.BT_CHAR:    return CstChar.VALUE_0;
        case Type.BT_DOUBLE:  return CstDouble.VALUE_0;
        case Type.BT_FLOAT:   return CstFloat.VALUE_0;
        case Type.BT_INT:     return CstInteger.VALUE_0;
        case Type.BT_LONG:    return CstLong.VALUE_0;
        case Type.BT_SHORT:   return CstShort.VALUE_0;
        case Type.BT_OBJECT:  return CstKnownNull.THE_ONE;
        default: {
            throw new UnsupportedOperationException("no zero for type: " +
                    type.toHuman());
        }
    }
}
 
Example 7
Source File: CstType.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an instance of this class that represents the wrapper
 * class corresponding to a given primitive type. For example, if
 * given {@link Type#INT}, this method returns the class reference
 * {@code java.lang.Integer}.
 *
 * @param primitiveType {@code non-null;} the primitive type
 * @return {@code non-null;} the corresponding wrapper class
 */
public static CstType forBoxedPrimitiveType(Type primitiveType) {
    switch (primitiveType.getBasicType()) {
        case Type.BT_BOOLEAN: return BOOLEAN;
        case Type.BT_BYTE:    return BYTE;
        case Type.BT_CHAR:    return CHARACTER;
        case Type.BT_DOUBLE:  return DOUBLE;
        case Type.BT_FLOAT:   return FLOAT;
        case Type.BT_INT:     return INTEGER;
        case Type.BT_LONG:    return LONG;
        case Type.BT_SHORT:   return SHORT;
        case Type.BT_VOID:    return VOID;
    }

    throw new IllegalArgumentException("not primitive: " + primitiveType);
}
 
Example 8
Source File: Rops.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code const} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the constant
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opConst(TypeBearer type) {
    if (type.getType() == Type.KNOWN_NULL) {
        return CONST_OBJECT_NOTHROW;
    }

    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return CONST_INT;
        case Type.BT_LONG:   return CONST_LONG;
        case Type.BT_FLOAT:  return CONST_FLOAT;
        case Type.BT_DOUBLE: return CONST_DOUBLE;
        case Type.BT_OBJECT: return CONST_OBJECT;
    }

    return throwBadType(type);
}
 
Example 9
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code const} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the constant
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opConst(TypeBearer type) {
    if (type.getType() == Type.KNOWN_NULL) {
        return CONST_OBJECT_NOTHROW;
    }

    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return CONST_INT;
        case Type.BT_LONG:   return CONST_LONG;
        case Type.BT_FLOAT:  return CONST_FLOAT;
        case Type.BT_DOUBLE: return CONST_DOUBLE;
        case Type.BT_OBJECT: return CONST_OBJECT;
    }

    return throwBadType(type);
}
 
Example 10
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code put-static} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the field in question
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opPutStatic(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return PUT_STATIC_INT;
        case Type.BT_LONG:    return PUT_STATIC_LONG;
        case Type.BT_FLOAT:   return PUT_STATIC_FLOAT;
        case Type.BT_DOUBLE:  return PUT_STATIC_DOUBLE;
        case Type.BT_OBJECT:  return PUT_STATIC_OBJECT;
        case Type.BT_BOOLEAN: return PUT_STATIC_BOOLEAN;
        case Type.BT_BYTE:    return PUT_STATIC_BYTE;
        case Type.BT_CHAR:    return PUT_STATIC_CHAR;
        case Type.BT_SHORT:   return PUT_STATIC_SHORT;
    }

    return throwBadType(type);
}
 
Example 11
Source File: Rops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code not} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} type of value being operated on
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opNot(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:  return NOT_INT;
        case Type.BT_LONG: return NOT_LONG;
    }

    return throwBadType(type);
}
 
Example 12
Source File: Rops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code return} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} type of value being returned
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opReturn(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return RETURN_INT;
        case Type.BT_LONG:   return RETURN_LONG;
        case Type.BT_FLOAT:  return RETURN_FLOAT;
        case Type.BT_DOUBLE: return RETURN_DOUBLE;
        case Type.BT_OBJECT: return RETURN_OBJECT;
        case Type.BT_VOID:   return RETURN_VOID;
    }

    return throwBadType(type);
}
 
Example 13
Source File: LiteralOpUpgrader.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to replace an instruction with a const instruction. The given
 * instruction must have a constant result for it to be replaced.
 *
 * @param insn {@code non-null;} instruction to try to replace
 * @return true if the instruction was replaced
 */
private boolean tryReplacingWithConstant(NormalSsaInsn insn) {
    Insn originalRopInsn = insn.getOriginalRopInsn();
    Rop opcode = originalRopInsn.getOpcode();
    RegisterSpec result = insn.getResult();

    if (result != null && !ssaMeth.isRegALocal(result) &&
            opcode.getOpcode() != RegOps.CONST) {
        TypeBearer type = insn.getResult().getTypeBearer();
        if (type.isConstant() && type.getBasicType() == Type.BT_INT) {
            // Replace the instruction with a constant
            replacePlainInsn(insn, RegisterSpecList.EMPTY,
                    RegOps.CONST, (Constant) type);

            // Remove the source as well if this is a move-result-pseudo
            if (opcode.getOpcode() == RegOps.MOVE_RESULT_PSEUDO) {
                int pred = insn.getBlock().getPredecessors().nextSetBit(0);
                ArrayList<SsaInsn> predInsns =
                        ssaMeth.getBlocks().get(pred).getInsns();
                NormalSsaInsn sourceInsn =
                        (NormalSsaInsn) predInsns.get(predInsns.size()-1);
                replacePlainInsn(sourceInsn, RegisterSpecList.EMPTY,
                        RegOps.GOTO, null);
            }
            return true;
        }
    }
    return false;
}
 
Example 14
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code move} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} type of value being moved
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opMove(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return MOVE_INT;
        case Type.BT_LONG:   return MOVE_LONG;
        case Type.BT_FLOAT:  return MOVE_FLOAT;
        case Type.BT_DOUBLE: return MOVE_DOUBLE;
        case Type.BT_OBJECT: return MOVE_OBJECT;
        case Type.BT_ADDR:   return MOVE_RETURN_ADDRESS;
    }

    return throwBadType(type);
}
 
Example 15
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code neg} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} type of value being operated on
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opNeg(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return NEG_INT;
        case Type.BT_LONG:   return NEG_LONG;
        case Type.BT_FLOAT:  return NEG_FLOAT;
        case Type.BT_DOUBLE: return NEG_DOUBLE;
    }

    return throwBadType(type);
}
 
Example 16
Source File: Rops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for all the {@code if*}-related methods, which
 * checks types and picks one of the four variants, throwing if
 * there's a problem.
 *
 * @param types {@code non-null;} the types
 * @param intZ {@code non-null;} the int-to-0 comparison
 * @param objZ {@code null-ok;} the object-to-null comparison
 * @param intInt {@code non-null;} the int-to-int comparison
 * @param objObj {@code non-null;} the object-to-object comparison
 * @return {@code non-null;} the appropriate instance
 */
private static Rop pickIf(TypeList types, Rop intZ, Rop objZ, Rop intInt,
                          Rop objObj) {
    switch(types.size()) {
        case 1: {
            switch (types.getType(0).getBasicFrameType()) {
                case Type.BT_INT: {
                    return intZ;
                }
                case Type.BT_OBJECT: {
                    if (objZ != null) {
                        return objZ;
                    }
                }
            }
            break;
        }
        case 2: {
            int bt = types.getType(0).getBasicFrameType();
            if (bt == types.getType(1).getBasicFrameType()) {
                switch (bt) {
                    case Type.BT_INT: {
                        return intInt;
                    }
                    case Type.BT_OBJECT: {
                        if (objObj != null) {
                            return objObj;
                        }
                    }
                }
            }
            break;
        }
    }

    return throwBadTypes(types);
}
 
Example 17
Source File: Rops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code neg} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} type of value being operated on
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opNeg(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return NEG_INT;
        case Type.BT_LONG:   return NEG_LONG;
        case Type.BT_FLOAT:  return NEG_FLOAT;
        case Type.BT_DOUBLE: return NEG_DOUBLE;
    }

    return throwBadType(type);
}
 
Example 18
Source File: LiteralOpUpgrader.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to replace an instruction with a const instruction. The given
 * instruction must have a constant result for it to be replaced.
 *
 * @param insn {@code non-null;} instruction to try to replace
 * @return true if the instruction was replaced
 */
private boolean tryReplacingWithConstant(NormalSsaInsn insn) {
    Insn originalRopInsn = insn.getOriginalRopInsn();
    Rop opcode = originalRopInsn.getOpcode();
    RegisterSpec result = insn.getResult();

    if (result != null && !ssaMeth.isRegALocal(result) &&
            opcode.getOpcode() != RegOps.CONST) {
        TypeBearer type = insn.getResult().getTypeBearer();
        if (type.isConstant() && type.getBasicType() == Type.BT_INT) {
            // Replace the instruction with a constant
            replacePlainInsn(insn, RegisterSpecList.EMPTY,
                    RegOps.CONST, (Constant) type);

            // Remove the source as well if this is a move-result-pseudo
            if (opcode.getOpcode() == RegOps.MOVE_RESULT_PSEUDO) {
                int pred = insn.getBlock().getPredecessors().nextSetBit(0);
                ArrayList<SsaInsn> predInsns =
                        ssaMeth.getBlocks().get(pred).getInsns();
                NormalSsaInsn sourceInsn =
                        (NormalSsaInsn) predInsns.get(predInsns.size()-1);
                replacePlainInsn(sourceInsn, RegisterSpecList.EMPTY,
                        RegOps.GOTO, null);
            }
            return true;
        }
    }
    return false;
}
 
Example 19
Source File: Rops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code move} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} type of value being moved
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opMove(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return MOVE_INT;
        case Type.BT_LONG:   return MOVE_LONG;
        case Type.BT_FLOAT:  return MOVE_FLOAT;
        case Type.BT_DOUBLE: return MOVE_DOUBLE;
        case Type.BT_OBJECT: return MOVE_OBJECT;
        case Type.BT_ADDR:   return MOVE_RETURN_ADDRESS;
    }

    return throwBadType(type);
}
 
Example 20
Source File: Rops.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the appropriate {@code conv} rop for the given types. The
 * result is a shared instance.
 *
 * @param dest {@code non-null;} target value type
 * @param source {@code non-null;} source value type
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opConv(TypeBearer dest, TypeBearer source) {
    int dbt = dest.getBasicFrameType();
    switch (source.getBasicFrameType()) {
        case Type.BT_INT: {
            switch (dbt) {
                case Type.BT_LONG:   return CONV_I2L;
                case Type.BT_FLOAT:  return CONV_I2F;
                case Type.BT_DOUBLE: return CONV_I2D;
                default:             break;
            }
        }
        case Type.BT_LONG: {
            switch (dbt) {
                case Type.BT_INT:    return CONV_L2I;
                case Type.BT_FLOAT:  return CONV_L2F;
                case Type.BT_DOUBLE: return CONV_L2D;
                default:             break;
            }
        }
        case Type.BT_FLOAT: {
            switch (dbt) {
                case Type.BT_INT:    return CONV_F2I;
                case Type.BT_LONG:   return CONV_F2L;
                case Type.BT_DOUBLE: return CONV_F2D;
                default:             break;
            }
        }
        case Type.BT_DOUBLE: {
            switch (dbt) {
                case Type.BT_INT:    return CONV_D2I;
                case Type.BT_LONG:   return CONV_D2L;
                case Type.BT_FLOAT:  return CONV_D2F;
                default:             break;
            }
        }
    }

    return throwBadTypes(StdTypeList.make(dest.getType(),
                                          source.getType()));
}