Search in sources :

Example 1 with MHGDominatorsFinder

use of soot.toolkits.graph.MHGDominatorsFinder 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 2 with MHGDominatorsFinder

use of soot.toolkits.graph.MHGDominatorsFinder 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

List (java.util.List)2 Stmt (soot.jimple.Stmt)2 ExceptionalUnitGraph (soot.toolkits.graph.ExceptionalUnitGraph)2 MHGDominatorsFinder (soot.toolkits.graph.MHGDominatorsFinder)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Unit (soot.Unit)1 LinkTag (soot.tagkit.LinkTag)1