aboutsummaryrefslogtreecommitdiff
path: root/fold.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <[email protected]>2017-02-21 16:45:20 -0500
committerQuentin Carbonneaux <[email protected]>2017-02-22 12:48:04 -0500
commiteebbb69291369c3188064d6c3cb779bc47e09bbe (patch)
treec06473a6f06bbaccc87a1171eab93d8206c4a26b /fold.c
parenta940cc808e12659ff307294492ec6152c67fb471 (diff)
do not err on address comparisons
While I was at it I also refreshed some bits in the instruction selection.
Diffstat (limited to 'fold.c')
-rw-r--r--fold.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/fold.c b/fold.c
index 0cbd6fa..6129421 100644
--- a/fold.c
+++ b/fold.c
@@ -323,7 +323,7 @@ fold(Fn *fn)
/* boring folding code */
-static void
+static int
foldint(Con *res, int op, int w, Con *cl, Con *cr)
{
union {
@@ -357,8 +357,11 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr)
else if (cr->type == CAddr)
err("undefined substraction (num - addr)");
}
- else if (cl->type == CAddr || cr->type == CAddr)
+ else if (cl->type == CAddr || cr->type == CAddr) {
+ if (Ocmpl <= op && op <= Ocmpl1)
+ return 1;
err("invalid address operand for '%s'", opdesc[op].name);
+ }
switch (op) {
case Oadd: x = l.u + r.u; break;
case Osub: x = l.u - r.u; break;
@@ -440,6 +443,7 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr)
res->bits.i = x;
if (lab)
strcpy(res->label, lab);
+ return 0;
}
static void
@@ -492,9 +496,10 @@ opfold(int op, int cls, Con *cl, Con *cr, Fn *fn)
if ((op == Odiv || op == Oudiv
|| op == Orem || op == Ourem) && czero(cr, KWIDE(cls)))
err("null divisor in '%s'", opdesc[op].name);
- if (cls == Kw || cls == Kl)
- foldint(&c, op, cls == Kl, cl, cr);
- else
+ if (cls == Kw || cls == Kl) {
+ if (foldint(&c, op, cls == Kl, cl, cr))
+ return Bot;
+ } else
foldflt(&c, op, cls == Kd, cl, cr);
if (c.type == CBits)
nc = getcon(c.bits.i, fn).val;