-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIR3.java
731 lines (583 loc) · 23.1 KB
/
IR3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.AbstractMap;
abstract class IR3 {
public static Integer labelCount = 0;
public static Integer variableCount = 0;
public static Integer mkLabel() {
return IR3.labelCount++;
}
public static String mkVar(Type type) {
String varName = "_tmp" + IR3.variableCount++;
SymbolTables.currentTable.setLocal(varName, type);
return varName;
}
public static String extractLvalue(ArrayList<IR3> irs) {
if (irs.isEmpty()) {
return "NO_L_VALUE";
}
return irs.get(irs.size() - 1).lvalue;
}
public static void printIR3(ArrayList<IR3> irs) {
System.out.println("===== IR3 BEGIN =====\n");
for (IR3 ir : irs) System.out.println(ir.toString());
System.out.println("===== IR3 END =====\n");
}
public String lvalue;
public ArrayList<ARMInstruction> toARMInstructions() {
return new ArrayList<>();
}
}
class PlaceholderIR3 extends IR3 {
@Override
public String toString() {
return "PLACEHOLDER\n";
}
}
class LabelIR3 extends IR3 {
public Integer label;
public LabelIR3() {
this.label = IR3.mkLabel();
}
@Override
public String toString() {
return "L" + label + ":\n";
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
instructions.add(new ARMLabel(label));
return instructions;
}
}
class GotoIR3 extends IR3 {
Integer label;
String condition;
public GotoIR3(Integer label, String condition) {
this.condition = condition;
this.label = label;
}
public GotoIR3(Integer label) {
this(label, null);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (condition != null) sb.append("If(" + condition + ") ");
sb.append("Goto .L" + label + ";\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
if (condition == null) {
instructions.add(new ARMJump(label));
return instructions;
}
SymbolTableEntry conditionTableEntry = SymbolTables.currentTable.getEntry(condition);
// place the boolean to check in v1
if (conditionTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov("v1", conditionTableEntry.register));
} else {
instructions.add(new ARMSimpleMemoryLoad("v1", "sp", conditionTableEntry.offset));
}
// cmp v1, #1
// beq Ln
instructions.add(new ARMCmp("v1", 1));
instructions.add(new ARMJump(label, "eq"));
return instructions;
}
}
class FunctionStartIR3 extends IR3 {
public String returntype;
public String name;
public ArrayList<Map.Entry<String, Type>> params = new ArrayList<>();
public FunctionStartIR3(String returntype, String name) {
this.returntype = returntype;
this.name = name;
}
public void addParam(String name, String type) {
params.add(new AbstractMap.SimpleEntry(name, Type.fromTypeString(type)));
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(returntype + " " + name);
sb.append("(");
for (Map.Entry<String, Type> entry : params) {
sb.append(entry.getValue() + " " + entry.getKey().toString() + ", ");
}
sb.deleteCharAt(sb.length() - 1);
sb.deleteCharAt(sb.length() - 1);
sb.append(")");
sb.append(" {\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
instructions.add(new ARMRawLabel(name));
instructions.add(new ARMSTMFD("lr"));
Integer sizeOfStackFrameNeeded = SymbolTables.currentTable.size;
instructions.add(new ARMLoadLiteral("v5", sizeOfStackFrameNeeded));
instructions.add(new ARMArithmetic("-", "sp", "sp", "v5"));
return instructions;
}
}
class FunctionEndIR3 extends IR3 {
@Override
public String toString() {
return "}\n";
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
Integer sizeOfStackFrameNeeded = SymbolTables.currentTable.size;
instructions.add(new ARMLoadLiteral("v5", sizeOfStackFrameNeeded));
instructions.add(new ARMArithmetic("+", "sp", "sp", "v5"));
instructions.add(new ARMLDMFD("pc"));
instructions.add(new ARMNewline(1));
return instructions;
}
}
class FunctionCallIR3 extends IR3 {
public String name;
public Type returntype;
public ArrayList<String> args;
public FunctionCallIR3(String name, Type returntype, ArrayList<String> args) {
this.lvalue = IR3.mkVar(returntype);
this.name = name;
this.returntype = returntype;
this.args = args;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + " = " + name + "(");
for (String arg : args) sb.append(arg + ",");
sb.deleteCharAt(sb.length() - 1);
sb.append(");\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
// move a1-a4 into v1-v4 (cannot push them just yet... will mess up stack offsets for the argument load)
instructions.add(new ARMMov("v1", "a1"));
instructions.add(new ARMMov("v2", "a2"));
instructions.add(new ARMMov("v3", "a3"));
instructions.add(new ARMMov("v4", "a4"));
// load arguments
int paramRegNum = 1;
for (String arg : args) {
if (paramRegNum > 4) break; // TODO: support more then 4 arguments!
String paramReg = "a" + paramRegNum;
SymbolTableEntry argEntry = SymbolTables.currentTable.getEntry(arg);
if (argEntry.isRegisterAllocated()) {
instructions.add(new ARMMov(paramReg, argEntry.register));
} else {
instructions.add(new ARMSimpleMemoryLoad(paramReg, "sp", argEntry.offset));
}
paramRegNum++;
}
// save registers (now safe to push)
instructions.add(new ARMSTMFD("v1"));
instructions.add(new ARMSTMFD("v2"));
instructions.add(new ARMSTMFD("v3"));
instructions.add(new ARMSTMFD("v4"));
// call function
instructions.add(new ARMBranchLink(this.name));
// move the return value from a1 into v5
instructions.add(new ARMMov("v5", "a1"));
// restore registers after return
instructions.add(new ARMLDMFD("a4"));
instructions.add(new ARMLDMFD("a3"));
instructions.add(new ARMLDMFD("a2"));
instructions.add(new ARMLDMFD("a1"));
// save return value (that is now in v5)
SymbolTableEntry lvalueTableEntry = SymbolTables.currentTable.getEntry(lvalue);
if (lvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov(lvalueTableEntry.register, "v5"));
} else {
instructions.add(new ARMSimpleMemoryStore("v5", "sp", lvalueTableEntry.offset));
}
return instructions;
}
}
class PrintIR3 extends IR3 {
String output;
Boolean isInt;
PrintIR3(String output, Boolean isInt) {
this.output = output;
this.isInt = isInt;
}
@Override
public String toString() {
return "println(" + output + "); " + (isInt ? "as Int" : "") + "\n";
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry outputTableEntry = SymbolTables.currentTable.getEntry(output);
// instructions.add(new ARMPush("a2")); // save a2
// instructions.add(new ARMPush("a1")); // save a1
instructions.add(new ARMMov("v1", "a1"));
instructions.add(new ARMMov("v2", "a2"));
if (isInt) {
instructions.add(new ARMLoadLabel("a1", DataTable.PRINT_INT_FORMAT_STR_LABEL));
if (outputTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov("a2", outputTableEntry.register));
} else {
instructions.add(new ARMSimpleMemoryLoad("a2", "sp", outputTableEntry.offset));
}
} else {
if (outputTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov("a1", outputTableEntry.register));
} else {
instructions.add(new ARMSimpleMemoryLoad("a1", "sp", outputTableEntry.offset));
}
}
instructions.add(new ARMPrintf());
instructions.add(new ARMMov("a2", "v2"));
instructions.add(new ARMMov("a1", "v1"));
// instructions.add(new ARMPop("a1")); // restore a1
// instructions.add(new ARMPop("a2")); // restore a2
return instructions;
}
}
class ReadIR3 extends IR3 {
String input;
ReadIR3(String input) {
this.input = input;
}
@Override
public String toString() {
return "readln(" + input + ");\n";
}
}
class ConstructionIR3 extends IR3 {
public String cls;
public Integer size;
public ConstructionIR3(String cls) {
this.lvalue = IR3.mkVar(new RefType(cls));
this.cls = cls;
this.size = ClassTables.get(cls).size;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + " = new " + cls + "();\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
instructions.add(new ARMLoadLiteral("a1", size));
instructions.add(new ARMMalloc());
instructions.add(new ARMMov("v1", "a1"));
SymbolTableEntry lvalueTableEntry = SymbolTables.currentTable.getEntry(lvalue);
if (lvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov(lvalueTableEntry.register, "v1"));
} else {
instructions.add(new ARMSimpleMemoryStore("v1", "sp", lvalueTableEntry.offset));
}
return instructions;
}
}
class ReturnIR3 extends IR3 {
public String retval;
public ReturnIR3(String retval) {
this.retval = retval;
}
public ReturnIR3() {
this(null);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Return");
if (retval != null) sb.append(" " + retval);
sb.append(";\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry retvalTableEntry = SymbolTables.currentTable.getEntry(retval);
if (retvalTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov("a1", retvalTableEntry.register));
} else {
instructions.add(new ARMSimpleMemoryLoad("a1", "sp", retvalTableEntry.offset));
}
// leave the function
Integer sizeOfStackFrameNeeded = SymbolTables.currentTable.size;
instructions.add(new ARMLoadLiteral("v5", sizeOfStackFrameNeeded));
instructions.add(new ARMArithmetic("+", "sp", "sp", "v5"));
instructions.add(new ARMLDMFD("pc"));
return instructions;
}
}
class AssignmentIR3 extends IR3 {
public String val;
public AssignmentIR3(String assignee, String val) {
this.lvalue = assignee;
this.val = val;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + " = " + val + ";\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry lvalueTableEntry = SymbolTables.currentTable.getEntry(lvalue);
SymbolTableEntry rvalueTableEntry = SymbolTables.currentTable.getEntry(val);
if (lvalueTableEntry.isRegisterAllocated() && rvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov(lvalueTableEntry.register, rvalueTableEntry.register));
} else if (lvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMSimpleMemoryLoad(lvalueTableEntry.register, "sp", rvalueTableEntry.offset));
} else if (rvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMSimpleMemoryStore(rvalueTableEntry.register, "sp", lvalueTableEntry.offset));
} else {
instructions.add(new ARMSimpleMemoryLoad("v1", "sp", rvalueTableEntry.offset));
instructions.add(new ARMSimpleMemoryStore("v1", "sp", lvalueTableEntry.offset));
}
return instructions;
}
}
class LabelAssignmentIR3 extends IR3 {
public Integer label;
public LabelAssignmentIR3(String assignee, Integer label) {
this.lvalue = assignee;
this.label = label;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + " = =L" + label + ";\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry lvalueTableEntry = SymbolTables.currentTable.getEntry(lvalue);
if (lvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMLoadLabel(lvalueTableEntry.register, label));
} else {
instructions.add(new ARMLoadLabel("v1", label));
instructions.add(new ARMSimpleMemoryStore("v1", "sp", lvalueTableEntry.offset));
}
return instructions;
}
}
class MemberAssignmentIR3 extends IR3 {
public String field;
public String val;
public Integer offset;
public MemberAssignmentIR3(String assigneeObject, String assigneeField, String val) {
this.lvalue = assigneeObject;
this.field = assigneeField;
this.val = val;
// a current table is expected to be active during IR3 construction
Type assigneeObjType = SymbolTables.currentTable.getEntry(assigneeObject).type;
this.offset = ClassTables.get(assigneeObjType).getFieldOffset(assigneeField);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + "[" + offset + "]" + " = " + val + ";");
sb.append(" {" + lvalue + "." + field + " = " + val + "}\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry valTableEntry = SymbolTables.currentTable.getEntry(val);
// put value in v2
if (valTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov("v2", valTableEntry.register));
} else {
instructions.add(new ARMSimpleMemoryLoad("v2", "sp", valTableEntry.offset));
}
SymbolTableEntry objTableEntry = SymbolTables.currentTable.getEntry(lvalue);
// put object reference in v1
if (objTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov("v1", objTableEntry.register));
} else {
instructions.add(new ARMSimpleMemoryLoad("v1", "sp", objTableEntry.offset));
}
// store the contents of v2 into the memory address pointed to by v1 with offset
instructions.add(new ARMSimpleMemoryStore("v2", "v1", offset));
return instructions;
}
}
class MemberAccessIR3 extends IR3 {
public String obj;
public String field;
public Integer offset;
public MemberAccessIR3(String obj, String field) {
// a current table is expected to be active during IR3 construction
RefType objType = (RefType) SymbolTables.currentTable.getEntry(obj).type;
this.lvalue = IR3.mkVar(ClassTables.get(objType.classname).getFieldType(field));
this.obj = obj;
this.field = field;
this.offset = ClassTables.get(objType).getFieldOffset(field);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + " = " + obj + "[" + offset + "];");
sb.append(" {" + lvalue + " = " + obj + "." + field + "}\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry objTableEntry = SymbolTables.currentTable.getEntry(obj);
// put object reference in v1
if (objTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov("v1", objTableEntry.register));
} else {
instructions.add(new ARMSimpleMemoryLoad("v1", "sp", objTableEntry.offset));
}
// load the memory address pointed to by v1 with offset and put it in v2
instructions.add(new ARMSimpleMemoryLoad("v2", "v1", offset));
SymbolTableEntry lvalueTableEntry = SymbolTables.currentTable.getEntry(lvalue);
// write contents of v2 into lvalue mem/reg
if (lvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov(lvalueTableEntry.register, "v2"));
} else {
instructions.add(new ARMSimpleMemoryStore("v2", "sp", lvalueTableEntry.offset));
}
return instructions;
}
}
class UnOpIR3 extends IR3 {
public String op;
public String operand;
public UnOpIR3(String op, String operand) {
this.lvalue = IR3.mkVar(SymbolTables.currentTable.getEntry(operand).type);
this.op = op;
this.operand = operand;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + " = " + op + operand + ";\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry operandTableEntry = SymbolTables.currentTable.getEntry(operand);
if (operandTableEntry.isRegisterAllocated()) {
instructions.add(new ARMArithmetic(op, "v1", operandTableEntry.register));
} else {
instructions.add(new ARMSimpleMemoryLoad("v2", "sp", operandTableEntry.offset));
instructions.add(new ARMArithmetic(op, "v1", "v2"));
}
SymbolTableEntry lvalueTableEntry = SymbolTables.currentTable.getEntry(lvalue);
if (lvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov(lvalueTableEntry.register, "v1"));
} else {
instructions.add(new ARMSimpleMemoryStore("v1", "sp", lvalueTableEntry.offset));
}
return instructions;
}
}
class BinOpIR3 extends IR3 {
public String op;
public String left;
public String right;
public BinOpIR3(String op, String left, String right) {
this.lvalue = IR3.mkVar(SymbolTables.currentTable.getEntry(left).type);
this.op = op;
this.left = left;
this.right = right;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + " = " + left + " " + op + " " + right + ";\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry leftTableEntry = SymbolTables.currentTable.getEntry(left);
SymbolTableEntry rightTableEntry = SymbolTables.currentTable.getEntry(right);
if (leftTableEntry.isRegisterAllocated() && rightTableEntry.isRegisterAllocated()) {
instructions.add(new ARMArithmetic(op, "v1", leftTableEntry.register, rightTableEntry.register));
} else if (leftTableEntry.isRegisterAllocated()) {
instructions.add(new ARMSimpleMemoryLoad("v3", "sp", rightTableEntry.offset));
instructions.add(new ARMArithmetic(op, "v1", "v2", "v3"));
} else if (rightTableEntry.isRegisterAllocated()) {
instructions.add(new ARMSimpleMemoryLoad("v2", "sp", leftTableEntry.offset));
instructions.add(new ARMArithmetic(op, "v1", "v2", "v3"));
} else {
instructions.add(new ARMSimpleMemoryLoad("v2", "sp", leftTableEntry.offset));
instructions.add(new ARMSimpleMemoryLoad("v3", "sp", rightTableEntry.offset));
instructions.add(new ARMArithmetic(op, "v1", "v2", "v3"));
}
SymbolTableEntry lvalueTableEntry = SymbolTables.currentTable.getEntry(lvalue);
if (lvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMMov(lvalueTableEntry.register, "v1"));
} else {
instructions.add(new ARMSimpleMemoryStore("v1", "sp", lvalueTableEntry.offset));
}
return instructions;
}
}
class IntIR3 extends IR3 {
public Integer val;
public IntIR3(Integer val) {
this.lvalue = IR3.mkVar(Type.JLINT);
this.val = val;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + " = " + val + ";\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry lvalueTableEntry = SymbolTables.currentTable.getEntry(lvalue);
if (lvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMLoadLiteral(lvalueTableEntry.register, val));
} else {
instructions.add(new ARMLoadLiteral("v1", val));
instructions.add(new ARMSimpleMemoryStore("v1", "sp", lvalueTableEntry.offset));
}
return instructions;
}
}
class BoolIR3 extends IR3 {
public Boolean val;
public BoolIR3(Boolean val) {
this.lvalue = IR3.mkVar(Type.JLBOOL);
this.val = val;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(lvalue + " = " + val + ";\n");
return sb.toString();
}
@Override
public ArrayList<ARMInstruction> toARMInstructions() {
ArrayList<ARMInstruction> instructions = new ArrayList<>();
SymbolTableEntry lvalueTableEntry = SymbolTables.currentTable.getEntry(lvalue);
if (lvalueTableEntry.isRegisterAllocated()) {
instructions.add(new ARMLoadLiteral(lvalueTableEntry.register, val ? 1 : 0));
} else {
instructions.add(new ARMLoadLiteral("v1", val ? 1 : 0));
instructions.add(new ARMSimpleMemoryStore("v1", "sp", lvalueTableEntry.offset));
}
return instructions;
}
}