[Soot-list] [PATCH] added classaddpack

Phil Pratt-Szeliga pcpratts at syr.edu
Sat Jun 11 14:15:45 EDT 2011


This patch allows someone to add classes during transformation.  It does
all classes in a phase before going on to the next phase.  This is useful
if you are doing whole program analysis but you don't want the expense
that the full whole program analyzer incurs in compile time.

-Phil Pratt-Szeliga

diff -r 557b6b1f9f60 -r eaca941f4caf src/soot/PackManager.java
--- a/src/soot/PackManager.java    Sat Jun 11 13:42:33 2011 -0400
+++ b/src/soot/PackManager.java    Sat Jun 11 14:12:02 2011 -0400
@@ -180,6 +180,8 @@
             p.add(new Transform("sop.cpf", SConstantPropagatorAndFolder.v()));
         }

+        addPack(p = new BodyPack("classaddpack"));
+
         // Jimple transformation pack
         addPack(p = new BodyPack("jtp"));

@@ -377,9 +379,52 @@
     }

     public void runBodyPacks() {
+        runClassAddPack();
         runBodyPacks( reachableClasses() );
     }

+    private List iteratorToList(Iterator iter){
+        List output = new ArrayList();
+        while(iter.hasNext()){
+            output.add(iter.next());
+        }
+        return output;
+    }
+
+    private void runClassAddPack(){
+            Iterator phases = getPack("classaddpack").iterator();
+        while(phases.hasNext()){
+            Transform transform = (Transform) phases.next();
+
+            //convert the iterator to a list so that we can add application classes at will
+            List classes = iteratorToList(reachableClasses());
+            for(int i = 0; i < classes.size(); ++i){
+                SootClass c = (SootClass) classes.get(i);
+                System.out.println("Applying transform "+transform.getPhaseName()+" to class "+c.getName());
+
+                List methods = iteratorToList(c.methodIterator());
+                for(int j = 0; j < methods.size(); ++j){
+                    SootMethod m = (SootMethod) methods.get(j);
+
+                    if (!m.isConcrete()) continue;
+
+                    ShimpleBody sBody = null;
+                    Body body = m.retrieveActiveBody();
+                    if(body instanceof ShimpleBody){
+                        sBody = (ShimpleBody) body;
+                        if(!sBody.isSSA())
+                            sBody.rebuild();
+                    } else {
+                        sBody = Shimple.v().newBody(body);
+                    }
+                    m.setActiveBody(sBody);  //set it here so transforms that get the active body deep in the process can get the shimple one
+                    transform.apply(sBody);
+                    m.setActiveBody(sBody);  //set it here so the changes in the transform are saved
+                }
+          }
+        }
+      }
+
     private ZipOutputStream jarFile = null;
     public void writeOutput() {
         if( Options.v().output_jar() ) {

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20110611/648d50e7/attachment.html 


More information about the Soot-list mailing list