shithub: mc

Download patch

ref: bc29b76c63d276ec52f11d9418d57bc131840849
parent: cb0c1ccdd7525db9d777c86010dc08e7edb4820c
author: Ori Bernstein <[email protected]>
date: Mon Jul 16 08:02:27 EDT 2012

Nested functions work slightly better now.

--- a/8/asm.h
+++ b/8/asm.h
@@ -32,8 +32,8 @@
     Locmem,  /* reg offset mem */
     Locmeml, /* label offset mem */
     Loclit,  /* literal value */
-    // FIXME: later. Loclitl  /* label address */
-} LocType;
+    Loclitl  /* label address */
+} Loctype;
 
 typedef enum {
     ModeNone,
@@ -46,7 +46,7 @@
 } Mode;
 
 struct Loc {
-    LocType type;
+    Loctype type;
     Mode mode;
     union {
         char *lbl;
@@ -179,7 +179,7 @@
 Loc *locmems(long disp, Loc *base, Loc *idx, int scale, Mode mode);
 Loc *locmemls(char *disp, Loc *base, Loc *idx, int scale, Mode mode);
 Loc *loclit(long val);
-/*Loc *loclitl(char *lbl); FIXME: later */
+Loc *loclitl(char *lbl);
 
 void locprint(FILE *fd, Loc *l, char spec);
 void iprintf(FILE *fd, Insn *insn);
--- a/8/isel.c
+++ b/8/isel.c
@@ -399,7 +399,7 @@
     if (fn->type == Loclbl)
         g(s, Icall, fn, NULL);
     else
-        g(s, Icallind, inr(s, fn), NULL);
+        g(s, Icallind, fn, NULL);
     if (argsz)
         g(s, Iadd, stkbump, esp, NULL);
     return eax;
@@ -494,8 +494,12 @@
 
         case Oaddr:
             a = selexpr(s, args[0]);
-            r = locreg(ModeL);
-            g(s, Ilea, a, r, NULL);
+            if (a->type == Loclbl) {
+                r = loclitl(a->lbl);
+            } else {
+                r = locreg(ModeL);
+                g(s, Ilea, a, r, NULL);
+            }
             break;
 
         case Olnot:
@@ -580,7 +584,12 @@
 void locprint(FILE *fd, Loc *l, char spec)
 {
     switch (l->type) {
+        case Loclitl:
+            assert(spec == 'i' || spec == 'x' || spec == 'u');
+            fprintf(fd, "$%s", l->lbl);
+            break;
         case Loclbl:
+            assert(spec == 'm' || spec == 'v' || spec == 'x');
             fprintf(fd, "%s", l->lbl);
             break;
         case Locreg:
@@ -758,6 +767,7 @@
             fprintf(fd, "%c", p[i]);
         else
             fprintf(fd, "\\%x", p[i]);
+        /* line wrapping for readability */
         if (i % 60 == 59 || i == sz - 1)
             fprintf(fd, "\"\n");
     }
--- a/8/locs.c
+++ b/8/locs.c
@@ -80,6 +80,17 @@
     return l;
 }
 
+Loc *loclitl(char *lbl)
+{
+    Loc *l;
+
+    l = zalloc(sizeof(Loc));
+    l->type = Loclitl;
+    l->mode = ModeL;
+    l->lbl = strdup(lbl);
+    return l;
+}
+
 Loc *loclbl(Node *lbl)
 {
     assert(lbl->type = Nlbl);