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