-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIRArrayReference.java
More file actions
24 lines (21 loc) · 889 Bytes
/
IRArrayReference.java
File metadata and controls
24 lines (21 loc) · 889 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 IRArrayReference implements IRInstruction {
TempVar t, var, index;
public IRArrayReference(TempVar t, TempVar var, TempVar index) {
this.t = t;
this.var = var;
this.index = index;
}
public String toString() {
return String.format("%s := %s[%s];", t.toString(), var.toString(), index.toString());
}
@Override
public String toBytecodeString() {
String elementType = ((ArrayType)var.type).type.toString().toLowerCase();
StringBuilder sb = new StringBuilder();
sb.append(String.format("aload %d", var.number));
sb.append(String.format("\n %sload %d", index.type.toString().toLowerCase(), index.number));
sb.append(String.format("\n %saload", elementType));
sb.append(String.format("\n %sstore %d", elementType, t.number));
return sb.toString();
}
}