checkpoint
authoradam <adam@megacz.com>
Sun, 22 May 2005 08:08:24 +0000 (08:08 +0000)
committeradam <adam@megacz.com>
Sun, 22 May 2005 08:08:24 +0000 (08:08 +0000)
darcs-hash:20050522080824-5007d-c5a6ff96ab5178ad728ad4093ab90c214945f680.gz

src/org/ibex/arenaj/Main.java

index 78e1c58..50982a6 100644 (file)
@@ -30,7 +30,6 @@ public class Main extends SceneTransformer {
             StringTokenizer st = new StringTokenizer(extDirs, File.pathSeparatorChar+"");
             while(st.hasMoreTokens()) {
                 String goo = st.nextToken();
-                System.out.println("goo " + goo);
                 File f = new File(goo);
                 if (!f.exists() || !f.isDirectory()) continue;
                 String[] jars = f.list();
@@ -161,7 +160,14 @@ public class Main extends SceneTransformer {
         // Set up the Arena zero-arg constructor 
 
         SootClass            arena = getArenaForGladiator(sc);
-        SootMethod arenaInitMethod = arena.getMethod("<init>", new LinkedList());
+        SootMethod arenaInitMethod = null;
+        for(Iterator it = arena.getMethods().iterator(); it.hasNext();) {
+            SootMethod m = (SootMethod)it.next();
+            if (m.getName().equals("<init>")) {
+                if (arenaInitMethod != null) throw new Error("class " + arena.getName() + " has two constructors");
+                arenaInitMethod = m;
+            }
+        }
         JimpleBody   arenaInitBody = (JimpleBody)arenaInitMethod.getActiveBody();
 
         SootField maxField = new SootField(getGladiatorName(sc) + "$$max", IntType.v());
@@ -230,9 +236,10 @@ public class Main extends SceneTransformer {
             boolean doremove = true;
             Body mincBody = m.getActiveBody();
             if (implementsGladiator(m.getDeclaringClass()) && m.getName().equals("<init>")) {
+                System.out.println("processing ctor " + sc.getName() + "." + m.getSignature());
                 doremove = false;
                 SootClass c = m.getDeclaringClass();
-                String name = /*c.getShortName().substring(c.getShortName().lastIndexOf('$')+1) + */"$init";
+                String name = "$init";
                 List li = m.getParameterTypes();
                 c.removeMethod(m);
                 SootMethod nm = new SootMethod(name, li, implementsGladiator(m.getReturnType()) ? IntType.v() : m.getReturnType());
@@ -241,8 +248,26 @@ public class Main extends SceneTransformer {
                 nm.setActiveBody(bod);
                 m = nm;
                 mincBody = bod;
-                mincBody.getUnits().remove(((JimpleBody)mincBody).getFirstNonIdentityStmt());
-                mincBody.getUnits().remove(((JimpleBody)mincBody).getFirstNonIdentityStmt());
+
+                for(Iterator it2 = mincBody.getUnits().snapshotIterator(); it2.hasNext(); ) {
+                    Unit u = (Unit)it2.next();
+                    if (u instanceof DefinitionStmt) {
+                        DefinitionStmt ds = (DefinitionStmt)u;
+                        if (ds.getLeftOp() instanceof ThisRef)
+                            mincBody.getUnits().remove(u);
+                        else if (ds.getLeftOp() instanceof FieldRef) {
+                            if (((FieldRef)ds.getLeftOp()).getFieldRef().name().endsWith("this$0"))
+                                mincBody.getUnits().remove(u);
+                        }
+                    } else if (u instanceof InvokeStmt) {
+                        InvokeExpr ie = ((InvokeStmt)u).getInvokeExpr();
+                        SootMethod meth = ie.getMethod();
+                        System.out.println(meth.getName());
+                        if (meth.getDeclaringClass().getName().equals("java.lang.Object") && meth.getName().equals("<init>"))
+                            mincBody.getUnits().remove(u);
+                    }
+                }
+
             } else {
                 System.out.println("examining " + sc.getName() + "." + m.getSignature());
                 m.retrieveActiveBody();
@@ -253,7 +278,6 @@ public class Main extends SceneTransformer {
             List list = new LinkedList();
             list.addAll(m.getParameterTypes());
             list.add(IntType.v());
-            for(Iterator i = list.iterator(); i.hasNext();) System.out.println(i.next());
             SootMethod m2 = new SootMethod(name, list, m.getReturnType());
             getArenaForGladiator(sc).addMethod(m2);
 
@@ -302,7 +326,6 @@ public class Main extends SceneTransformer {
                         }
                         */
                         if (vb.getValue() instanceof ThisRef) {
-                            System.out.println(s);
                             vb.setValue(loc);
                         }
                     }
@@ -383,7 +406,6 @@ public class Main extends SceneTransformer {
             body = b2;
         }
         Chain units = body.getUnits();
-        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());
@@ -532,9 +554,7 @@ public class Main extends SceneTransformer {
                         SootFieldRef fr = ifr.getFieldRef();
                         Type t = fr.type();
                         if (implementsGladiator(fr.declaringClass()) && fr.name().equals("this$0")) {
-                            System.out.println("******************");
                             vb.setValue(body.getThisLocal());
-                            System.out.println("s is " + s);
                         } else if (implementsGladiator(fr.declaringClass())) {
                             SootClass arena = getArenaForGladiator(fr.declaringClass());
                             InstanceFieldRef sfr = newIFR(body,  getSliceForField(fr));