diff --git a/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java b/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java index 2987d20..badd685 100644 --- a/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java +++ b/src/main/java/de/hsrm/compiler/Klang/visitors/GenASM.java @@ -64,7 +64,6 @@ public class GenASM implements Visitor { private String mainName; Map env = new HashMap<>(); Map structs; - Set vars; String[] registers = { "%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9" }; String[] floatRegisters = { "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" }; private int lCount = 0; // Invariant: lCount is used @@ -545,11 +544,6 @@ public class GenASM implements Visitor { asm.mov("q", "%rsp", "%rbp"); asm.label(lblStart); - // Get the number of local variables. - // TODO: Do this during context analysis and save the result as an attribute of FunctionDefinition. - vars = new TreeSet<>(); - new GetVars(vars, new HashMap<>()).visit(e); - // Create a new environment env = new HashMap<>(); @@ -606,19 +600,19 @@ public class GenASM implements Visitor { } // Reserve memory on the stack for the local variables. - if (!vars.isEmpty()) { + if (e.localVariables.length > 0) { // Each variable is at most 8 bytes in size. - asm.sub("q", "$" + (8 * vars.size()), "%rsp"); + asm.sub("q", "$" + (8 * e.localVariables.length), "%rsp"); // Save the offsets (they are relative to rbp) - for (String lok_var : vars) { + for (var localVariable : e.localVariables) { offset -= 8; - this.env.put(lok_var, offset); + env.put(localVariable.name, offset); } } // Check the stack alignment and correct if necessary - if ((registerParameters.size() + vars.size()) % 2 != 0) { + if ((registerParameters.size() + e.localVariables.length) % 2 != 0) { // Since each variable is 8 bytes and the stack is 16 byte aligned // we need to add 8 bytes to the stack to make it aligned // if there is an odd number of parameters and local variables. @@ -644,7 +638,7 @@ public class GenASM implements Visitor { asm.push("q", "%rax"); } - // push args into local var locations, last arg is ontop of the stack + // push args into local var locations, last arg is on top of the stack for (int i = e.arguments.length - 1; i >= 0; i--) { asm.pop("q", this.env.get(this.currentFunctionParams[i].name) + "(%rbp)"); }