changes.
[IRC.git] / Robust / src / Analysis / ArrayReferencees.java
index 0aa28df6e35d8a110424395d0a112a0b2c5ac301..1c9cba2be363265f9f4f174630842d34a0aa4fdf 100644 (file)
 
 package Analysis;
 
-import IR.State;
-import IR.Descriptor;
-import IR.ClassDescriptor;
-import IR.MethodDescriptor;
-import IR.TaskDescriptor;
-import IR.TypeDescriptor;
+import IR.*;
+import Analysis.CallGraph.*;
 import IR.Flat.TempDescriptor;
 import IR.Flat.FlatMethod;
 import IR.Flat.FlatNode;
@@ -35,8 +31,8 @@ public class ArrayReferencees {
   ////////////////////////////////
   // public interface
   ////////////////////////////////
-  public ArrayReferencees( State state ) {
-    init( state );
+  public ArrayReferencees( State state, TypeUtil typeUtil, CallGraph callGraph ) {
+    init( state, typeUtil, callGraph );
   }
 
   public boolean doesNotCreateNewReaching( FlatSetElementNode fsen ) {
@@ -48,7 +44,9 @@ public class ArrayReferencees {
 
 
 
-  protected State state;
+  protected State     state;
+  protected TypeUtil  typeUtil;
+  protected CallGraph callGraph;
 
   // maintain the relation at every program point
   protected Hashtable<FlatNode, InArrayRelation> fn2rel;
@@ -60,29 +58,47 @@ public class ArrayReferencees {
 
   protected ArrayReferencees() {}
 
-  protected void init( State state ) {
-    this.state = state;
+  protected void init( State     state, 
+                       TypeUtil  typeUtil, 
+                       CallGraph callGraph ) {
+    this.state     = state;
+    this.typeUtil  = typeUtil;
+    this.callGraph = callGraph;
     fn2rel = new Hashtable<FlatNode, InArrayRelation>();
     noNewReaching = new HashSet<FlatSetElementNode>();
     buildRelation();
   }
 
   protected void buildRelation() {
-    // just analyze every method of every class that the
-    // compiler has code for, fix if this is too costly
-    Iterator classItr = state.getClassSymbolTable().getDescriptorsIterator();
-    while( classItr.hasNext() ) {
-      ClassDescriptor cd = (ClassDescriptor)classItr.next();
-
-      Iterator methodItr = cd.getMethods();
-      while( methodItr.hasNext() ) {
-       MethodDescriptor md = (MethodDescriptor)methodItr.next();
-
-       FlatMethod fm = state.getMethodFlat( md );
-       analyzeMethod( fm );
+    Set<MethodDescriptor> descriptorsToAnalyze = null;
+
+    if(state.TASK) {
+      // for Bristlecone and Bamboo, there are no main method,
+      // analyze all methods transitively reachable from tasks instead
+      Iterator it_sourceEntries = state.getTaskSymbolTable().getDescriptorsIterator();
+      while(it_sourceEntries.hasNext()) {
+        TaskDescriptor tdSourceEntry = (TaskDescriptor)it_sourceEntries.next();
+        if(descriptorsToAnalyze == null) {
+          descriptorsToAnalyze = callGraph.getAllMethods(tdSourceEntry);
+        } else {
+          descriptorsToAnalyze.addAll(callGraph.getAllMethods(tdSourceEntry));
+        }
+        //descriptorsToAnalyze.add( tdSourceEntry );
       }
+    } else {
+    // analyze all methods transitively reachable from main
+    MethodDescriptor mdSourceEntry = typeUtil.getMain();
+    FlatMethod       fmMain        = state.getMethodFlat( mdSourceEntry );
+    
+    descriptorsToAnalyze = callGraph.getAllMethods( mdSourceEntry );
+    descriptorsToAnalyze.add( mdSourceEntry );
     }
-  }  
+    
+    for( MethodDescriptor md: descriptorsToAnalyze ) {
+      FlatMethod fm =  state.getMethodFlat( md );
+      analyzeMethod( fm );
+    }
+  }
 
   protected void analyzeMethod( FlatMethod fm ) {
     Set<FlatNode> toVisit = new HashSet<FlatNode>();