Added Classes TaskNode and TEdge for task graphs.
authorsivaji <sivaji>
Sat, 19 May 2007 19:19:45 +0000 (19:19 +0000)
committersivaji <sivaji>
Sat, 19 May 2007 19:19:45 +0000 (19:19 +0000)
Updated TaskAnalysis.java with methods for producing taskgraphs.
The createDOTFile method has been augmented to produce both dot files:
one for the flagstates and another for the tasks.

Robust/src/Analysis/TaskStateAnalysis/TEdge.java [new file with mode: 0644]
Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java
Robust/src/Analysis/TaskStateAnalysis/TaskNode.java [new file with mode: 0644]

diff --git a/Robust/src/Analysis/TaskStateAnalysis/TEdge.java b/Robust/src/Analysis/TaskStateAnalysis/TEdge.java
new file mode 100644 (file)
index 0000000..869272c
--- /dev/null
@@ -0,0 +1,34 @@
+package Analysis.TaskStateAnalysis;
+import IR.*;
+import Analysis.TaskStateAnalysis.*;
+import IR.Tree.*;
+import IR.Flat.*;
+import java.util.*;
+import Util.Edge;
+
+
+public class TEdge extends Edge{
+       
+       private String target;
+       
+       public TEdge(TaskNode target){
+               super(target);
+       }
+       
+          
+        
+    public int hashCode(){
+       return target.hashCode()^target.toString().hashCode();
+    }
+    
+       
+    public boolean equals(Object o) {
+        if (o instanceof TEdge) {
+            TEdge e=(TEdge)o;
+           return e.target.equals(target);
+        }
+        return false;
+    }
+
+    
+}
index cedc52aa9c421a23c91da1dab97eadc5bce47b0f..6c3f8d0bce1d3c0c2d7059f91b03049850748c2d 100644 (file)
@@ -15,6 +15,7 @@ public class TaskAnalysis {
     Hashtable flags;
     Hashtable extern_flags;
     Queue<FlagState> toprocess;
+    
     TypeUtil typeutil;
     
     /** 
@@ -251,6 +252,7 @@ public class TaskAnalysis {
                        //seen this node already
                        fs_taskexit=canonicalizeFlagState(sourcenodes,fs_taskexit);
                        FEdge newedge=new FEdge(fs_taskexit,taskname);
+                       //FEdge newedge=new FEdge(fs_taskexit,td);
                        fs.addEdge(newedge);
                }
                }
@@ -411,9 +413,13 @@ private boolean isTaskTrigger_tag(TagExpressionList tel, FlagState fs){
     */
     
     public void createDOTfile(ClassDescriptor cd) throws java.io.IOException {
-               File dotfile= new File("graph"+cd.getSymbol()+".dot");
-               FileOutputStream dotstream=new FileOutputStream(dotfile,true);
+               File dotfile_flagstates= new File("graph"+cd.getSymbol()+".dot");
+               FileOutputStream dotstream=new FileOutputStream(dotfile_flagstates,true);
                FlagState.DOTVisitor.visit(dotstream,((Hashtable)flagstates.get(cd)).values());
+               
+               File dotfile_tasknodes=new File("graph"+cd.getSymbol()+"_task.dot");
+               dotstream=new FileOutputStream(dotfile_tasknodes,true);
+               TaskNode.DOTVisitor.visit(dotstream,(produceTaskNodes((Hashtable)flagstates.get(cd))).values());
     }
        
 
@@ -452,5 +458,43 @@ private boolean isTaskTrigger_tag(TagExpressionList tel, FlagState fs){
        fs.addEdge(new FEdge(fstemp,"Runtime"));
     }
        }
+       
+       private TaskNode canonicalizeTaskNode(Hashtable nodes, TaskNode node){
+       if (nodes.containsKey(node))
+           return (TaskNode)nodes.get(node);
+       else{
+           nodes.put(node,node);
+           return (TaskNode)node;
+       }
+    }
+       
+       public Hashtable produceTaskNodes(Hashtable<FlagState,FlagState> fsnodes){
+               
+               Hashtable<TaskNode,TaskNode> tasknodes=new Hashtable<TaskNode,TaskNode>();
+               for(Enumeration en=fsnodes.keys();en.hasMoreElements();){
+                       FlagState fs=(FlagState)en.nextElement();
+                       
+                       Iterator it_inedges=fs.inedges();       
+                       TaskNode tn;
+                       do{
+                               if (!fs.inedges().hasNext()){
+                                       tn=new TaskNode("Start Node");
+                               }else{
+                                       FEdge inedge=(FEdge)it_inedges.next();
+                                       tn=new TaskNode(inedge.getLabel());
+                               }
+                               if(fs.edges().hasNext()){
+                                       tn=(TaskNode)canonicalizeTaskNode(tasknodes, tn);
+                                       for (Iterator it_edges=fs.edges();it_edges.hasNext();){
+                                               TaskNode target=new TaskNode(((FEdge)it_edges.next()).getLabel());
+                                               target=(TaskNode)canonicalizeTaskNode(tasknodes,target);
+                                               tn.addEdge(new TEdge(target));
+                                       }
+                               }
+                       }while(it_inedges.hasNext());
+               }
+               return tasknodes;
+       }
+       
 } 
 
diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskNode.java b/Robust/src/Analysis/TaskStateAnalysis/TaskNode.java
new file mode 100644 (file)
index 0000000..babae4b
--- /dev/null
@@ -0,0 +1,63 @@
+package Analysis.TaskStateAnalysis;
+import Analysis.TaskStateAnalysis.*;
+import IR.*;
+import IR.Tree.*;
+import IR.Flat.*;
+import java.util.*;
+import java.io.*;
+import Util.GraphNode;
+
+public class TaskNode extends GraphNode {
+       
+       private final String name;
+       private int uid;
+    private static int nodeid=0;
+    
+    public void setOption(String option) {
+       this.nodeoption=","+option;
+    }
+
+    /**Class Constructor
+     * Creates a new TaskNode using the TaskDescriptor.
+     * @param tasknode TaskDescriptor
+     */
+    public TaskNode(String name){
+           this.name=name;
+           this.uid=TaskNode.nodeid++;
+    }
+     
+    /**Returns the string representation of the node 
+     * @return string representation of the tasknode (e.g "Task foo")
+     */
+    public String getTextLabel() {
+               return "Task "+name;
+       }
+       
+       public String getLabel() {
+       return "N"+uid;
+    }
+
+       
+       /**toString method.
+        * @return  string representation of the tasknode (e.g "Task foo")
+        */
+       public String toString(){
+               return getTextLabel();
+       }
+       
+       public int hashCode(){
+               return name.hashCode();
+               
+       }
+       
+       public boolean equals(Object o) {
+        if (o instanceof TaskNode) {
+           TaskNode tn=(TaskNode)o;
+           return (tn.name.equals(name));
+        }
+        return false;
+    }
+}
+       
+     
+