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