Search in sources :

Example 16 with SourcePosition

use of com.android.dx.rop.code.SourcePosition in project J2ME-Loader by nikita36078.

the class BlockAddresses method setupArrays.

/**
 * Sets up the address arrays.
 */
private void setupArrays(RopMethod method) {
    BasicBlockList blocks = method.getBlocks();
    int sz = blocks.size();
    for (int i = 0; i < sz; i++) {
        BasicBlock one = blocks.get(i);
        int label = one.getLabel();
        Insn insn = one.getInsns().get(0);
        starts[label] = new CodeAddress(insn.getPosition());
        SourcePosition pos = one.getLastInsn().getPosition();
        lasts[label] = new CodeAddress(pos);
        ends[label] = new CodeAddress(pos);
    }
}
Also used : Insn(com.android.dx.rop.code.Insn) SourcePosition(com.android.dx.rop.code.SourcePosition) BasicBlock(com.android.dx.rop.code.BasicBlock) BasicBlockList(com.android.dx.rop.code.BasicBlockList)

Example 17 with SourcePosition

use of com.android.dx.rop.code.SourcePosition in project J2ME-Loader by nikita36078.

the class Ropper method addReturnBlock.

/**
 * Constructs and adds the return block, if necessary. The return
 * block merely contains an appropriate {@code return}
 * instruction.
 */
private void addReturnBlock() {
    Rop returnOp = machine.getReturnOp();
    if (returnOp == null) {
        /*
             * The method being converted never returns normally, so there's
             * no need for a return block.
             */
        return;
    }
    SourcePosition returnPos = machine.getReturnPosition();
    int label = getSpecialLabel(RETURN);
    if (isSynchronized()) {
        InsnList insns = new InsnList(1);
        Insn insn = new ThrowingInsn(Rops.MONITOR_EXIT, returnPos, RegisterSpecList.make(getSynchReg()), StdTypeList.EMPTY);
        insns.set(0, insn);
        insns.setImmutable();
        int nextLabel = getSpecialLabel(SYNCH_RETURN);
        BasicBlock bb = new BasicBlock(label, insns, IntList.makeImmutable(nextLabel), nextLabel);
        addBlock(bb, IntList.EMPTY);
        label = nextLabel;
    }
    InsnList insns = new InsnList(1);
    TypeList sourceTypes = returnOp.getSources();
    RegisterSpecList sources;
    if (sourceTypes.size() == 0) {
        sources = RegisterSpecList.EMPTY;
    } else {
        RegisterSpec source = RegisterSpec.make(0, sourceTypes.getType(0));
        sources = RegisterSpecList.make(source);
    }
    Insn insn = new PlainInsn(returnOp, returnPos, null, sources);
    insns.set(0, insn);
    insns.setImmutable();
    BasicBlock bb = new BasicBlock(label, insns, IntList.EMPTY, -1);
    addBlock(bb, IntList.EMPTY);
}
Also used : PlainInsn(com.android.dx.rop.code.PlainInsn) Rop(com.android.dx.rop.code.Rop) ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn) ThrowingInsn(com.android.dx.rop.code.ThrowingInsn) PlainInsn(com.android.dx.rop.code.PlainInsn) Insn(com.android.dx.rop.code.Insn) PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) SourcePosition(com.android.dx.rop.code.SourcePosition) BasicBlock(com.android.dx.rop.code.BasicBlock) InsnList(com.android.dx.rop.code.InsnList) ThrowingInsn(com.android.dx.rop.code.ThrowingInsn) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) TypeList(com.android.dx.rop.type.TypeList) StdTypeList(com.android.dx.rop.type.StdTypeList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 18 with SourcePosition

use of com.android.dx.rop.code.SourcePosition in project J2ME-Loader by nikita36078.

the class PositionList method make.

/**
 * Extracts and returns the source position information out of an
 * instruction list.
 *
 * @param insns {@code non-null;} instructions to convert
 * @param howMuch how much information should be included; one of the
 * static constants defined by this class
 * @return {@code non-null;} the positions list
 */
public static PositionList make(DalvInsnList insns, int howMuch) {
    switch(howMuch) {
        case NONE:
            {
                return EMPTY;
            }
        case LINES:
        case IMPORTANT:
            {
                // Valid.
                break;
            }
        default:
            {
                throw new IllegalArgumentException("bogus howMuch");
            }
    }
    SourcePosition noInfo = SourcePosition.NO_INFO;
    SourcePosition cur = noInfo;
    int sz = insns.size();
    PositionList.Entry[] arr = new PositionList.Entry[sz];
    boolean lastWasTarget = false;
    int at = 0;
    for (int i = 0; i < sz; i++) {
        DalvInsn insn = insns.get(i);
        if (insn instanceof CodeAddress) {
            lastWasTarget = true;
            ;
            continue;
        }
        SourcePosition pos = insn.getPosition();
        if (pos.equals(noInfo) || pos.sameLine(cur)) {
            continue;
        }
        if ((howMuch == IMPORTANT) && !lastWasTarget) {
            continue;
        }
        cur = pos;
        arr[at] = new PositionList.Entry(insn.getAddress(), pos);
        at++;
        lastWasTarget = false;
    }
    PositionList result = new PositionList(at);
    for (int i = 0; i < at; i++) {
        result.set(i, arr[i]);
    }
    result.setImmutable();
    return result;
}
Also used : SourcePosition(com.android.dx.rop.code.SourcePosition)

Aggregations

SourcePosition (com.android.dx.rop.code.SourcePosition)18 Insn (com.android.dx.rop.code.Insn)14 BasicBlock (com.android.dx.rop.code.BasicBlock)12 PlainCstInsn (com.android.dx.rop.code.PlainCstInsn)12 PlainInsn (com.android.dx.rop.code.PlainInsn)12 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)12 ThrowingInsn (com.android.dx.rop.code.ThrowingInsn)12 InsnList (com.android.dx.rop.code.InsnList)10 RegisterSpec (com.android.dx.rop.code.RegisterSpec)8 CstType (com.android.dx.rop.cst.CstType)6 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)4 Rop (com.android.dx.rop.code.Rop)4 StdTypeList (com.android.dx.rop.type.StdTypeList)4 Type (com.android.dx.rop.type.Type)4 IntList (com.android.dx.util.IntList)4 BasicBlockList (com.android.dx.rop.code.BasicBlockList)2 FillArrayDataInsn (com.android.dx.rop.code.FillArrayDataInsn)2 SwitchInsn (com.android.dx.rop.code.SwitchInsn)2 Constant (com.android.dx.rop.cst.Constant)2 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)2