Search in sources :

Example 21 with ExceptionalUnitGraph

use of soot.toolkits.graph.ExceptionalUnitGraph in project soot by Sable.

the class LoopFinder method internalTransform.

protected void internalTransform(Body b, String phaseName, Map options) {
    g = new ExceptionalUnitGraph(b);
    MHGDominatorsFinder a = new MHGDominatorsFinder(g);
    loops = new HashMap<Stmt, List<Stmt>>();
    Iterator<Unit> stmtsIt = b.getUnits().iterator();
    while (stmtsIt.hasNext()) {
        Stmt s = (Stmt) stmtsIt.next();
        List<Unit> succs = g.getSuccsOf(s);
        Collection<Unit> dominaters = (Collection<Unit>) a.getDominators(s);
        ArrayList<Stmt> headers = new ArrayList<Stmt>();
        Iterator<Unit> succsIt = succs.iterator();
        while (succsIt.hasNext()) {
            Stmt succ = (Stmt) succsIt.next();
            if (dominaters.contains(succ)) {
                // header succeeds and dominates s, we have a loop
                headers.add(succ);
            }
        }
        Iterator<Stmt> headersIt = headers.iterator();
        while (headersIt.hasNext()) {
            Stmt header = headersIt.next();
            List<Stmt> loopBody = getLoopBodyFor(header, s);
            // System.out.println("FOUND LOOP: Header: "+header+" Body: "+loopBody);
            if (loops.containsKey(header)) {
                // merge bodies
                List<Stmt> lb1 = loops.get(header);
                loops.put(header, union(lb1, loopBody));
            } else {
                loops.put(header, loopBody);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MHGDominatorsFinder(soot.toolkits.graph.MHGDominatorsFinder) Unit(soot.Unit) Stmt(soot.jimple.Stmt) ExceptionalUnitGraph(soot.toolkits.graph.ExceptionalUnitGraph) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 22 with ExceptionalUnitGraph

use of soot.toolkits.graph.ExceptionalUnitGraph in project soot by Sable.

the class DominatorsTagger method internalTransform.

protected void internalTransform(Body b, String phaseName, Map opts) {
    MHGDominatorsFinder analysis = new MHGDominatorsFinder(new ExceptionalUnitGraph(b));
    Iterator it = b.getUnits().iterator();
    while (it.hasNext()) {
        Stmt s = (Stmt) it.next();
        List dominators = analysis.getDominators(s);
        Iterator dIt = dominators.iterator();
        while (dIt.hasNext()) {
            Stmt ds = (Stmt) dIt.next();
            String info = ds + " dominates " + s;
            s.addTag(new LinkTag(info, ds, b.getMethod().getDeclaringClass().getName(), "Dominators"));
        }
    }
}
Also used : ExceptionalUnitGraph(soot.toolkits.graph.ExceptionalUnitGraph) LinkTag(soot.tagkit.LinkTag) Iterator(java.util.Iterator) List(java.util.List) MHGDominatorsFinder(soot.toolkits.graph.MHGDominatorsFinder) Stmt(soot.jimple.Stmt)

Aggregations

ExceptionalUnitGraph (soot.toolkits.graph.ExceptionalUnitGraph)22 Unit (soot.Unit)14 Local (soot.Local)10 List (java.util.List)8 ArrayList (java.util.ArrayList)7 Value (soot.Value)7 Stmt (soot.jimple.Stmt)6 ValueBox (soot.ValueBox)5 AssignStmt (soot.jimple.AssignStmt)5 Trap (soot.Trap)4 DefinitionStmt (soot.jimple.DefinitionStmt)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 NullConstant (soot.jimple.NullConstant)3 UnitGraph (soot.toolkits.graph.UnitGraph)3 LocalDefs (soot.toolkits.scalar.LocalDefs)3 BitSet (java.util.BitSet)2 Body (soot.Body)2 NormalUnitPrinter (soot.NormalUnitPrinter)2