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