Skip to content

Commit a110d7c

Browse files
committed
Created fields to keep track of locals and stack size
1 parent 4dae57c commit a110d7c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
public class JVMInstructionUtils {
1212

13+
public static int numLocals = 0;
14+
public static int stackSize = 0;
15+
1316
public static String getLoadInstruction(Element element, HashMap<String, Descriptor> varTable) {
1417
if (element.isLiteral()) {
1518
int literal = parseInt(((LiteralElement)element).getLiteral());

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,15 @@ public static String createConstructMethod(String superClassName) {
196196
}
197197

198198
public static String createMethodDirective(Method method) {
199+
JVMInstructionUtils.numLocals = 0;
200+
JVMInstructionUtils.stackSize = 0;
199201
String methodDirective = ".method ";
202+
String instructions = handleMethodStatements(method);
203+
200204
methodDirective += createMethodDeclaration(method);
201-
methodDirective += "\t.limit stack 99\n";
202-
methodDirective += "\t.limit locals 99\n";
203-
methodDirective += handleMethodStatements(method);
205+
methodDirective += "\t.limit stack " + JVMInstructionUtils.stackSize + "\n";
206+
methodDirective += "\t.limit locals " + JVMInstructionUtils.numLocals + "\n";
207+
methodDirective += instructions;
204208
return methodDirective + ".end method\n\n";
205209
}
206210
}

0 commit comments

Comments
 (0)