commit d1b2cf2d49cad7978b7c6307a2c17cc3d34aa42c
parent 7c7a8b30ea73cc5b402dab217ad6c0a72f601072
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Mon, 12 Oct 2015 12:40:55 -0400
add super cheap constant folding in minic
Diffstat:
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/minic/minic.y b/minic/minic.y
@@ -226,13 +226,17 @@ prom(int op, Symb *l, Symb *r)
}
Scale:
- if (irtyp(r->ctyp) != 'l')
- sext(r);
sz = SIZE(DREF(l->ctyp));
- fprintf(of, "\t%%t%d =l mul %d, ", tmp, sz);
- psymb(*r);
- fprintf(of, "\n");
- r->u.n = tmp++;
+ if (r->t == Con)
+ r->u.n *= sz;
+ else {
+ if (irtyp(r->ctyp) != 'l')
+ sext(r);
+ fprintf(of, "\t%%t%d =l mul %d, ", tmp, sz);
+ psymb(*r);
+ fprintf(of, "\n");
+ r->u.n = tmp++;
+ }
return l->ctyp;
}
@@ -255,7 +259,7 @@ expr(Node *n)
['*'] = "mul",
['/'] = "div",
['%'] = "rem",
- ['<'] = "cslt", /* meeeeh, careful with pointers */
+ ['<'] = "cslt", /* meeeeh, careful with pointers/long */
['l'] = "csle",
['e'] = "ceq",
['n'] = "cne",