summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-05-07 22:28:08 -0700
committerOri Bernstein <ori@eigenstate.org>2015-05-07 22:28:08 -0700
commit3623ee59e2c80fe5a5334f3e52499295b510f026 (patch)
tree559c759ae35a20b3e4149659dfcfbc595009e297
parent6a8faed320bdd72e0ca316ee4f780ed25bf141ae (diff)
downloadmc-3623ee59e2c80fe5a5334f3e52499295b510f026.tar.gz
Add 'undef' operator.
Marks values as undefined, useful for reaching defn dummy analysis.
-rw-r--r--6/isel.c1
-rw-r--r--6/simp.c17
-rw-r--r--parse/infer.c31
-rw-r--r--parse/ops.def3
4 files changed, 30 insertions, 22 deletions
diff --git a/6/isel.c b/6/isel.c
index 42d94c9..5e5e90f 100644
--- a/6/isel.c
+++ b/6/isel.c
@@ -777,6 +777,7 @@ Loc *selexpr(Isel *s, Node *n)
g(s, Icvttss2sd, a, r, NULL);
break;
case Odead:
+ case Oundef:
/* nothing */
break;
diff --git a/6/simp.c b/6/simp.c
index 6578a88..eb64414 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -1518,6 +1518,9 @@ static Node *rval(Simp *s, Node *n, Node *dst)
case Ogt: case Oge: case Olt: case Ole:
r = compare(s, n, 0);
break;
+ case Obad:
+ die("bad operator");
+ break;
default:
if (istyfloat(exprtype(n))) {
switch (exprop(n)) {
@@ -1530,9 +1533,6 @@ static Node *rval(Simp *s, Node *n, Node *dst)
}
r = visit(s, n);
break;
- case Obad:
- die("bad operator");
- break;
}
return r;
}
@@ -1587,11 +1587,14 @@ static Node *simp(Simp *s, Node *n)
case Ndecl:
declarelocal(s, n);
- if (!n->decl.init)
- break;
t = mkexpr(n->loc, Ovar, n->decl.name, NULL);
- u = mkexpr(n->loc, Oasn, t, n->decl.init, NULL);
- u->expr.type = n->decl.type;
+ if (!n->decl.init) {
+ u = mkexpr(n->loc, Oundef, t, NULL);
+ u->expr.type = mktype(n->loc, Tyvoid);
+ } else {
+ u = mkexpr(n->loc, Oasn, t, n->decl.init, NULL);
+ u->expr.type = n->decl.type;
+ }
t->expr.type = n->decl.type;
t->expr.did = n->decl.did;
simp(s, u);
diff --git a/parse/infer.c b/parse/infer.c
index 477c1fb..aa840a0 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -517,19 +517,21 @@ static void settype(Inferstate *st, Node *n, Type *t)
/* Gets the type of a literal value */
static Type *littype(Node *n)
{
- if (n->lit.type)
- return n->lit.type;
- switch (n->lit.littype) {
- case Lchr: return mktype(n->loc, Tychar); break;
- case Lbool: return mktype(n->loc, Tybool); break;
- case Lint: return mktylike(n->loc, Tyint); break;
- case Lflt: return mktylike(n->loc, Tyflt64); break;
- case Lstr: return mktyslice(n->loc, mktype(n->loc, Tybyte)); break;
- case Llbl: return mktyptr(n->loc, mktype(n->loc, Tyvoid)); break;
- case Lfunc: return n->lit.fnval->func.type; break;
- };
- die("Bad lit type %d", n->lit.littype);
- return NULL;
+ Type *t;
+
+ if (!n->lit.type) {
+ switch (n->lit.littype) {
+ case Lchr: t = mktype(n->loc, Tychar); break;
+ case Lbool: t = mktype(n->loc, Tybool); break;
+ case Lint: t = mktylike(n->loc, Tyint); break;
+ case Lflt: t = mktylike(n->loc, Tyflt64); break;
+ case Lstr: t = mktyslice(n->loc, mktype(n->loc, Tybyte)); break;
+ case Llbl: t = mktyptr(n->loc, mktype(n->loc, Tyvoid)); break;
+ case Lfunc: t = n->lit.fnval->func.type; break;
+ }
+ n->lit.type = t;
+ }
+ return n->lit.type;
}
static Type *delayeducon(Inferstate *st, Type *fallback)
@@ -1446,7 +1448,8 @@ static void inferexpr(Inferstate *st, Node **np, Type *ret, int *sawret)
}
settype(st, n, type(st, args[0]));
break;
- case Obad: case Ocjmp: case Ojtab: case Oset: case Odead:
+ case Obad: case Ocjmp: case Ojtab: case Oset:
+ case Odead: case Oundef:
case Oslbase: case Osllen: case Outag:
case Oblit: case Oclear: case Oudata:
case Otrunc: case Oswiden: case Ozwiden:
diff --git a/parse/ops.def b/parse/ops.def
index fac46a3..9b8de94 100644
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -56,7 +56,8 @@ O(Ostruct, 1, OTmisc, NULL)
O(Oarr, 1, OTmisc, NULL)
/* all below this point are backend-only */
-O(Odead, 0, OTmisc, "DEAD") /* code */
+O(Odead, 0, OTmisc, "DEAD") /* dead code */
+O(Oundef, 0, OTmisc, "UNDEF") /* undefined var */
O(Ocjmp, 1, OTmisc, "CJMP") /* conditional jump */
O(Ojtab, 1, OTmisc, "JTAB") /* jump table */
O(Oset, 1, OTbin, "=") /* store to var */