few more changes
[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     this.excprefetch=new HashSet();
20     this.classpath=new Vector();
21   }
22
23   public void addParseNode(ParseNode parsetree) {
24     parsetrees.add(parsetree);
25   }
26
27   public void storeAnalysisResult(Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults) {
28     this.analysisresults=analysisresults;
29   }
30
31   public Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> getAnalysisResult() {
32     return analysisresults;
33   }
34
35
36   public void storeOptionalTaskDescriptors(Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors) {
37     this.optionaltaskdescriptors=optionaltaskdescriptors;
38   }
39
40   public Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> getOptionalTaskDescriptors() {
41     return optionaltaskdescriptors;
42   }
43
44
45   /** Boolean flag which indicates whether compiler is compiling a task-based
46    * program. */
47   public boolean WEBINTERFACE=false;
48   public boolean TASK=false;
49   public boolean FASTCHECK=false;
50   public boolean DSM=false;
51   public boolean PREFETCH=false;
52   public boolean TASKSTATE=false;
53   public boolean TAGSTATE=false;
54   public boolean FLATIRGRAPH=false;
55   public boolean FLATIRGRAPHTASKS=false;
56   public boolean FLATIRGRAPHUSERMETHODS=false;
57   public boolean FLATIRGRAPHLIBMETHODS=false;
58   public boolean MULTICORE=false;
59   public boolean OWNERSHIP=false;
60   public int OWNERSHIPALLOCDEPTH=3;
61   public boolean OWNERSHIPWRITEDOTS=false;
62   public boolean OWNERSHIPWRITEALL=false;
63   public String OWNERSHIPALIASFILE=null;
64   public boolean OPTIONAL=false;
65   public boolean ARRAYBOUNDARYCHECK=true;
66   public boolean RAW=false;
67   public boolean SCHEDULING=false;
68   public boolean USEPROFILE=false;
69   public boolean THREAD=false;
70   public boolean CONSCHECK=false;
71   public boolean INSTRUCTIONFAILURE=false;
72   public static double TRUEPROB=0.8;
73   public static boolean PRINTFLAT=false;
74   public static boolean PRINTSCHEDULING=false;
75   public static boolean PRINTSCHEDULESIM=false;
76   public static boolean ABORTREADERS=false;
77   public int CORENUM = 1;
78   public String structfile;
79   public String main;
80
81   public HashSet selfloops;
82   public HashSet excprefetch;
83   public Vector classpath;
84   public SymbolTable classes;
85   public SymbolTable tasks;
86   public Set parsetrees;
87   public Hashtable treemethodmap;
88   public Hashtable flatmethodmap;
89   private HashSet arraytypes;
90   public Hashtable arraytonumber;
91   private int numclasses=0;
92   private int numtasks=0;
93   private int arraycount=0;
94
95
96
97   private Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors;
98   private Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults;
99
100   private Hashtable tagmap;
101   private int numtags=0;
102
103   public void addArrayType(TypeDescriptor td) {
104     if (!arraytypes.contains(td)) {
105       arraytypes.add(td);
106       arraytonumber.put(td,new Integer(arraycount++));
107     }
108   }
109
110   public Iterator getArrayIterator() {
111     return arraytypes.iterator();
112   }
113
114   public int getTagId(TagDescriptor tag) {
115     if (tagmap.containsKey(tag)) {
116       return ((Integer) tagmap.get(tag)).intValue();
117     } else {
118       tagmap.put(tag, new Integer(numtags));
119       return numtags++;
120     }
121   }
122
123   public int getArrayNumber(TypeDescriptor td) {
124     if (arraytonumber.containsKey(td))
125       return ((Integer)arraytonumber.get(td)).intValue();
126     else return -1;
127   }
128
129   public int numArrays() {
130     return arraytypes.size();
131   }
132
133   public static TypeDescriptor getTypeDescriptor(int t) {
134     TypeDescriptor td=new TypeDescriptor(t);
135     return td;
136   }
137
138   public static TypeDescriptor getTypeDescriptor(NameDescriptor n) {
139     TypeDescriptor td=new TypeDescriptor(n);
140     return td;
141   }
142
143   public void addClass(ClassDescriptor tdn) {
144     if (classes.contains(tdn.getSymbol()))
145       throw new Error("Class "+tdn.getSymbol()+" defined twice");
146     classes.add(tdn);
147     numclasses++;
148   }
149
150   public int numClasses() {
151     return numclasses;
152   }
153
154   public BlockNode getMethodBody(MethodDescriptor md) {
155     return (BlockNode)treemethodmap.get(md);
156   }
157
158   public BlockNode getMethodBody(TaskDescriptor td) {
159     return (BlockNode)treemethodmap.get(td);
160   }
161
162   public SymbolTable getClassSymbolTable() {
163     return classes;
164   }
165
166   public SymbolTable getTaskSymbolTable() {
167     return tasks;
168   }
169
170   /** Returns Flat IR representation of MethodDescriptor md. */
171
172   public FlatMethod getMethodFlat(MethodDescriptor md) {
173     return (FlatMethod)flatmethodmap.get(md);
174   }
175
176   /** Returns Flat IR representation of TaskDescriptor td. */
177
178   public FlatMethod getMethodFlat(TaskDescriptor td) {
179     return (FlatMethod)flatmethodmap.get(td);
180   }
181
182   public void addTreeCode(MethodDescriptor md, BlockNode bn) {
183     treemethodmap.put(md,bn);
184   }
185
186   public void addTreeCode(TaskDescriptor td, BlockNode bn) {
187     treemethodmap.put(td,bn);
188   }
189
190   public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
191     flatmethodmap.put(md,bn);
192   }
193
194   public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
195     flatmethodmap.put(td,bn);
196   }
197
198   public void addTask(TaskDescriptor td) {
199     if (tasks.contains(td.getSymbol()))
200       throw new Error("Task "+td.getSymbol()+" defined twice");
201     tasks.add(td);
202     numtasks++;
203   }
204 }