Add directory and codes for task scheduling
[IRC.git] / Robust / src / IR / State.java
1 package IR;
2 import IR.Tree.*;
3 import IR.Flat.*;
4 import IR.*;
5 import java.util.*;
6 import Analysis.TaskStateAnalysis.*;
7
8 public class State {
9     public State() {
10         this.classes=new SymbolTable();
11         this.tasks=new SymbolTable();
12         this.treemethodmap=new Hashtable();
13         this.flatmethodmap=new Hashtable();
14         this.parsetrees=new HashSet();
15         this.arraytypes=new HashSet();
16         this.arraytonumber=new Hashtable();
17         this.tagmap=new Hashtable();
18         this.selfloops=new HashSet();
19     }
20
21     public void addParseNode(ParseNode parsetree) {
22         parsetrees.add(parsetree);
23     }
24
25     public void storeAnalysisResult(Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults) {
26         this.analysisresults=analysisresults;
27     }
28
29     public Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> getAnalysisResult() {
30         return analysisresults;
31     }
32
33
34     public void storeOptionalTaskDescriptors(Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors){
35         this.optionaltaskdescriptors=optionaltaskdescriptors;
36     }
37
38     public Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> getOptionalTaskDescriptors(){
39         return optionaltaskdescriptors;
40     }
41
42     /** Boolean flag which indicates whether compiler is compiling a task-based
43      * program. */
44     public boolean WEBINTERFACE=false;
45     public boolean TASK=false;
46     public boolean DSM=false;
47     public boolean PREFETCH=false;
48     public boolean TASKSTATE=false;
49     public boolean FLATIRGRAPH=false;
50     public boolean FLATIRGRAPHTASKS=false;
51     public boolean FLATIRGRAPHUSERMETHODS=false;
52     public boolean FLATIRGRAPHLIBMETHODS=false;
53     public boolean OWNERSHIP=false;
54     public boolean OPTIONAL=false;
55     public boolean SCHEDULING=false;  
56     public boolean THREAD=false;
57     public boolean CONSCHECK=false;
58     public boolean INSTRUCTIONFAILURE=false;
59     public String structfile;
60     public String main;
61
62     public HashSet selfloops;
63     public SymbolTable classes;
64     public SymbolTable tasks;
65     public Set parsetrees;
66     public Hashtable treemethodmap;
67     public Hashtable flatmethodmap;
68     private HashSet arraytypes;
69     public Hashtable arraytonumber;
70     private int numclasses=0;
71     private int numtasks=0;
72     private int arraycount=0;
73
74
75     private Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors;
76     private Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults;
77
78     private Hashtable tagmap;
79     private int numtags=0;
80
81     public void addArrayType(TypeDescriptor td) {
82         if (!arraytypes.contains(td)) {
83             arraytypes.add(td);
84             arraytonumber.put(td,new Integer(arraycount++));
85         }
86     }
87
88     public Iterator getArrayIterator() {
89         return arraytypes.iterator();
90     }
91
92     public int getTagId(TagDescriptor tag) {
93         if (tagmap.containsKey(tag)) {
94             return ((Integer) tagmap.get(tag)).intValue();
95         } else {
96             tagmap.put(tag, new Integer(numtags));
97             return numtags++;
98         }
99     }
100
101     public int getArrayNumber(TypeDescriptor td) {
102         return ((Integer)arraytonumber.get(td)).intValue();
103     }
104
105     public int numArrays() {
106         return arraytypes.size();
107     }
108
109     public static TypeDescriptor getTypeDescriptor(int t) {
110         TypeDescriptor td=new TypeDescriptor(t);
111         return td;
112     }
113
114     public static TypeDescriptor getTypeDescriptor(NameDescriptor n) {
115         TypeDescriptor td=new TypeDescriptor(n);
116         return td;
117     }
118
119     public void addClass(ClassDescriptor tdn) {
120         if (classes.contains(tdn.getSymbol()))
121             throw new Error("Class "+tdn.getSymbol()+" defined twice");
122         classes.add(tdn);
123         numclasses++;
124     }
125
126     public int numClasses() {
127         return numclasses;
128     }
129
130     public BlockNode getMethodBody(MethodDescriptor md) {
131         return (BlockNode)treemethodmap.get(md);
132     }
133
134     public BlockNode getMethodBody(TaskDescriptor td) {
135         return (BlockNode)treemethodmap.get(td);
136     }
137
138     public SymbolTable getClassSymbolTable() {
139         return classes;
140     }
141
142     public SymbolTable getTaskSymbolTable() {
143         return tasks;
144     }
145
146     /** Returns Flat IR representation of MethodDescriptor md. */
147
148     public FlatMethod getMethodFlat(MethodDescriptor md) {
149         return (FlatMethod)flatmethodmap.get(md);
150     }
151
152     /** Returns Flat IR representation of TaskDescriptor td. */
153
154     public FlatMethod getMethodFlat(TaskDescriptor td) {
155         return (FlatMethod)flatmethodmap.get(td);
156     }
157
158     public void addTreeCode(MethodDescriptor md, BlockNode bn) {
159         treemethodmap.put(md,bn);
160     }
161
162     public void addTreeCode(TaskDescriptor td, BlockNode bn) {
163         treemethodmap.put(td,bn);
164     }
165
166     public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
167         flatmethodmap.put(md,bn);
168     }
169
170     public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
171         flatmethodmap.put(td,bn);
172     }
173
174     public void addTask(TaskDescriptor td) {
175         if (tasks.contains(td.getSymbol()))
176             throw new Error("Task "+td.getSymbol()+" defined twice");
177         tasks.add(td);
178         numtasks++;
179     }
180 }