Search in sources :

Example 11 with Unit

use of soot.Unit in project soot by Sable.

the class AsmMethodSource method mergeUnits.

void mergeUnits(AbstractInsnNode insn, Unit u) {
    Unit prev = units.put(insn, u);
    if (prev != null) {
        Unit merged = new UnitContainer(prev, u);
        units.put(insn, merged);
    }
}
Also used : Unit(soot.Unit)

Example 12 with Unit

use of soot.Unit in project soot by Sable.

the class AsmMethodSource method emitUnits.

private void emitUnits() {
    AbstractInsnNode insn = instructions.getFirst();
    ArrayDeque<LabelNode> labls = new ArrayDeque<LabelNode>();
    while (insn != null) {
        // Save the label to assign it to the next real unit
        if (insn instanceof LabelNode)
            labls.add((LabelNode) insn);
        // Get the unit associated with the current instruction
        Unit u = units.get(insn);
        if (u == null) {
            insn = insn.getNext();
            continue;
        }
        emitUnits(u);
        // If this is an exception handler, register the starting unit for it
        {
            IdentityStmt caughtEx = null;
            if (u instanceof IdentityStmt)
                caughtEx = (IdentityStmt) u;
            else if (u instanceof UnitContainer)
                caughtEx = getIdentityRefFromContrainer((UnitContainer) u);
            if (insn instanceof LabelNode && caughtEx != null && caughtEx.getRightOp() instanceof CaughtExceptionRef) {
                // We directly place this label
                Collection<UnitBox> traps = trapHandlers.get((LabelNode) insn);
                for (UnitBox ub : traps) ub.setUnit(caughtEx);
            }
        }
        // Register this unit for all targets of the labels ending up at it
        while (!labls.isEmpty()) {
            LabelNode ln = labls.poll();
            Collection<UnitBox> boxes = labels.get(ln);
            if (boxes != null) {
                for (UnitBox box : boxes) {
                    box.setUnit(u instanceof UnitContainer ? ((UnitContainer) u).getFirstUnit() : u);
                }
            }
        }
        insn = insn.getNext();
    }
    // Emit the inline exception handlers
    for (LabelNode ln : this.inlineExceptionHandlers.keySet()) {
        Unit handler = this.inlineExceptionHandlers.get(ln);
        emitUnits(handler);
        Collection<UnitBox> traps = trapHandlers.get(ln);
        for (UnitBox ub : traps) ub.setUnit(handler);
        // We need to jump to the original implementation
        Unit targetUnit = units.get(ln);
        GotoStmt gotoImpl = Jimple.v().newGotoStmt(targetUnit);
        body.getUnits().add(gotoImpl);
    }
    /* set remaining labels & boxes to last unit of chain */
    if (labls.isEmpty())
        return;
    Unit end = Jimple.v().newNopStmt();
    body.getUnits().add(end);
    while (!labls.isEmpty()) {
        LabelNode ln = labls.poll();
        Collection<UnitBox> boxes = labels.get(ln);
        if (boxes != null) {
            for (UnitBox box : boxes) box.setUnit(end);
        }
    }
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) UnitBox(soot.UnitBox) CaughtExceptionRef(soot.jimple.CaughtExceptionRef) GotoStmt(soot.jimple.GotoStmt) Collection(java.util.Collection) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) Unit(soot.Unit) ArrayDeque(java.util.ArrayDeque) IdentityStmt(soot.jimple.IdentityStmt)

Example 13 with Unit

use of soot.Unit in project soot by Sable.

the class AsmMethodSource method setUnit.

void setUnit(AbstractInsnNode insn, Unit u) {
    if (Options.v().keep_line_number() && lastLineNumber >= 0) {
        Tag lineTag = u.getTag("LineNumberTag");
        if (lineTag == null) {
            lineTag = new LineNumberTag(lastLineNumber);
            u.addTag(lineTag);
        } else if (((LineNumberTag) lineTag).getLineNumber() != lastLineNumber)
            throw new RuntimeException("Line tag mismatch");
    }
    Unit o = units.put(insn, u);
    if (o != null)
        throw new AssertionError(insn.getOpcode() + " already has a unit, " + o);
}
Also used : LineNumberTag(soot.tagkit.LineNumberTag) Tag(soot.tagkit.Tag) LineNumberTag(soot.tagkit.LineNumberTag) Unit(soot.Unit)

Example 14 with Unit

use of soot.Unit in project soot by Sable.

the class AsmMethodSource method emitLocals.

private void emitLocals() {
    JimpleBody jb = body;
    SootMethod m = jb.getMethod();
    Collection<Local> jbl = jb.getLocals();
    Collection<Unit> jbu = jb.getUnits();
    int iloc = 0;
    if (!m.isStatic()) {
        Local l = getLocal(iloc++);
        jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef(m.getDeclaringClass().getType())));
    }
    int nrp = 0;
    for (Object ot : m.getParameterTypes()) {
        Type t = (Type) ot;
        Local l = getLocal(iloc);
        jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newParameterRef(t, nrp++)));
        if (AsmUtil.isDWord(t))
            iloc += 2;
        else
            iloc++;
    }
    for (Local l : locals.values()) {
        jbl.add(l);
    }
}
Also used : BooleanType(soot.BooleanType) Type(soot.Type) UnknownType(soot.UnknownType) ArrayType(soot.ArrayType) RefType(soot.RefType) ShortType(soot.ShortType) ByteType(soot.ByteType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) VoidType(soot.VoidType) SootMethod(soot.SootMethod) Local(soot.Local) Unit(soot.Unit) JimpleBody(soot.jimple.JimpleBody)

Example 15 with Unit

use of soot.Unit in project soot by Sable.

the class Walker method outAIdentityNoTypeStatement.

public void outAIdentityNoTypeStatement(AIdentityNoTypeStatement node) {
    // get rid of @caughtexception string
    mProductions.removeLast();
    // presently on top of the stack
    // the local ref
    Value local = mLocals.get(mProductions.removeLast());
    // from it's
    // identifier
    Unit u = Jimple.v().newIdentityStmt(local, Jimple.v().newCaughtExceptionRef());
    mProductions.addLast(u);
}
Also used : Value(soot.Value) Unit(soot.Unit)

Aggregations

Unit (soot.Unit)240 Local (soot.Local)77 Stmt (soot.jimple.Stmt)77 Value (soot.Value)74 ArrayList (java.util.ArrayList)65 AssignStmt (soot.jimple.AssignStmt)58 SootMethod (soot.SootMethod)47 Body (soot.Body)37 InvokeStmt (soot.jimple.InvokeStmt)35 Type (soot.Type)34 HashSet (java.util.HashSet)33 ValueBox (soot.ValueBox)33 InvokeExpr (soot.jimple.InvokeExpr)33 Trap (soot.Trap)32 RefType (soot.RefType)30 IdentityStmt (soot.jimple.IdentityStmt)28 HashMap (java.util.HashMap)27 IfStmt (soot.jimple.IfStmt)27 DefinitionStmt (soot.jimple.DefinitionStmt)25 List (java.util.List)23