shithub: mc

Download patch

ref: 6150817f07afc55f77f9da56baa2383fcd53d9f2
parent: 24ea01171738b8c7612074650557438521c218e2
author: Ori Bernstein <[email protected]>
date: Sat May 12 16:17:02 EDT 2012

Fix pre/postinc

--- a/8/isel.c
+++ b/8/isel.c
@@ -207,6 +207,7 @@
     Loc l;
     int i;
 
+    l.reg = Rnone;
     for (i = 0; i < Nreg; i++) {
         if (!s->rtaken[i] && regmodes[i] == m) {
             locreg(&l, i);
@@ -213,6 +214,8 @@
             break;
         }
     }
+    if (l.reg == Rnone)
+        die("Not enough registers. Please split your expression and try again (FIXME: implement spilling)");
     for (i = 0; i < Nmode; i++)
         s->rtaken[reginterferes[l.reg][i]] = 1;
 
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -212,6 +212,8 @@
     return rval(s, n);
 }
 
+static Node *one;
+
 Node *rval(Simp *s, Node *n)
 {
     Node *r, *t, *u, *v;
@@ -230,6 +232,8 @@
     };
 
 
+    if (!one)
+        one = mkexpr(-1, Olit, mkint(-1, 1), NULL);
     r = NULL;
     args = n->expr.args;
     switch (exprop(n)) {
@@ -254,17 +258,17 @@
             break;
 
         /* ++expr(x)
-         *  => x = x + 1
+         *  => args[0] = args[0] + 1
          *     expr(x) */
         case Opreinc:
-            t = rval(s, args[0]);
-            v = mkexpr(-1, Oadd, mkint(-1, 1), t, NULL);
+            t = lval(s, args[0]);
+            v = mkexpr(-1, Oadd, one, t, NULL);
             r = mkexpr(-1, Ostor, t, v, NULL);
             lappend(&s->incqueue, &s->nqueue, t); 
             break;
         case Opredec:
-            t = rval(s, args[0]);
-            v = mkexpr(-1, Oadd, mkint(-1, -1), t, NULL);
+            t = lval(s, args[0]);
+            v = mkexpr(-1, Osub, one, t, NULL);
             r = mkexpr(-1, Ostor, t, v, NULL);
             lappend(&s->incqueue, &s->nqueue, t); 
             break;
@@ -275,15 +279,14 @@
          *      x = x + 1 
          */
         case Opostinc:
-            breakhere();
-            r = rval(s, args[0]);
-            v = mkexpr(-1, Oadd, mkint(-1, 1), r, NULL);
+            r = lval(s, args[0]);
+            v = mkexpr(-1, Oadd, one, r, NULL);
             t = mkexpr(-1, Ostor, r, v, NULL);
             lappend(&s->incqueue, &s->nqueue, t); 
             break;
         case Opostdec:
-            r = rval(s, args[0]);
-            v = mkexpr(-1, Oadd, mkint(-1, -1), args[0], NULL);
+            r = lval(s, args[0]);
+            v = mkexpr(-1, Osub, one, args[0], NULL);
             t = mkexpr(-1, Ostor, r, v, NULL);
             lappend(&s->incqueue, &s->nqueue, t); 
             break;
@@ -335,7 +338,10 @@
 Node *simp(Simp *s, Node *n)
 {
     Node *r;
+    int i;
 
+    if (!n)
+        return NULL;
     r = NULL;
     switch (n->type) {
         case Nblock:
@@ -351,6 +357,12 @@
             r = rval(s, n);
             if (r)
                 append(s, r);
+            /* drain the increment queue for this expr */
+            for (i = 0; i < s->nqueue; i++)
+                append(s, s->incqueue[i]);
+            free(s->incqueue);
+            s->nqueue = 0;
+            s->incqueue = NULL;
             break;
         case Nlit:
             r = n;
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -187,7 +187,8 @@
             fprintf(fd, ")\n");
             break;
         case Nnone:
-            die("Nnone a real node type!");
+            fprintf(stderr, "Nnone not a real node type!");
+            fprintf(fd, "Nnone\n");
             break;
     }
 }
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -369,6 +369,8 @@
 {
     int i;
 
+    if (!n)
+        return;
     switch (n->type) {
         case Nfile:
             pushstab(n->file.globls);
@@ -455,6 +457,8 @@
 {
     int i;
 
+    if (!n)
+        return;
     switch (n->type) {
         case Nfile:
             for (i = 0; i < n->file.nstmts; i++)