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;
////////////////////////////////
// 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 ) {
- protected State state;
+ protected State state;
+ protected TypeUtil typeUtil;
+ protected CallGraph callGraph;
// maintain the relation at every program point
protected Hashtable<FlatNode, InArrayRelation> fn2rel;
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>();