ref: 6cf64ac765264c305b91b3062ef8e3525e83add5
parent: b9b8f61c838c2a384ead451f70de9d30a97526d0
author: Ori Bernstein <ori@eigenstate.org>
date: Thu May 7 18:28:08 EDT 2015
Add 'undef' operator. Marks values as undefined, useful for reaching defn dummy analysis.
--- a/6/isel.c
+++ b/6/isel.c
@@ -777,6 +777,7 @@
g(s, Icvttss2sd, a, r, NULL);
break;
case Odead:
+ case Oundef:
/* nothing */
break;
--- a/6/simp.c
+++ b/6/simp.c
@@ -1518,6 +1518,9 @@
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 @@
}
r = visit(s, n);
break;
- case Obad:
- die("bad operator");
- break;
}
return r;
}
@@ -1587,11 +1587,14 @@
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);
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -517,19 +517,21 @@
/* 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 @@
}
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:
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -56,7 +56,8 @@
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 */