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