Search in sources :

Example 1 with StdTypeList

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;
}
Also used : StdTypeList(com.taobao.android.dx.rop.type.StdTypeList)

Example 2 with StdTypeList

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);
}
Also used : CstType(com.taobao.android.dx.rop.cst.CstType) Type(com.taobao.android.dx.rop.type.Type) StdTypeList(com.taobao.android.dx.rop.type.StdTypeList)

Example 3 with StdTypeList

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);
}
Also used : StdTypeList(com.taobao.android.dx.rop.type.StdTypeList)

Example 4 with StdTypeList

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);
    }
}
Also used : Insn(com.taobao.android.dx.rop.code.Insn) PlainCstInsn(com.taobao.android.dx.rop.code.PlainCstInsn) PlainInsn(com.taobao.android.dx.rop.code.PlainInsn) ThrowingInsn(com.taobao.android.dx.rop.code.ThrowingInsn) ThrowingCstInsn(com.taobao.android.dx.rop.code.ThrowingCstInsn) Prototype(com.taobao.android.dx.rop.type.Prototype) ThrowingCstInsn(com.taobao.android.dx.rop.code.ThrowingCstInsn) BasicBlock(com.taobao.android.dx.rop.code.BasicBlock) InsnList(com.taobao.android.dx.rop.code.InsnList) ThrowingInsn(com.taobao.android.dx.rop.code.ThrowingInsn) PlainCstInsn(com.taobao.android.dx.rop.code.PlainCstInsn) PlainInsn(com.taobao.android.dx.rop.code.PlainInsn) CstType(com.taobao.android.dx.rop.cst.CstType) Type(com.taobao.android.dx.rop.type.Type) StdTypeList(com.taobao.android.dx.rop.type.StdTypeList) SourcePosition(com.taobao.android.dx.rop.code.SourcePosition) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Example 5 with StdTypeList

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());
        }
    }
}
Also used : StdTypeList(com.taobao.android.dx.rop.type.StdTypeList)

Aggregations

StdTypeList (com.taobao.android.dx.rop.type.StdTypeList)9 Type (com.taobao.android.dx.rop.type.Type)5 CstType (com.taobao.android.dx.rop.cst.CstType)4 CstString (com.taobao.android.dx.rop.cst.CstString)2 ByteArrayByteInput (com.taobao.android.dex.util.ByteArrayByteInput)1 ByteInput (com.taobao.android.dex.util.ByteInput)1 AttInnerClasses (com.taobao.android.dx.cf.attrib.AttInnerClasses)1 AttRuntimeInvisibleAnnotations (com.taobao.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations)1 AttRuntimeInvisibleParameterAnnotations (com.taobao.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations)1 AttRuntimeVisibleAnnotations (com.taobao.android.dx.cf.attrib.AttRuntimeVisibleAnnotations)1 AttRuntimeVisibleParameterAnnotations (com.taobao.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations)1 InnerClassList (com.taobao.android.dx.cf.attrib.InnerClassList)1 LocalList (com.taobao.android.dx.dex.code.LocalList)1 PositionList (com.taobao.android.dx.dex.code.PositionList)1 Annotations (com.taobao.android.dx.rop.annotation.Annotations)1 BasicBlock (com.taobao.android.dx.rop.code.BasicBlock)1 Insn (com.taobao.android.dx.rop.code.Insn)1 InsnList (com.taobao.android.dx.rop.code.InsnList)1 PlainCstInsn (com.taobao.android.dx.rop.code.PlainCstInsn)1 PlainInsn (com.taobao.android.dx.rop.code.PlainInsn)1