summaryrefslogtreecommitdiff
path: root/opt
diff options
context:
space:
mode:
authorOri Bernstein <orib@google.com>2012-06-25 18:24:25 -0400
committerOri Bernstein <orib@google.com>2012-06-25 18:24:25 -0400
commite91825e9e811a55a5d7fb72505f56cd0f32b4b4f (patch)
treeec3ee88812b639fbced6b61c7d02b64aea8014d0 /opt
parentb0ced7c8189081449ffa6073d134a53898cba89f (diff)
downloadmc-e91825e9e811a55a5d7fb72505f56cd0f32b4b4f.tar.gz
Whitespace fixes.
Diffstat (limited to 'opt')
-rw-r--r--opt/fold.c131
1 files changed, 65 insertions, 66 deletions
diff --git a/opt/fold.c b/opt/fold.c
index 99f0d31..0dc5dea 100644
--- a/opt/fold.c
+++ b/opt/fold.c
@@ -18,10 +18,10 @@ static int islit(Node *n, vlong *v)
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 @@ static int isval(Node *n, vlong val)
vlong v;
if (!islit(n, &v))
- return 0;
+ return 0;
return v == val;
}
@@ -49,76 +49,75 @@ Node *fold(Node *n)
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;
}