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