From dcebd8a1b4c2f89ce779797bf5ba8d298fa8596c Mon Sep 17 00:00:00 2001
From: Ting-Wei Lan <lantw44@gmail.com>
Date: Sun, 3 Jan 2016 05:47:24 +0800
Subject: Temporarily workaround the wrong return label

---
 src/code-generation.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'src/code-generation.c')

diff --git a/src/code-generation.c b/src/code-generation.c
index c9067c4..16b3dde 100644
--- a/src/code-generation.c
+++ b/src/code-generation.c
@@ -634,6 +634,16 @@ static void generate_statement(
                         state, current_offset, "w0");
                     if (func_type == CCMMC_AST_VALUE_FLOAT)
                         fputs("\tfmov\ts0, w0\n", state->asm_output);
+                    // XXX: We should fix the location of the return label
+                    // instead of copying code and modifying sp here.
+                    if (safe_immediate(current_offset)) {
+                        fprintf(state->asm_output, "\tadd\tsp, sp, #%" PRIu64 "\n",
+                            current_offset);
+                    } else {
+                        fprintf(state->asm_output,
+                            "\tldr\t%s, =%" PRIu64 "\n"
+                            "\tadd\tsp, sp, %s\n", "x9", current_offset, "x9");
+                    }
                     fprintf(state->asm_output, "\tb\t.LR_%s\n", func_name);
                     break;
                 }
-- 
cgit