checkpoint
authoradam <adam@megacz.com>
Thu, 19 May 2005 03:13:34 +0000 (03:13 +0000)
committeradam <adam@megacz.com>
Thu, 19 May 2005 03:13:34 +0000 (03:13 +0000)
darcs-hash:20050519031334-5007d-108282eac1b37597133b18459a9bcfc6a58f50d3.gz

src/org/ibex/arenaj/Main.java

index c8105e1..ea31f02 100644 (file)
@@ -59,36 +59,7 @@ public class Main extends SceneTransformer {
         soot.Main.main(args2);
     }
 
         soot.Main.main(args2);
     }
 
-    static int tfr = 0;
-
-    public static Local newLocal(Body b, Type t) {
-        Local l = Jimple.v().newLocal("tmpRef" + (tfr++), t);
-        b.getLocals().add(l);
-        return l;
-    }
-
-    public static Local viaLocal(Value v, Body b) {
-        Local l = newLocal(b, v.getType());
-        if (v instanceof IdentityRef) {
-            b.getUnits().addFirst(Jimple.v().newIdentityStmt(l, v));
-        } else {
-            b.getUnits().addFirst(Jimple.v().newAssignStmt(l, v));
-        }
-        return l;
-    }
-    public static Local viaLocal(Value v, Body b, Unit u) {
-        Local l = newLocal(b, v.getType());
-        if (v instanceof IdentityRef) {
-            b.getUnits().insertBefore(Jimple.v().newIdentityStmt(l, v), u);
-        } else {
-            b.getUnits().insertBefore(Jimple.v().newAssignStmt(l, v), u);
-        }
-        return l;
-    }
-
-    HashMap map = new HashMap();
-    HashSet size_added = new HashSet();
-
+    // The main loop //////////////////////////////////////////////////////////////////////////////
 
     public void internalTransform(String phaseName, Map options) {
         System.out.println("begun");
 
     public void internalTransform(String phaseName, Map options) {
         System.out.println("begun");
@@ -107,6 +78,7 @@ public class Main extends SceneTransformer {
                 getArenaForGladiator(sc).setApplicationClass();
                 ac.add(sc);
                 ac.add(getArenaForGladiator(sc));
                 getArenaForGladiator(sc).setApplicationClass();
                 ac.add(sc);
                 ac.add(getArenaForGladiator(sc));
+                /*
                 for(Iterator i2 = sc.getMethods().iterator(); i2.hasNext();) {
                     SootMethod m = (SootMethod)i2.next();
                     if (m.isConcrete()) m.retrieveActiveBody();
                 for(Iterator i2 = sc.getMethods().iterator(); i2.hasNext();) {
                     SootMethod m = (SootMethod)i2.next();
                     if (m.isConcrete()) m.retrieveActiveBody();
@@ -115,39 +87,22 @@ public class Main extends SceneTransformer {
                     SootMethod m = (SootMethod)i2.next();
                     if (m.isConcrete()) m.retrieveActiveBody();
                 }
                     SootMethod m = (SootMethod)i2.next();
                     if (m.isConcrete()) m.retrieveActiveBody();
                 }
+                */
             }
         }
         for(Iterator it = ac.iterator(); it.hasNext();) {
             SootClass sc = (SootClass)it.next();
             }
         }
         for(Iterator it = ac.iterator(); it.hasNext();) {
             SootClass sc = (SootClass)it.next();
-            if (sc.isInterface()) continue;
-            if (!implementsGladiator(sc)) continue;
-            System.out.println("fixing Gladiator class: " + sc);
-            fixClass(sc);
+            if (sc.isInterface() || !implementsGladiator(sc)) continue;
+            processGladiatorClass(sc);
         }
         for(Iterator it = ac.iterator(); it.hasNext();) {
             SootClass sc = (SootClass)it.next();
             if (sc.isInterface()) continue;
         }
         for(Iterator it = ac.iterator(); it.hasNext();) {
             SootClass sc = (SootClass)it.next();
             if (sc.isInterface()) continue;
-            System.out.println("        updating class: " + sc);
-            nuke(sc);
+            processClass(sc);
         }
     }
 
         }
     }
 
-    boolean          implementsGladiator(SootClass c)  { return c.implementsInterface("org.ibex.arenaj.Gladiator"); }
-    boolean          implementsGladiator(Type t) {return (t instanceof RefType)&&implementsGladiator(((RefType)t).getSootClass());}
-    String           getArenaName(SootClass sc) { return sc.getName().substring(0, sc.getName().lastIndexOf('$')); }
-    String           getGladiatorName(SootClass sc) { return sc.getName().substring(sc.getName().lastIndexOf('$')+1); }
-    SootClass        getArenaForGladiator(SootClass sc) { return Scene.v().getSootClass(getArenaName(sc)); }
-    InstanceFieldRef newIFR(Body b, SootFieldRef fr) { return Jimple.v().newInstanceFieldRef(b.getThisLocal(), fr); }
-    void             assign(Body b, Value left, Value right) { b.getUnits().add(Jimple.v().newAssignStmt(left, right)); }
-    void             assign(Body b, Value l, Value r, Stmt w) { b.getUnits().insertBefore(Jimple.v().newAssignStmt(l, r), w); }
-    Type             getSliceElementType(Type t) { return implementsGladiator(t) ? IntType.v() : t; }
-    SootFieldRef     getSliceForField(SootField f)    { return getSliceForField(f.makeRef()); }
-    SootFieldRef     getSliceForField(SootFieldRef f) {
-        return Scene.v().makeFieldRef(getArenaForGladiator(f.declaringClass()),
-                                      getGladiatorName(f.declaringClass())+"$$"+f.name(),
-                                      getSliceElementType(f.type()).makeArrayType(),
-                                      false);
-    }
+    // Initializers //////////////////////////////////////////////////////////////////////////////
 
     public Type objectType;
     public List arrayCopyTypes = new LinkedList();
 
     public Type objectType;
     public List arrayCopyTypes = new LinkedList();
@@ -167,9 +122,43 @@ public class Main extends SceneTransformer {
                                     true);
     }
 
                                     true);
     }
 
-    //////////////////////////////////////////////////////////////////////////////
+    // Helpers //////////////////////////////////////////////////////////////////////////////
+
+    private int tfr = 0;
+    public Local newLocal(Body b, Type t) {
+        Local l = Jimple.v().newLocal("tmpRef" + (tfr++), t);
+        b.getLocals().add(l);
+        return l;
+    }
+
+    public Local viaLocal(Value v, Body b, Unit u) {
+        Local l = newLocal(b, v.getType());
+        if (v instanceof IdentityRef) b.getUnits().insertBefore(Jimple.v().newIdentityStmt(l, v), u);
+        else b.getUnits().insertBefore(Jimple.v().newAssignStmt(l, v), u);
+        return l;
+    }
 
 
-    public void fixClass(SootClass sc) {
+    boolean          implementsGladiator(SootClass c)  { return c.implementsInterface("org.ibex.arenaj.Gladiator"); }
+    boolean          implementsGladiator(Type t) {return (t instanceof RefType)&&implementsGladiator(((RefType)t).getSootClass());}
+    String           getArenaName(SootClass sc) { return sc.getName().substring(0, sc.getName().lastIndexOf('$')); }
+    String           getGladiatorName(SootClass sc) { return sc.getName().substring(sc.getName().lastIndexOf('$')+1); }
+    SootClass        getArenaForGladiator(SootClass sc) { return Scene.v().getSootClass(getArenaName(sc)); }
+    InstanceFieldRef newIFR(Body b, SootFieldRef fr) { return Jimple.v().newInstanceFieldRef(b.getThisLocal(), fr); }
+    void             assign(Body b, Value left, Value right) { b.getUnits().add(Jimple.v().newAssignStmt(left, right)); }
+    void             assign(Body b, Value l, Value r, Stmt w) { b.getUnits().insertBefore(Jimple.v().newAssignStmt(l, r), w); }
+    Type             getSliceElementType(Type t) { return implementsGladiator(t) ? IntType.v() : t; }
+    SootFieldRef     getSliceForField(SootField f)    { return getSliceForField(f.makeRef()); }
+    SootFieldRef     getSliceForField(SootFieldRef f) {
+        return Scene.v().makeFieldRef(getArenaForGladiator(f.declaringClass()),
+                                      getGladiatorName(f.declaringClass())+"$$"+f.name(),
+                                      getSliceElementType(f.type()).makeArrayType(),
+                                      false);
+    }
+
+
+    // Operations performed on the Gladiator class //////////////////////////////////////////////////////////////////////////
+
+    public void processGladiatorClass(SootClass sc) {
         SootClass mc = getArenaForGladiator(sc);
         String subname = sc.getShortName().substring(sc.getShortName().lastIndexOf('$')+1);
         String incFuncName = subname + "$$inc";
         SootClass mc = getArenaForGladiator(sc);
         String subname = sc.getShortName().substring(sc.getShortName().lastIndexOf('$')+1);
         String incFuncName = subname + "$$inc";
@@ -326,7 +315,9 @@ public class Main extends SceneTransformer {
         body.getUnits().add(returnStmt);
     }
 
         body.getUnits().add(returnStmt);
     }
 
-    public void nuke(SootClass c) {
+    // Operations performed on all classes ////////////////////////////////////////////////////////////////////////////
+
+    public void processClass(SootClass c) {
         for(Iterator it = c.getFields().iterator(); it.hasNext();) {
             SootField f = (SootField)it.next();
             Type t = f.getType();
         for(Iterator it = c.getFields().iterator(); it.hasNext();) {
             SootField f = (SootField)it.next();
             Type t = f.getType();
@@ -349,7 +340,7 @@ public class Main extends SceneTransformer {
             SootMethod m = (SootMethod)it.next();
             Body b = null;
             if (m.getName().endsWith("$$inc")) continue;
             SootMethod m = (SootMethod)it.next();
             Body b = null;
             if (m.getName().endsWith("$$inc")) continue;
-            if (m.hasActiveBody()) b = fixBody(m.getActiveBody(), c, m);
+            if (m.hasActiveBody()) b = processBody(m.getActiveBody(), c, m);
             List l2 = new LinkedList();
             List l = m.getParameterTypes();
             for(Iterator it2 = l.iterator(); it2.hasNext();) {
             List l2 = new LinkedList();
             List l = m.getParameterTypes();
             for(Iterator it2 = l.iterator(); it2.hasNext();) {
@@ -384,14 +375,14 @@ public class Main extends SceneTransformer {
 
     }
 
 
     }
 
-    protected Body fixBody(Body body, SootClass ownerClass, SootMethod smeth) {
+    protected Body processBody(Body body, SootClass ownerClass, SootMethod smeth) {
         if (body instanceof JimpleBody) {
             JimpleBody b2 = Jimple.v().newBody(smeth);
             b2.importBodyContentsFrom(body);
             body = b2;
         }
         Chain units = body.getUnits();
         if (body instanceof JimpleBody) {
             JimpleBody b2 = Jimple.v().newBody(smeth);
             b2.importBodyContentsFrom(body);
             body = b2;
         }
         Chain units = body.getUnits();
-        System.out.println("fixBody("+body.getMethod()+")");
+        System.out.println("processBody("+body.getMethod()+")");
         for(Iterator it = body.getLocals().snapshotIterator(); it.hasNext();) {
             Local l = (Local)it.next();
             if (implementsGladiator(l.getType())) l.setType(IntType.v());
         for(Iterator it = body.getLocals().snapshotIterator(); it.hasNext();) {
             Local l = (Local)it.next();
             if (implementsGladiator(l.getType())) l.setType(IntType.v());