remove some codes for scheduling
[IRC.git] / Robust / src / IR / Flat / FlatMethod.java
index d0c7b83e09dd1bc95aaa234a345dde110c2c7396..b48f718ec3add0365bcf4b7d1e75d1ec43e066e4 100644 (file)
 package IR.Flat;
 import IR.MethodDescriptor;
+import IR.TaskDescriptor;
 import java.util.*;
 
 public class FlatMethod extends FlatNode {
-    FlatNode method_entry;
     MethodDescriptor method;
+    TaskDescriptor task;
+    Vector parameterTemps;
+    Vector tagTemps;
+    Hashtable tagtointmap;
 
-    FlatMethod(MethodDescriptor md, FlatNode entry) {
+    FlatMethod(MethodDescriptor md) {
        method=md;
-       method_entry=entry;
+       task=null;
+       parameterTemps=new Vector();
+       tagTemps=new Vector();
+       tagtointmap=new Hashtable();
     }
-    
+
+    FlatMethod(TaskDescriptor td) {
+       task=td;
+       method=null;
+       parameterTemps=new Vector();
+       tagTemps=new Vector();
+       tagtointmap=new Hashtable();
+    }
+
     public String toString() {
        return method.toString();
     }
+
+    public MethodDescriptor getMethod() {
+       return method;
+    }
+
+    public TaskDescriptor getTask() {
+       return task;
+    }
+    
+    public int kind() {
+       return FKind.FlatMethod;
+    }
+
+    public void addParameterTemp(TempDescriptor t) {
+       parameterTemps.add(t);
+    }
+
+    public int numParameters() {
+       return parameterTemps.size();
+    }
+
+    public void addTagTemp(TempDescriptor t) {
+       tagtointmap.put(t, new Integer(tagTemps.size()));
+       tagTemps.add(t);
+    }
+
+    public int getTagInt(TempDescriptor t) {
+       return ((Integer)tagtointmap.get(t)).intValue();
+    }
+
+    public int numTags() {
+       return tagTemps.size();
+    }
+
+    public TempDescriptor getTag(int i) {
+       return (TempDescriptor) tagTemps.get(i);
+    }
+    
+    public TempDescriptor getParameter(int i) {
+       return (TempDescriptor) parameterTemps.get(i);
+    }
+
+    /** This method returns a set of the nodes in this flat representation */
+
+    public Set<FlatNode> getNodeSet() {
+       HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
+       HashSet<FlatNode> visited=new HashSet<FlatNode>();
+       tovisit.add(this);
+       while(!tovisit.isEmpty()) {
+           FlatNode fn=tovisit.iterator().next();
+           tovisit.remove(fn);
+           visited.add(fn);
+           for(int i=0;i<fn.numNext();i++) {
+               FlatNode nn=fn.getNext(i);
+               if (!visited.contains(nn))
+                   tovisit.add(nn);
+           }
+       }
+       return visited;
+    }
     
     public String printMethod() {
-       String st=method+"\n";
+       return printMethod(null);
+    }
+
+    /** This method returns a string that is a human readable
+     * representation of this method. */
+
+    public String printMethod(Hashtable map) {
+       String st=method+" {\n";
        HashSet tovisit=new HashSet();
        HashSet visited=new HashSet();
        int labelindex=0;
        Hashtable nodetolabel=new Hashtable();
-       tovisit.add(method_entry);
+       tovisit.add(this);
        FlatNode current_node=null;
        //Assign labels 1st
        //Node needs a label if it is
@@ -29,13 +111,14 @@ public class FlatMethod extends FlatNode {
            FlatNode fn=(FlatNode)tovisit.iterator().next();
            tovisit.remove(fn);
            visited.add(fn);
+
            for(int i=0;i<fn.numNext();i++) {
                FlatNode nn=fn.getNext(i);
                if(i>0) {
                    //1) Edge >1 of node
                    nodetolabel.put(nn,new Integer(labelindex++));
                }
-               if (!visited.contains(nn)) {
+               if (!visited.contains(nn)&&!tovisit.contains(nn)) {
                    tovisit.add(nn);
                } else {
                    //2) Join point
@@ -47,7 +130,7 @@ public class FlatMethod extends FlatNode {
        //Do the actual printing
        tovisit=new HashSet();
        visited=new HashSet();
-       tovisit.add(method_entry);
+       tovisit.add(this);
        while(current_node!=null||!tovisit.isEmpty()) {
            if (current_node==null) {
                current_node=(FlatNode)tovisit.iterator().next();
@@ -57,10 +140,16 @@ public class FlatMethod extends FlatNode {
            if (nodetolabel.containsKey(current_node))
                st+="L"+nodetolabel.get(current_node)+":\n";
            if (current_node.numNext()==0) {
-               st+="   "+current_node.toString()+"\n";
+               if (map==null)
+                   st+="   "+current_node.toString()+"\n";
+               else
+                   st+="   "+current_node.toString()+"["+map.get(current_node)+"]\n";
                current_node=null;
            } else if(current_node.numNext()==1) {
-               st+="   "+current_node.toString()+"\n";
+               if (map==null)
+                   st+="   "+current_node.toString()+"\n";
+               else
+                   st+="   "+current_node.toString()+"["+map.get(current_node)+"]\n";
                FlatNode nextnode=current_node.getNext(0);
                if (visited.contains(nextnode)) {
                    st+="goto L"+nodetolabel.get(nextnode)+"\n";
@@ -79,7 +168,10 @@ public class FlatMethod extends FlatNode {
                    current_node=current_node.getNext(0);
            } else throw new Error();
        }
-       return st;
+       return st+"}\n";
+    }
+    
+    public TempDescriptor [] writesTemps() {
+       return (TempDescriptor[]) parameterTemps.toArray(new TempDescriptor[ parameterTemps.size()]);
     }
-
 }