ref: 47f1611cbac920df2a365ca4bb39612f18410ba0
parent: fa492d6d9f5addf0231506d9c8f97308152eca23
author: Ori Bernstein <[email protected]>
date: Sun May 6 15:16:23 EDT 2012
Add the func we generate as a param to reduce() We need it to do the declarations, so pass it in.
--- a/8/gen.h
+++ b/8/gen.h
@@ -66,4 +66,4 @@
Fn *mkfn(char *name);
Bb *mkbb(void);
void edge(Bb *from, Bb *to);
-Node **reduce(Node *n, int *ret_nn);
+Node **reduce(Fn *fn, Node *n, int *ret_nn);
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -24,6 +24,9 @@
Node **blk;
size_t nblk;
+ /* the function that we're reducing the body for */
+ Fn *fn;
+
/* return handling */
Node *endlbl;
Node *retval;
@@ -70,6 +73,10 @@
return mkexpr(-1, Ovar, t, NULL);
}
+void jmp(Simp *s, Node *lbl) { append(s, mkexpr(-1, Ojmp, lbl, NULL)); }
+Node *store(Node *t, Node *n) { return mkexpr(-1, Oasn, t, n, NULL); }
+Node *storetmp(Node *n) { return store(temp(n), n); }
+
void cjmp(Simp *s, Node *cond, Node *iftrue, Node *iffalse)
{
Node *jmp;
@@ -78,21 +85,6 @@
append(s, jmp);
}
-void jmp(Simp *s, Node *lbl)
-{
- append(s, mkexpr(-1, Ojmp, lbl, NULL));
-}
-
-Node *store(Node *t, Node *n)
-{
- return mkexpr(-1, Oasn, t, n, NULL);
-}
-
-Node *storetmp(Node *n)
-{
- return store(temp(n), n);
-}
-
/* if foo; bar; else baz;;
* => cjmp (foo) :bar :baz */
void simpif(Simp *s, Node *n)
@@ -249,6 +241,10 @@
return r;
}
+void declare(Simp *s, Node *n)
+{
+}
+
Node *simp(Simp *s, Node *n)
{
Node *r;
@@ -271,7 +267,7 @@
r = n;
break;
case Ndecl:
- //declare(s, n);
+ declare(s, n);
break;
case Nlbl:
append(s, n);
@@ -283,7 +279,7 @@
return r;
}
-Node **reduce(Node *n, int *ret_nn)
+Node **reduce(Fn *fn, Node *n, int *ret_nn)
{
Simp s = {0,};
@@ -290,6 +286,8 @@
s.nblk = 0;
s.endlbl = genlbl();
s.retval = NULL;
+ s.fn = fn;
+
if (n->type == Nblock)
simp(&s, n);
else
--- a/8/simp.c
+++ b/8/simp.c
@@ -68,7 +68,7 @@
fn = mkfn(name);
fn->name = strdup(name);
- nl = reduce(n->func.body, &nn);
+ nl = reduce(fn, n->func.body, &nn);
for (i = 0; i < nn; i++) {
dump(nl[i], stdout);