Skip to content

Commit 4281e80

Browse files
committed
Refactor: implemented new method to load array index
1 parent 1b9c44e commit 4281e80

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/pt/up/fe/comp2023/jasmin/JVMInstructionUtils.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public static String getLoadInstruction(Element element, HashMap<String, Descrip
4747
return "";
4848
}
4949

50+
public static String getArrayLoadInstruction(ArrayOperand array, HashMap<String, Descriptor> varTable) {
51+
String statementList = "";
52+
statementList += getLoadInstruction(array, varTable);
53+
statementList += getLoadInstruction(array.getIndexOperands().get(0), varTable);
54+
return statementList;
55+
}
56+
5057
public static String getStoreInstruction(Element element, HashMap<String, Descriptor> varTable) {
5158
int virtualReg = varTable.get(((Operand)element).getName()).getVirtualReg();
5259

@@ -195,11 +202,8 @@ public static String createAssignStatement(AssignInstruction instruction, HashMa
195202
Element assignElement = instruction.getDest();
196203
String statementList = "";
197204

198-
if (assignElement instanceof ArrayOperand) {
199-
statementList += getLoadInstruction(assignElement, varTable);
200-
statementList += getLoadInstruction(((ArrayOperand)assignElement).getIndexOperands().get(0), varTable);
201-
}
202-
205+
if (assignElement instanceof ArrayOperand)
206+
statementList += getArrayLoadInstruction((ArrayOperand)assignElement, varTable);
203207
statementList += JasminUtils.handleInstruction(instruction.getRhs(), varTable, true);
204208
if (assignElement instanceof ArrayOperand)
205209
statementList += "\tiastore\n";

0 commit comments

Comments
 (0)