summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-05-06 23:41:16 -0700
committerOri Bernstein <ori@eigenstate.org>2015-05-06 23:41:16 -0700
commitfb2f85ca9b8e7033d6d7190ecc59b0120f246830 (patch)
treeee6c3372a32e5a458d06c70207237d612621b024
parent535af2de79e234b615a2c6e758d778a3639bfc21 (diff)
downloadmc-fb2f85ca9b8e7033d6d7190ecc59b0120f246830.tar.gz
More work towards getting undefined variables to be defined.
-rw-r--r--6/gengas.c1
-rw-r--r--6/simp.c5
-rw-r--r--bench/Makefile2
-rw-r--r--bench/mandelbrot.myr1
-rw-r--r--mi/dfcheck.c38
-rw-r--r--parse/gram.y1
-rw-r--r--parse/specialize.c2
7 files changed, 44 insertions, 6 deletions
diff --git a/6/gengas.c b/6/gengas.c
index a2b709e..16f29a4 100644
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -79,6 +79,7 @@ static void initconsts(Htab *globls)
dcl = mkdecl(Zloc, name, ty);
dcl->decl.isconst = 1;
dcl->decl.isextern = 1;
+ dcl->decl.isglobl = 1;
htput(globls, dcl, asmname(dcl));
abortoob = mkexpr(Zloc, Ovar, name, NULL);
diff --git a/6/simp.c b/6/simp.c
index 333902e..6578a88 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -1276,6 +1276,9 @@ static void addvatype(Simp *s, Node *n)
/* make the decl */
tn = mkname(Zloc, tydescid(buf, sizeof buf, vt));
td = mkdecl(Zloc, tn, mktype(n->loc, Tybyte));
+ td->decl.isglobl = 1;
+ td->decl.isconst = 1;
+ td->decl.ishidden = 1;
/* and the var */
ti = mkexpr(Zloc, Ovar, tn, NULL);
@@ -1283,7 +1286,7 @@ static void addvatype(Simp *s, Node *n)
ti->expr.did = td->decl.did;
/* and the pointer */
- tp = mkexpr(Zloc, Oaddr, ti);
+ tp = mkexpr(Zloc, Oaddr, ti, NULL);
tp->expr.type = mktyptr(n->loc, td->decl.type);
linsert(&n->expr.args, &n->expr.nargs, ft->nsub - 1, tp);
diff --git a/bench/Makefile b/bench/Makefile
index c54922f..362a3db 100644
--- a/bench/Makefile
+++ b/bench/Makefile
@@ -17,6 +17,6 @@ bench: runner cleanbuild
cleanbuild:
rm -f $(BENCHSRC:.myr=) $(BENCHSRC:.myr=.o) $(BENCHSRC:.myr=.use)
@for i in $(BENCHSRC:.myr=); do \
- ../myrbuild/myrbuild -b $$i -C../6/6m -M../muse/muse -I../libstd -r../rt/_myrrt.o $$i.myr; \
+ ../mbld/mbld -b $$i -C../6/6m -M../muse/muse -I../libstd -r../rt/_myrrt.o $$i.myr; \
done
diff --git a/bench/mandelbrot.myr b/bench/mandelbrot.myr
index c97176d..cf75fda 100644
--- a/bench/mandelbrot.myr
+++ b/bench/mandelbrot.myr
@@ -30,6 +30,7 @@ const mandelbrot = {x, y
-> 0
;;
;;
+ -> 0
}
const main = {args : byte[:][:]
diff --git a/mi/dfcheck.c b/mi/dfcheck.c
index 51df9a8..9fd4ee3 100644
--- a/mi/dfcheck.c
+++ b/mi/dfcheck.c
@@ -44,6 +44,7 @@ void nodedef(Node *n, Bitset *bs)
case Obxoreq: case Obsleq:
case Obsreq:
nodevars(n->expr.args[0], bs);
+ nodedef(n->expr.args[1], bs);
break;
/* for the sake of less noise: assume that f(&var) inits the var. */
case Ocall:
@@ -88,6 +89,19 @@ static void checkuse(Bb *bb, Bitset *def)
return;
for (i = 0; i < bb->nnl; i++) {
n = bb->nl[i];
+ /* Tradeoff.
+ *
+ * We could check after, and get slightly more accurate checking,
+ * but then we error on things like:
+ * init(&foo);
+ *
+ * We can check before, but then we don't error on things like:
+ * x = f(x)
+ *
+ * Eventually we should check both ways. Right now, I want to get
+ * something working.
+ */
+ nodedef(n, def);
switch(exprop(n)) {
case Oset:
case Oasn:
@@ -96,7 +110,6 @@ static void checkuse(Bb *bb, Bitset *def)
default:
checkdefined(n, def);
}
- nodedef(n, def);
}
}
@@ -116,7 +129,7 @@ static Bitset *indef(Cfg *cfg, Bb *bb, Bitset **outdef)
Bitset *def;
j = 0;
- if (!bsiter(bb->pred, &j))
+ if (!bb || !bsiter(bb->pred, &j))
return mkbs();
def = bsdup(outdef[j]);
for (; bsiter(bb->pred, &j); j++)
@@ -124,6 +137,23 @@ static Bitset *indef(Cfg *cfg, Bb *bb, Bitset **outdef)
return def;
}
+static void addargs(Cfg *cfg, Bitset *def)
+{
+ Node *n;
+ size_t i;
+
+ n = cfg->fn;
+ assert(n->type == Ndecl);
+ n = n->decl.init;
+ assert(n->type == Nexpr);
+ n = n->expr.args[0];
+ assert(n->type == Nlit);
+ n = n->lit.fnval;
+
+ for (i = 0; i < n->func.nargs; i++)
+ bsput(def,n->func.args[i]->decl.did);
+}
+
static void checkreach(Cfg *cfg)
{
Bitset **outdef;
@@ -140,8 +170,8 @@ static void checkreach(Cfg *cfg)
outdef[i] = mkbs();
bbdef(cfg->bb[i], outdef[i]);
}
+ addargs(cfg, outdef[cfg->start->id]);
- dumpcfg(cfg, stdout);
for (i = 0; i < cfg->nbb; i++)
for (j= 0; bsiter(outdef[i], &j); j++)
printf("bb %zd defines %s\n", i, declname(decls[j]));
@@ -209,6 +239,6 @@ static void checkret(Cfg *cfg)
void check(Cfg *cfg)
{
checkret(cfg);
- if (0) /* Not quite ready yet. */
+ if (0)
checkreach(cfg);
}
diff --git a/parse/gram.y b/parse/gram.y
index 8190e9c..47f3f0a 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -297,6 +297,7 @@ pkgitem : decl {
size_t i;
for (i = 0; i < $1.nn; i++) {
$1.nl[i]->decl.vis = Visexport;
+ $1.nl[i]->decl.isglobl = 1;
putdcl(file->file.globls, $1.nl[i]);
if ($1.nl[i]->decl.init)
lappend(&file->file.stmts, &file->file.nstmts, $1.nl[i]);
diff --git a/parse/specialize.c b/parse/specialize.c
index 4cb38a0..6cf5aa9 100644
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -327,6 +327,7 @@ static Node *specializenode(Node *n, Htab *tsmap)
r->decl.isconst = n->decl.isconst;
r->decl.isgeneric = n->decl.isgeneric;
r->decl.isextern = n->decl.isextern;
+ r->decl.isglobl = n->decl.isglobl;
if (curstab())
putdcl(curstab(), r);
@@ -418,6 +419,7 @@ Node *specializedcl(Node *g, Type *to, Node **name)
d = mkdecl(g->loc, n, tysubst(g->decl.type, tsmap));
d->decl.isconst = g->decl.isconst;
d->decl.isextern = g->decl.isextern;
+ d->decl.isglobl = g->decl.isglobl;
d->decl.init = specializenode(g->decl.init, tsmap);
putdcl(st, d);