ref: e084f0b744935182770b34045d72edc6f5e91048
parent: bfa86d22fdc7b22fa4bc2819d4aa928acfac5168
author: Ori Bernstein <[email protected]>
date: Sat Jun 30 06:57:27 EDT 2012
Make checking sub-union members work.
--- a/8/insns.def
+++ b/8/insns.def
@@ -44,12 +44,12 @@
Insn(Ipop, "\tpop%t %r\n", Use(.l={1}), Def())
/* branch instructions */
-Insn(Isetz, "\tsetz %v\n", Use(), Def(.l={2}))
-Insn(Isetnz, "\tsetnz %v\n", Use(), Def(.l={2}))
-Insn(Isetlt, "\tsetlt %v\n", Use(), Def(.l={2}))
-Insn(Isetle, "\tsetle %v\n", Use(), Def(.l={2}))
-Insn(Isetgt, "\tsetgt %v\n", Use(), Def(.l={2}))
-Insn(Isetge, "\tsetge %v\n", Use(), Def(.l={2}))
+Insn(Isetz, "\tsetz %v\n", Use(), Def(.l={1}))
+Insn(Isetnz, "\tsetnz %v\n", Use(), Def(.l={1}))
+Insn(Isetlt, "\tsetlt %v\n", Use(), Def(.l={1}))
+Insn(Isetle, "\tsetle %v\n", Use(), Def(.l={1}))
+Insn(Isetgt, "\tsetgt %v\n", Use(), Def(.l={1}))
+Insn(Isetge, "\tsetge %v\n", Use(), Def(.l={1}))
/* branch instructions */
Insn(Icall, "\tcall %v\n", Use(.l={1}), Def())
--- a/8/simp.c
+++ b/8/simp.c
@@ -358,27 +358,49 @@
simp(s, lend); /* exit */
}
-static Node *uconid(Node *n)
+static Ucon *finducon(Node *n)
{
size_t i;
- Ucon *uc;
Type *t;
+ Ucon *uc;
t = tybase(n->expr.type);
if (exprop(n) != Ocons)
- return load(addr(n, tyword));
-
+ return NULL;
for (i = 0; i < t->nmemb; i++) {
uc = t->udecls[i];
if (!strcmp(namestr(uc->name), namestr(n->expr.args[0])))
- return mkintlit(uc->line, uc->id);
+ return uc;
}
+ die("No ucon?!?");
return NULL;
}
+static Node *uconid(Node *n)
+{
+ Ucon *uc;
+ Type *t;
+
+ t = tybase(n->expr.type);
+ if (exprop(n) != Ocons)
+ return load(addr(n, tyword));
+
+ uc = finducon(n);
+ return mkintlit(uc->line, uc->id);
+}
+
+static Node *uval(Node *n)
+{
+ if (exprop(n) == Ocons)
+ return n->expr.args[1];
+ else
+ return load(add(addr(n, tyword), wordsz));
+}
+
static Node *compare(Simp *s, Node *a, Node *b)
{
Node *r, *v, *x, *y;
+ Ucon *uc;
Type *t;
assert(a->type == Nexpr);
@@ -397,15 +419,21 @@
case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint:
case Typtr: case Tyfunc:
r = mkexpr(a->line, Oeq, a, b, NULL);
+ r->expr.type = tyword;
break;
case Tyunion:
x = uconid(a);
y = uconid(b);
+ uc = finducon(a);
+ if (!uc)
+ uc = finducon(b);
r = mkexpr(a->line, Oeq, x, y, NULL);
- if (a->expr.nargs == 2) {
- v = compare(s, a->expr.args[1], b->expr.args[1]);
+ r->expr.type = tyword;
+ if (uc->etype) {
+ v = compare(s, uval(a), uval(b));
r = mkexpr(a->line, Oland, r, v, NULL);
+ r->expr.type = tyword;
r = rval(s, r); /* Oandl needs to be reduced */
}
break;