shithub: mc

Download patch

ref: 31102d1a19b83d92de219c0f2d986694d34c8b53
parent: 53fab201a6702a0e017527eff6f0caedfc01204e
author: Ori Bernstein <[email protected]>
date: Mon May 7 10:27:42 EDT 2012

Load the return value into the return register.

    We never did this in the epilogue. That's a bad thing.

--- a/8/Makefile
+++ b/8/Makefile
@@ -8,8 +8,5 @@
 LDFLAGS+=-L../parse -lparse
 EXTRADEP=../parse/libparse.a
 
-../libparse.a:
-	make -C ../parse
-
 include ../mk/lexyacc.mk
 include ../mk/c.mk
--- a/8/gen.h
+++ b/8/gen.h
@@ -20,10 +20,11 @@
 struct Fn {
     char *name; /* assembly name; mangled */
     int isglobl;
-    
+
     /* filled in by the lowering process */
     size_t stksz;
     Htab *locs;
+    Node *ret;
 
     Htab *bbnames; /* char* => Bb* map */
     Bb *start;
--- a/8/isel.c
+++ b/8/isel.c
@@ -19,6 +19,7 @@
 struct Isel {
     Insn **il;
     size_t ni;
+    Node *ret;
     Htab *locs; /* Node => int stkoff */
 };
 
@@ -502,13 +503,15 @@
 
 void epilogue(Isel *s)
 {
-    Loc esp;
-    Loc ebp;
-    Loc stksz;
+    Loc esp, ebp, eax;
+    Loc ret;
 
     locreg(&esp, Resp);
     locreg(&ebp, Rebp);
-    loclit(&stksz, 16);
+    locreg(&eax, Reax);
+    ret = loc(s, s->ret);
+    if (s->ret)
+      g(s, Imov, &ret, &eax, NULL);
     g(s, Imov, &ebp, &esp, NULL);
     g(s, Ipop, &ebp, NULL);
 }
@@ -522,6 +525,7 @@
     int i;
 
     is.locs = fn->locs;
+    is.ret = fn->ret;
 
     prologue(&is, fn->stksz);
     for (i = 0; i < fn->nn; i++)
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -278,7 +278,11 @@
             break;
         case Oret:
             if (n->expr.args[0]) {
-                t = storetmp(s, simp(s, n->expr.args[0]));
+                if (s->fn->ret)
+                    t = s->fn->ret;
+                else
+                    t = s->fn->ret = temp(s, args[0]);
+                t = store(t, simp(s, args[0]));
                 append(s, t);
             }
             jmp(s, s->endlbl);