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