ref: 1f1347b5b30a7cec94bfe58e84fef595310d2b1c
parent: a2d560c05bd359bc0d1afcd5061ce7aadfdab1c7
author: Ori Bernstein <[email protected]>
date: Mon May 7 20:39:45 EDT 2012
Make postinc work.
--- a/8/isel.c
+++ b/8/isel.c
@@ -576,9 +576,10 @@
locreg(&esp, Resp);
locreg(&ebp, Rebp);
locreg(&eax, Reax);
- ret = loc(s, s->ret);
- if (s->ret)
- g(s, Imov, &ret, &eax, NULL);
+ if (s->ret) {
+ ret = loc(s, s->ret);
+ g(s, Imov, &ret, &eax, NULL);
+ }
g(s, Imov, &ebp, &esp, NULL);
g(s, Ipop, &ebp, NULL);
g(s, Iret, NULL);
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -13,6 +13,11 @@
#include "gen.h"
#include "asm.h"
+void breakhere()
+{
+ volatile int x = 0;
+ x++;
+}
/* takes a list of nodes, and reduces it (and it's subnodes) to a list
* following these constraints:
@@ -38,6 +43,8 @@
};
Node *simp(Simp *s, Node *n);
+Node *rval(Simp *s, Node *n);
+Node *lval(Simp *s, Node *n);
void declare(Simp *s, Node *n);
void append(Simp *s, Node *n)
@@ -203,12 +210,18 @@
}
}
-Node *simpexpr(Simp *s, Node *n)
+Node *lval(Simp *s, Node *n)
{
- Node *r, *t, *v;
+ return rval(s, n);
+}
+
+Node *rval(Simp *s, Node *n)
+{
+ Node *r, *t, *u, *v;
int i;
Node **args;
const Op fusedmap[] = {
+ [Oaddeq] = Oadd,
[Osubeq] = Osub,
[Omuleq] = Omul,
[Odiveq] = Odiv,
@@ -224,7 +237,7 @@
args = n->expr.args;
switch (exprop(n)) {
case Obad:
- case Olor: case Oland: case Oaddeq:
+ case Olor: case Oland:
case Obsreq: case Omemb:
case Oslice: case Oidx: case Osize:
die("Have not implemented lowering op %s", opstr(exprop(n)));
@@ -234,10 +247,14 @@
* foo ?= blah
* =>
* foo = foo ? blah*/
- case Osubeq: case Omuleq: case Odiveq: case Omodeq: case Oboreq:
- case Obandeq: case Obxoreq: case Obsleq:
- v = mkexpr(-1, fusedmap[exprop(n)], args[0], args[1], NULL);
- r = mkexpr(-1, Oasn, args[0], v, NULL);
+ case Oaddeq: case Osubeq: case Omuleq: case Odiveq: case Omodeq:
+ case Oboreq: case Obandeq: case Obxoreq: case Obsleq:
+ breakhere();
+ assert(fusedmap[exprop(n)] != Obad);
+ u = simp(s, args[0]);
+ v = simp(s, args[1]);
+ v = mkexpr(-1, fusedmap[exprop(n)], u, v, NULL);
+ r = mkexpr(-1, Ostor, u, v, NULL);
break;
/* ++expr(x)
@@ -245,14 +262,14 @@
* expr(x) */
case Opreinc:
t = simp(s, args[0]);
- v = mkexpr(-1, Oadd, mkint(-1, 1), args[0], NULL);
- r = mkexpr(-1, Oasn, args[0], v, NULL);
+ v = mkexpr(-1, Oadd, mkint(-1, 1), t, NULL);
+ r = mkexpr(-1, Ostor, t, v, NULL);
lappend(&s->incqueue, &s->nqueue, t);
break;
case Opredec:
t = simp(s, args[0]);
- v = mkexpr(-1, Oadd, mkint(-1, -1), args[0], NULL);
- r = mkexpr(-1, Oasn, args[0], v, NULL);
+ v = mkexpr(-1, Oadd, mkint(-1, -1), t, NULL);
+ r = mkexpr(-1, Ostor, t, v, NULL);
lappend(&s->incqueue, &s->nqueue, t);
break;
@@ -264,13 +281,13 @@
case Opostinc:
r = simp(s, args[0]);
v = mkexpr(-1, Oadd, mkint(-1, 1), r, NULL);
- t = mkexpr(-1, Oasn, args[0], v, NULL);
+ t = mkexpr(-1, Ostor, r, v, NULL);
lappend(&s->incqueue, &s->nqueue, t);
break;
case Opostdec:
r = simp(s, args[0]);
- v = mkexpr(-1, Osub, mkint(-1, -1), args[0], NULL);
- t = mkexpr(-1, Oasn, args[0], v, NULL);
+ v = mkexpr(-1, Oadd, mkint(-1, -1), args[0], NULL);
+ t = mkexpr(-1, Ostor, r, v, NULL);
lappend(&s->incqueue, &s->nqueue, t);
break;
case Ovar:
@@ -287,6 +304,12 @@
}
jmp(s, s->endlbl);
break;
+ case Oasn:
+ breakhere();
+ t = rval(s, args[0]);
+ v = lval(s, args[1]);
+ r = mkexpr(-1, Ostor, r, v, NULL);
+ break;
default:
if (isimpure(n)) {
v = simp(s, n);
@@ -327,7 +350,7 @@
simploop(s, n);
break;
case Nexpr:
- r = simpexpr(s, n);
+ r = rval(s, n);
break;
case Nlit:
r = n;
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -154,12 +154,6 @@
}
}
-void breakhere()
-{
- volatile int a;
- a++;
-}
-
static Type *unify(Node *ctx, Type *a, Type *b)
{
Type *t;