ref: e91825e9e811a55a5d7fb72505f56cd0f32b4b4f
parent: b0ced7c8189081449ffa6073d134a53898cba89f
author: Ori Bernstein <[email protected]>
date: Mon Jun 25 14:24:25 EDT 2012
Whitespace fixes.
--- a/opt/fold.c
+++ b/opt/fold.c
@@ -18,10 +18,10 @@
Node *l;
if (exprop(n) != Olit)
- return 0;
+ return 0;
l = n->expr.args[0];
if (l->lit.littype != Lint)
- return 0;
+ return 0;
*v = l->lit.intval;
return 1;
}
@@ -31,7 +31,7 @@
vlong v;
if (!islit(n, &v))
- return 0;
+ return 0;
return v == val;
}
@@ -49,76 +49,75 @@
Node **args, *r;
vlong a, b;
size_t i;
-
- assert(n->type == Nexpr);
+ assert(n->type == Nexpr);
r = NULL;
args = n->expr.args;
if (exprop(n) != Ovar && exprop(n) != Ocjmp &&
- exprop(n) != Ojmp && exprop(n) != Olit)
- for (i = 0; i < n->expr.nargs; i++)
- args[i] = fold(args[i]);
+ exprop(n) != Ojmp && exprop(n) != Olit)
+ for (i = 0; i < n->expr.nargs; i++)
+ args[i] = fold(args[i]);
switch (exprop(n)) {
- case Ovar:
- /* FIXME: chase small consts */
- break;
- case Oadd:
- /* x + 0 = 0 */
- if (isval(args[0], 0))
- r = args[1];
- if (isval(args[1], 0))
- r = args[0];
- if (islit(args[0], &a) && islit(args[1], &b))
- r = val(n->line, a + b);
- break;
- case Osub:
- /* x - 0 = 0 */
- if (isval(args[1], 0))
- r = args[0];
- if (islit(args[0], &a) && islit(args[1], &b))
- r = val(n->line, a - b);
- break;
- case Omul:
- /* 1 * x = x */
- if (isval(args[0], 1))
- r = args[1];
- if (isval(args[1], 1))
- r = args[0];
- /* 0 * x = 0 */
- if (isval(args[0], 0))
- r = args[0];
- if (isval(args[1], 0))
- r = args[1];
- if (islit(args[0], &a) && islit(args[1], &b))
- r = val(n->line, a * b);
- break;
- case Odiv:
- /* x/1 = x */
- if (isval(args[1], 1))
- r = args[0];
- /* 0/x = 0 */
- if (isval(args[1], 0))
- r = args[1];
- if (islit(args[0], &a) && islit(args[1], &b))
- r = val(n->line, a / b);
- break;
- case Omod:
- /* x%1 = x */
- if (isval(args[1], 0))
- r = args[0];
- if (islit(args[0], &a) && islit(args[1], &b))
- r = val(n->line, a % b);
- break;
- case Oneg:
- if (islit(args[0], &a))
- r = val(n->line, -a);
- break;
- default:
- break;
+ case Ovar:
+ /* FIXME: chase small consts */
+ break;
+ case Oadd:
+ /* x + 0 = 0 */
+ if (isval(args[0], 0))
+ r = args[1];
+ if (isval(args[1], 0))
+ r = args[0];
+ if (islit(args[0], &a) && islit(args[1], &b))
+ r = val(n->line, a + b);
+ break;
+ case Osub:
+ /* x - 0 = 0 */
+ if (isval(args[1], 0))
+ r = args[0];
+ if (islit(args[0], &a) && islit(args[1], &b))
+ r = val(n->line, a - b);
+ break;
+ case Omul:
+ /* 1 * x = x */
+ if (isval(args[0], 1))
+ r = args[1];
+ if (isval(args[1], 1))
+ r = args[0];
+ /* 0 * x = 0 */
+ if (isval(args[0], 0))
+ r = args[0];
+ if (isval(args[1], 0))
+ r = args[1];
+ if (islit(args[0], &a) && islit(args[1], &b))
+ r = val(n->line, a * b);
+ break;
+ case Odiv:
+ /* x/1 = x */
+ if (isval(args[1], 1))
+ r = args[0];
+ /* 0/x = 0 */
+ if (isval(args[1], 0))
+ r = args[1];
+ if (islit(args[0], &a) && islit(args[1], &b))
+ r = val(n->line, a / b);
+ break;
+ case Omod:
+ /* x%1 = x */
+ if (isval(args[1], 0))
+ r = args[0];
+ if (islit(args[0], &a) && islit(args[1], &b))
+ r = val(n->line, a % b);
+ break;
+ case Oneg:
+ if (islit(args[0], &a))
+ r = val(n->line, -a);
+ break;
+ default:
+ break;
}
if (r)
- return r;
+ return r;
else
- return n;
+ return n;
}