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