ref: 80ade912fa6ecf863d0f36ebc8fd3c999b45746e
parent: 91d7d2a303319f8a0fd2d2be1426bf4b03590bf0
author: Ori Bernstein <ori@eigenstate.org>
date: Wed May 6 19:41:16 EDT 2015
More work towards getting undefined variables to be defined.
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -79,6 +79,7 @@
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);
--- a/6/simp.c
+++ b/6/simp.c
@@ -1276,6 +1276,9 @@
/* 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 @@
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);
--- a/bench/Makefile
+++ b/bench/Makefile
@@ -17,6 +17,6 @@
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
--- a/bench/mandelbrot.myr
+++ b/bench/mandelbrot.myr
@@ -30,6 +30,7 @@
-> 0
;;
;;
+ -> 0
}
const main = {args : byte[:][:]
--- a/mi/dfcheck.c
+++ b/mi/dfcheck.c
@@ -44,6 +44,7 @@
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 @@
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 @@
default:
checkdefined(n, def);
}
- nodedef(n, def);
}
}
@@ -116,7 +129,7 @@
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 @@
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 @@
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 @@
void check(Cfg *cfg)
{
checkret(cfg);
- if (0) /* Not quite ready yet. */
+ if (0)
checkreach(cfg);
}
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -297,6 +297,7 @@
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]);
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -327,6 +327,7 @@
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 @@
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);