use of com.taobao.android.dx.rop.type.StdTypeList in project atlas by alibaba.
the class ByteCatchList method toRopCatchList.
/**
* Returns a rop-style catches list equivalent to this one.
*
* @return {@code non-null;} the converted instance
*/
public TypeList toRopCatchList() {
int sz = size();
if (sz == 0) {
return StdTypeList.EMPTY;
}
StdTypeList result = new StdTypeList(sz);
for (int i = 0; i < sz; i++) {
result.set(i, get(i).getExceptionClass().getClassType());
}
result.setImmutable();
return result;
}
use of com.taobao.android.dx.rop.type.StdTypeList in project atlas by alibaba.
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 >= 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.taobao.android.dx.rop.type.StdTypeList in project atlas by alibaba.
the class ProtoIdItem method writeTo.
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
int shortyIdx = file.getStringIds().indexOf(shortForm);
int returnIdx = file.getTypeIds().indexOf(prototype.getReturnType());
int paramsOff = OffsettedItem.getAbsoluteOffsetOr0(parameterTypes);
if (out.annotates()) {
StringBuilder sb = new StringBuilder();
sb.append(prototype.getReturnType().toHuman());
sb.append(" proto(");
StdTypeList params = prototype.getParameterTypes();
int size = params.size();
for (int i = 0; i < size; i++) {
if (i != 0) {
sb.append(", ");
}
sb.append(params.getType(i).toHuman());
}
sb.append(")");
out.annotate(0, indexString() + ' ' + sb.toString());
out.annotate(4, " shorty_idx: " + Hex.u4(shortyIdx) + " // " + shortForm.toQuoted());
out.annotate(4, " return_type_idx: " + Hex.u4(returnIdx) + " // " + prototype.getReturnType().toHuman());
out.annotate(4, " parameters_off: " + Hex.u4(paramsOff));
}
out.writeInt(shortyIdx);
out.writeInt(returnIdx);
out.writeInt(paramsOff);
}
use of com.taobao.android.dx.rop.type.StdTypeList in project atlas by alibaba.
the class Ropper method addSetupBlocks.
/**
* Constructs and adds the blocks that perform setup for the rest of
* the method. This includes a first block which merely contains
* assignments from parameters to the same-numbered registers and
* a possible second block which deals with synchronization.
*/
private void addSetupBlocks() {
LocalVariableList localVariables = method.getLocalVariables();
SourcePosition pos = method.makeSourcePosistion(0);
Prototype desc = method.getEffectiveDescriptor();
StdTypeList params = desc.getParameterTypes();
int sz = params.size();
InsnList insns = new InsnList(sz + 1);
int at = 0;
for (int i = 0; i < sz; i++) {
Type one = params.get(i);
LocalVariableList.Item local = localVariables.pcAndIndexToLocal(0, at);
RegisterSpec result = (local == null) ? RegisterSpec.make(at, one) : RegisterSpec.makeLocalOptional(at, one, local.getLocalItem());
Insn insn = new PlainCstInsn(Rops.opMoveParam(one), pos, result, RegisterSpecList.EMPTY, CstInteger.make(at));
insns.set(i, insn);
at += one.getCategory();
}
insns.set(sz, new PlainInsn(Rops.GOTO, pos, null, RegisterSpecList.EMPTY));
insns.setImmutable();
boolean synch = isSynchronized();
int label = synch ? getSpecialLabel(SYNCH_SETUP_1) : 0;
BasicBlock bb = new BasicBlock(getSpecialLabel(PARAM_ASSIGNMENT), insns, IntList.makeImmutable(label), label);
addBlock(bb, IntList.EMPTY);
if (synch) {
RegisterSpec synchReg = getSynchReg();
Insn insn;
if (isStatic()) {
insn = new ThrowingCstInsn(Rops.CONST_OBJECT, pos, RegisterSpecList.EMPTY, StdTypeList.EMPTY, method.getDefiningClass());
insns = new InsnList(1);
insns.set(0, insn);
} else {
insns = new InsnList(2);
insn = new PlainCstInsn(Rops.MOVE_PARAM_OBJECT, pos, synchReg, RegisterSpecList.EMPTY, CstInteger.VALUE_0);
insns.set(0, insn);
insns.set(1, new PlainInsn(Rops.GOTO, pos, null, RegisterSpecList.EMPTY));
}
int label2 = getSpecialLabel(SYNCH_SETUP_2);
insns.setImmutable();
bb = new BasicBlock(label, insns, IntList.makeImmutable(label2), label2);
addBlock(bb, IntList.EMPTY);
insns = new InsnList(isStatic() ? 2 : 1);
if (isStatic()) {
insns.set(0, new PlainInsn(Rops.opMoveResultPseudo(synchReg), pos, synchReg, RegisterSpecList.EMPTY));
}
insn = new ThrowingInsn(Rops.MONITOR_ENTER, pos, RegisterSpecList.make(synchReg), StdTypeList.EMPTY);
insns.set(isStatic() ? 1 : 0, insn);
insns.setImmutable();
bb = new BasicBlock(label2, insns, IntList.makeImmutable(0), 0);
addBlock(bb, IntList.EMPTY);
}
}
use of com.taobao.android.dx.rop.type.StdTypeList in project atlas by alibaba.
the class BaseMachine method popArgs.
/** {@inheritDoc} */
public void popArgs(Frame frame, Prototype prototype) {
StdTypeList types = prototype.getParameterTypes();
int size = types.size();
// Use the above method to do the actual popping...
popArgs(frame, size);
for (int i = 0; i < size; i++) {
if (!Merger.isPossiblyAssignableFrom(types.getType(i), args[i])) {
throw new SimException("at stack depth " + (size - 1 - i) + ", expected type " + types.getType(i).toHuman() + " but found " + args[i].getType().toHuman());
}
}
}
Aggregations