1
3 package jminusminus;
4
5
8 abstract class NRegister {
9
12 protected int number;
13
14
17 protected String name;
18
19
25 protected NRegister(int number, String name) {
26 this.number = number;
27 this.name = name;
28 }
29
30
35 public int number() {
36 return number;
37 }
38
39
44 public String name() {
45 return name;
46 }
47 }
48
49
52 class NVirtualRegister extends NRegister {
53 private String sType;
55
56 private String lType;
58
59
66 public NVirtualRegister(int number, String sType, String lType) {
67 super(number, "V" + number);
68 this.sType = sType;
69 this.lType = lType;
70 }
71
72
77 public String toString() {
78 return "[" + name + "|" + sType + "]";
79 }
80 }
81
82
85 class NPhysicalRegister extends NRegister {
86
89 public static int MAX_COUNT = 8;
90
91
94
97 public static final int ZERO = 0;
98
99
102 public static final int AT = 1;
103
104
107 public static final int V0 = 2;
108
109
112 public static final int V1 = 3;
113
114
117 public static final int A0 = 4;
118
119
122 public static final int A1 = 5;
123
124
127 public static final int A2 = 6;
128
129
132 public static final int A3 = 7;
133
134
137 public static final int T0 = 8;
138
139
142 public static final int T1 = 9;
143
144
147 public static final int T2 = 10;
148
149
152 public static final int T3 = 11;
153
154
157 public static final int T4 = 12;
158
159
162 public static final int T5 = 13;
163
164
167 public static final int T6 = 14;
168
169
172 public static final int T7 = 15;
173
174
177 public static final int S0 = 16;
178
179
182 public static final int S1 = 17;
183
184
187 public static final int S2 = 18;
188
189
192 public static final int S3 = 19;
193
194
197 public static final int S4 = 20;
198
199
202 public static final int S5 = 21;
203
204
207 public static final int S6 = 22;
208
209
212 public static final int S7 = 23;
213
214
217 public static final int T8 = 24;
218
219
222 public static final int T9 = 25;
223
224
227 public static final int K0 = 26;
228
229
232 public static final int K1 = 27;
233
234
237 public static final int GP = 28;
238
239
242 public static final int SP = 29;
243
244
247 public static final int FP = 30;
248
249
252 public static final int RA = 31;
253
254
257 public static final NPhysicalRegister[] regInfo = {
258 new NPhysicalRegister(0, "zero"), new NPhysicalRegister(1, "at"),
259 new NPhysicalRegister(2, "v0"), new NPhysicalRegister(3, "v1"),
260 new NPhysicalRegister(4, "a0"), new NPhysicalRegister(5, "a1"),
261 new NPhysicalRegister(6, "a2"), new NPhysicalRegister(7, "a3"),
262 new NPhysicalRegister(8, "t0"), new NPhysicalRegister(9, "t1"),
263 new NPhysicalRegister(10, "t2"), new NPhysicalRegister(11, "t3"),
264 new NPhysicalRegister(12, "t4"), new NPhysicalRegister(13, "t5"),
265 new NPhysicalRegister(14, "t6"), new NPhysicalRegister(15, "t7"),
266 new NPhysicalRegister(16, "s0"), new NPhysicalRegister(17, "s1"),
267 new NPhysicalRegister(18, "s2"), new NPhysicalRegister(19, "s3"),
268 new NPhysicalRegister(20, "s4"), new NPhysicalRegister(21, "s5"),
269 new NPhysicalRegister(22, "s6"), new NPhysicalRegister(23, "s7"),
270 new NPhysicalRegister(24, "t8"), new NPhysicalRegister(25, "t9"),
271 new NPhysicalRegister(26, "k0"), new NPhysicalRegister(27, "k1"),
272 new NPhysicalRegister(28, "gp"), new NPhysicalRegister(29, "sp"),
273 new NPhysicalRegister(30, "fp"), new NPhysicalRegister(31, "ra")};
274
275
281 public NPhysicalRegister(int number, String name) {
282 super(number, name);
283 }
284
285
290 public String toString() {
291 return "$" + name();
292 }
293 }
294