Always return stack pointer to bottom of frame when method returns

This commit is contained in:
Henry 2019-12-20 17:19:31 +00:00
parent df4fa67122
commit 0c03966509
3 changed files with 9 additions and 0 deletions

View file

@ -176,6 +176,9 @@ public class CodegenImpl implements Codegen {
// set frame pointer to start of arguments
"addi s0,sp,8\n"
+ "call " + methodLabel + "\n"
// restore stack to frame pointer - 8 (bottom of frame)
// this ensures any stack growth inside the method is undone
+ "addi sp,s0,-8\n"
// restore old frame pointer & stack pointer
+ "lw s0,4(sp)\n"
+ "lw sp,(sp)\n"

View file

@ -176,6 +176,9 @@ public class CodegenImpl implements Codegen {
// set frame pointer to start of arguments
"addi s0,sp,8\n"
+ "call " + methodLabel + "\n"
// restore stack to frame pointer - 8 (bottom of frame)
// this ensures any stack growth inside the method is undone
+ "addi sp,s0,-8\n"
// restore old frame pointer & stack pointer
+ "lw s0,4(sp)\n"
+ "lw sp,(sp)\n"

View file

@ -176,6 +176,9 @@ public class CodegenImpl implements Codegen {
// set frame pointer to start of arguments
"addi s0,sp,8\n"
+ "call " + methodLabel + "\n"
// restore stack to frame pointer - 8 (bottom of frame)
// this ensures any stack growth inside the method is undone
+ "addi sp,s0,-8\n"
// restore old frame pointer & stack pointer
+ "lw s0,4(sp)\n"
+ "lw sp,(sp)\n"