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