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);
}
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);
}
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);
}
}
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);
}
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();
}
Aggregations