-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIRArrayCreation.java
More file actions
25 lines (22 loc) · 928 Bytes
/
IRArrayCreation.java
File metadata and controls
25 lines (22 loc) · 928 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
25
public class IRArrayCreation implements IRInstruction {
TempVar t;
public IRArrayCreation(TempVar t) {
this.t = t;
}
public String toString() {
ArrayType aType = (ArrayType)t.type;
return String.format("%s := NEWARRAY %s %s;", t.toString(), aType.type.toString(), aType.size.val.toString());
}
@Override
public String toBytecodeString() {
ArrayType aType = (ArrayType)t.type;
StringBuilder sb = new StringBuilder();
sb.append(String.format("ldc %d", aType.size.val));
// This is super tedious
String arrayStringPrefix = (aType.type instanceof StringType) ? "a" : "";
String arrayElementType = aType.type.toStringInArrayCreation();
sb.append(String.format("\n %snewarray %s", arrayStringPrefix, arrayElementType));
sb.append(String.format("\n astore %d", t.number));
return sb.toString();
}
}