|
2 | 2 |
|
3 | 3 | import org.specs.comp.ollir.*;
|
4 | 4 |
|
5 |
| -import java.util.ArrayList; |
6 |
| -import java.util.HashMap; |
7 |
| -import java.util.Objects; |
| 5 | +import java.util.*; |
8 | 6 |
|
9 | 7 | import static java.lang.Integer.parseInt;
|
10 | 8 | import static java.lang.Math.abs;
|
@@ -77,7 +75,8 @@ public static String getStoreInstruction(Element element, HashMap<String, Descri
|
77 | 75 | public static String loadInvokeArguments(ArrayList<Element> listOfOperands, HashMap<String, Descriptor> varTable) {
|
78 | 76 | String statementList = "";
|
79 | 77 | for (Element argument: listOfOperands) {
|
80 |
| - statementList += getLoadInstruction(argument, varTable); } |
| 78 | + statementList += getLoadInstruction(argument, varTable); |
| 79 | + } |
81 | 80 | return statementList;
|
82 | 81 | }
|
83 | 82 |
|
@@ -122,7 +121,14 @@ public static String getNewInstruction(CallInstruction instruction, HashMap<Stri
|
122 | 121 | public static String getNewArrayInstruction(CallInstruction instruction, HashMap<String, Descriptor> varTable) {
|
123 | 122 | String statementList = "";
|
124 | 123 | statementList += loadInvokeArguments(instruction.getListOfOperands(), varTable);
|
125 |
| - statementList += "\tnewarray int\n"; // TODO: change array type |
| 124 | + statementList += "\tnewarray int\n"; |
| 125 | + return statementList; |
| 126 | + } |
| 127 | + |
| 128 | + public static String getArrayLengthInstruction(CallInstruction instruction, HashMap<String, Descriptor> varTable) { |
| 129 | + String statementList = ""; |
| 130 | + statementList += getLoadInstruction(instruction.getFirstArg(), varTable); |
| 131 | + statementList += "\tarraylength\n"; |
126 | 132 | return statementList;
|
127 | 133 | }
|
128 | 134 |
|
@@ -210,6 +216,7 @@ public static String createCallStatement(CallInstruction instruction, HashMap<St
|
210 | 216 | statementList += getInvokeVirtualInstruction(instruction, varTable);
|
211 | 217 | break;
|
212 | 218 | case arraylength:
|
| 219 | + statementList += getArrayLengthInstruction(instruction, varTable); |
213 | 220 | break;
|
214 | 221 | case ldc:
|
215 | 222 | statementList += "\tldc " + ((LiteralElement)instruction.getFirstArg()).getLiteral() + '\n';
|
|
0 commit comments