]> rethought.computer Git - sorel-lang.git/commitdiff
no need to restore stack pointer if we're exiting keep/942b296c1adf7778e7476e8b7d1df4235cbb7af6
authorBryan English <bryan@rethought.computer>
Fri, 23 Jan 2026 14:11:49 +0000 (09:11 -0500)
committerBryan English <bryan@rethought.computer>
Tue, 10 Feb 2026 04:08:54 +0000 (04:08 +0000)
hylo-lang/hyloc/src/riscv_asm_codegen.rs

index d90ca6b0ca043f101ffc6633717e02f3330a52b1..3f0a96ca46776271eb775d5cece5ba39dc73e702 100644 (file)
@@ -130,14 +130,14 @@ impl<'a> CodeGen<'a> {
                     self.line(format!("call {}", name));    
                 },
                 IR::Ret => {
-                    self.line("lw ra, 8(sp)");  // load return address from stack
-                    self.line("addi sp, sp, 16"); // restore stack pointer
                     if last_label == "main" {
                         // exit 0 syscall
                         self.line("li a7, 93");
                         self.line("mv a0, x0");
                         self.line("ecall");
                     } else {
+                        self.line("lw ra, 8(sp)");  // load return address from stack
+                        self.line("addi sp, sp, 16"); // restore stack pointer
                         self.line("ret");
                     }
                 },