-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIRArrayAssignment.java
More file actions
24 lines (21 loc) · 903 Bytes
/
IRArrayAssignment.java
File metadata and controls
24 lines (21 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class IRArrayAssignment implements IRInstruction {
TempVar lhs, rhs, index;
public IRArrayAssignment(TempVar lhs, TempVar rhs, TempVar index) {
this.lhs = lhs;
this.rhs = rhs;
this.index = index;
}
public String toString() {
return String.format("%s[%s] := %s;", lhs.toString(), index.toString(), rhs.toString());
}
@Override
public String toBytecodeString() {
String elementType = ((ArrayType)lhs.type).type.toString().toLowerCase();
StringBuilder sb = new StringBuilder();
sb.append(String.format("aload %d", lhs.number));
sb.append(String.format("\n %sload %d", index.type.toString().toLowerCase(), index.number));
sb.append(String.format("\n %sload %d", elementType, rhs.number));
sb.append(String.format("\n %sastore", elementType));
return sb.toString();
}
}