1
3 package jminusminus;
4
5 import java.util.ArrayList;
6 import java.util.Collections;
7
8
11
12 abstract class NRegister {
13
14
15 protected int number;
16
17
18 protected String name;
19
20
28
29 protected NRegister(int number, String name) {
30 this.number = number;
31 this.name = name;
32 }
33
34
39
40 public int number() {
41 return number;
42 }
43
44
49
50 public String name() {
51 return name;
52 }
53
54 }
55
56
59
60 class NVirtualRegister extends NRegister {
61
62
63 private String sType;
64
65
66 private String lType;
67
68
78
79 public NVirtualRegister(int number, String sType, String lType) {
80 super(number, "V" + number);
81 this.sType = sType;
82 this.lType = lType;
83 }
84
85
90
91 public String toString() {
92 return "[" + name + "|" + sType + "]";
93 }
94
95 }
96
97
100
101 class NPhysicalRegister extends NRegister {
102
103
106 public static int MAX_COUNT = 8;
107
108
113
114 public static final int ZERO = 0;
115
116
117 public static final int AT = 1;
118
119
120 public static final int V0 = 2;
121
122
123 public static final int V1 = 3;
124
125
126 public static final int A0 = 4;
127
128
129 public static final int A1 = 5;
130
131
132 public static final int A2 = 6;
133
134
135 public static final int A3 = 7;
136
137
138 public static final int T0 = 8;
139
140
141 public static final int T1 = 9;
142
143
144 public static final int T2 = 10;
145
146
147 public static final int T3 = 11;
148
149
150 public static final int T4 = 12;
151
152
153 public static final int T5 = 13;
154
155
156 public static final int T6 = 14;
157
158
159 public static final int T7 = 15;
160
161
162 public static final int S0 = 16;
163
164
165 public static final int S1 = 17;
166
167
168 public static final int S2 = 18;
169
170
171 public static final int S3 = 19;
172
173
174 public static final int S4 = 20;
175
176
177 public static final int S5 = 21;
178
179
180 public static final int S6 = 22;
181
182
183 public static final int S7 = 23;
184
185
186 public static final int T8 = 24;
187
188
189 public static final int T9 = 25;
190
191
192 public static final int K0 = 26;
193
194
195 public static final int K1 = 27;
196
197
198 public static final int GP = 28;
199
200
201 public static final int SP = 29;
202
203
204 public static final int FP = 30;
205
206
207 public static final int RA = 31;
208
209
212 public static final NPhysicalRegister[] regInfo = {
213 new NPhysicalRegister(0, "zero"), new NPhysicalRegister(1, "at"),
214 new NPhysicalRegister(2, "v0"), new NPhysicalRegister(3, "v1"),
215 new NPhysicalRegister(4, "a0"), new NPhysicalRegister(5, "a1"),
216 new NPhysicalRegister(6, "a2"), new NPhysicalRegister(7, "a3"),
217 new NPhysicalRegister(8, "t0"), new NPhysicalRegister(9, "t1"),
218 new NPhysicalRegister(10, "t2"), new NPhysicalRegister(11, "t3"),
219 new NPhysicalRegister(12, "t4"), new NPhysicalRegister(13, "t5"),
220 new NPhysicalRegister(14, "t6"), new NPhysicalRegister(15, "t7"),
221 new NPhysicalRegister(16, "s0"), new NPhysicalRegister(17, "s1"),
222 new NPhysicalRegister(18, "s2"), new NPhysicalRegister(19, "s3"),
223 new NPhysicalRegister(20, "s4"), new NPhysicalRegister(21, "s5"),
224 new NPhysicalRegister(22, "s6"), new NPhysicalRegister(23, "s7"),
225 new NPhysicalRegister(24, "t8"), new NPhysicalRegister(25, "t9"),
226 new NPhysicalRegister(26, "k0"), new NPhysicalRegister(27, "k1"),
227 new NPhysicalRegister(28, "gp"), new NPhysicalRegister(29, "sp"),
228 new NPhysicalRegister(30, "fp"), new NPhysicalRegister(31, "ra"), };
229
230
238
239 public NPhysicalRegister(int number, String name) {
240 super(number, name);
241 }
242
243
248
249 public String toString() {
250 return "$" + name();
251 }
252
253 }
254