more changes
[IRC.git] / Robust / src / Analysis / TaskStateAnalysis / SafetyAnalysis.java
index ffb118ff8eb51bba6e2cfaa0f308d629483dc8e4..939613773cf40408298017cbfbd77720e28c5812 100644 (file)
@@ -15,10 +15,10 @@ public class SafetyAnalysis {
     private State state;
     private TaskAnalysis taskanalysis;
     private Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors;
+    private Hashtable<FlagState, Hashtable<TaskIndex, Set<OptionalTaskDescriptor>>> fstotimap;
 
     private ClassDescriptor processedclass;
    
-    
     public Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> getResult() {
        return safeexecution;
     }
@@ -39,6 +39,7 @@ public class SafetyAnalysis {
        this.state = state;
        this.taskanalysis = taskanalysis;
         this.optionaltaskdescriptors = new Hashtable();
+       this.fstotimap=new Hashtable<FlagState, Hashtable<TaskIndex, Set<OptionalTaskDescriptor>>>();
     }
     
     /* Builds map of fs -> EGTasknodes that can fire on fs for class cd */
@@ -56,6 +57,20 @@ public class SafetyAnalysis {
        return table;
     }
 
+
+    public Set<OptionalTaskDescriptor> getOptions(FlagState fs, TaskDescriptor td, int index) {
+       return fstotimap.get(fs).get(new TaskIndex(td, index));
+    }
+
+    public Set<OptionalTaskDescriptor> getOptions(FlagState fs, TaskIndex ti) {
+       return fstotimap.get(fs).get(ti);
+    }
+
+    public Set<TaskIndex> getTaskIndex(FlagState fs) {
+       return fstotimap.get(fs).keySet();
+    }
+
+
     /* Builds map of fs -> set of fs that depend on this fs */
 
     private Hashtable<FlagState, Set<FlagState>> buildUseMap(ClassDescriptor cd) {
@@ -103,6 +118,7 @@ public class SafetyAnalysis {
 
     public void analyzeFS(FlagState fs, Set<EGTaskNode> egset, Hashtable<FlagState, Set<OptionalTaskDescriptor>> fstootd, Hashtable<FlagState, Set<FlagState>> fsusemap, HashSet<FlagState> tovisit) {
        Hashtable<TaskIndex, Set<OptionalTaskDescriptor>>  timap=new Hashtable<TaskIndex, Set<OptionalTaskDescriptor>>();
+       Set<TaskIndex> tiselfloops=new HashSet<TaskIndex>();
 
        for(Iterator<EGTaskNode> egit=egset.iterator();egit.hasNext();) {
            EGTaskNode egnode=egit.next();
@@ -157,13 +173,36 @@ public class SafetyAnalysis {
                else
                    setotd=new HashSet<OptionalTaskDescriptor>();
            }
-
-           TaskIndex ti=new TaskIndex(egnode.getTD(), egnode.getIndex());
-           if (timap.containsKey(ti)) {
-               //AND case
-               timap.put(ti, createIntersection(timap.get(ti), setotd, fs.getClassDescriptor()));
-           } else {
-               timap.put(ti, setotd);
+           TaskIndex ti=egnode.isRuntime()?new TaskIndex():new TaskIndex(egnode.getTD(), egnode.getIndex());
+           if (!ti.runtime) {
+               //runtime edges don't do anything...don't have to take
+               //them, can't predict when we can.
+               if (state.selfloops.contains(egnode.getTD().getSymbol())) {
+                   System.out.println("Self loop for: "+egnode.getTD()+" "+egnode.getIndex());
+                   if (timap.containsKey(ti)) {
+                       if (egnode.getPostFS()!=fs) {
+                           if (tiselfloops.contains(ti)) {
+                               //dump old self loop
+                               timap.put(ti, setotd);
+                               tiselfloops.remove(ti);
+                           } else {
+                               //standard and case
+                               timap.put(ti, createIntersection(timap.get(ti), setotd, fs.getClassDescriptor()));
+                           }
+                       }
+                   } else {
+                       //mark as self loop
+                       timap.put(ti, setotd);
+                       if (egnode.getPostFS()==fs) {
+                           tiselfloops.add(ti);
+                       }
+                   }
+               } else if (timap.containsKey(ti)) {
+                   //AND case
+                   timap.put(ti, createIntersection(timap.get(ti), setotd, fs.getClassDescriptor()));
+               } else {
+                   timap.put(ti, setotd);
+               }
            }
        }
 
@@ -182,6 +221,7 @@ public class SafetyAnalysis {
                tovisit.addAll(fsusemap.get(fs));
            }
        }
+       fstotimap.put(fs, timap);
     }
 
     private HashSet createIntersection(Set A, Set B, ClassDescriptor cd){
@@ -496,7 +536,7 @@ public class SafetyAnalysis {
     private void createDOTFile(String classname, Collection v) throws java.io.IOException {
        java.io.PrintWriter output;
        File dotfile_flagstates= new File("markedgraph_"+classname+".dot");
-       FileOutputStream dotstream=new FileOutputStream(dotfile_flagstates,true);
+       FileOutputStream dotstream=new FileOutputStream(dotfile_flagstates,false);
        output = new java.io.PrintWriter(dotstream, true);
        output.println("digraph dotvisitor {");
        output.println("\tnode [fontsize=10,height=\"0.1\", width=\"0.1\"];");