scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit eb5bf586bfe6b26995bb2ca24f13eee8cfb268ca
parent 022b66c883b41558202c1e602ee98c44e8c6a146
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 23 Jul 2015 12:13:11 +0200

Add simplify() to all binary operators

Diffstat:
Mcc1/code.c | 39+++++++++++++++++++++++++++++++++++++++
Mcc1/expr.c | 13++++++++-----
2 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -425,6 +425,45 @@ simplify(Node *np) goto division_by_0; FOLDINT(sym, ls, rs, %); break; + case OSHL: + FOLDINT(sym, ls, rs, <<); + break; + case OSHR: + FOLDINT(sym, ls, rs, >>); + break; + case OLT: + FOLDINT(sym, ls, rs, <); + break; + case OGT: + FOLDINT(sym, ls, rs, >); + break; + case OGE: + FOLDINT(sym, ls, rs, >=); + break; + case OLE: + FOLDINT(sym, ls, rs, <=); + break; + case OEQ: + FOLDINT(sym, ls, rs, ==); + break; + case ONE: + FOLDINT(sym, ls, rs, !=); + break; + case OBAND: + FOLDINT(sym, ls, rs, &); + break; + case OBEXOR: + FOLDINT(sym, ls, rs, ^); + break; + case OBOR: + FOLDINT(sym, ls, rs, |); + break; + case OAND: + FOLDINT(sym, ls, rs, &&); + break; + case OOR: + FOLDINT(sym, ls, rs, ||); + break; default: abort(); } diff --git a/cc1/expr.c b/cc1/expr.c @@ -705,6 +705,7 @@ shift(void) } next(); np = integerop(op, np, add()); + np = simplify(np); } } @@ -725,6 +726,7 @@ relational(void) } next(); np = compare(op, np, shift()); + np = simplify(np); } } @@ -743,6 +745,7 @@ eq(void) } next(); np = compare(op, np, relational()); + np = simplify(np); } } @@ -754,7 +757,7 @@ bit_and(void) np = eq(); while (accept('&')) np = integerop(OBAND, np, eq()); - return np; + return simplify(np); } static Node * @@ -765,7 +768,7 @@ bit_xor(void) np = bit_and(); while (accept('^')) np = integerop(OBXOR, np, bit_and()); - return np; + return simplify(np); } static Node * @@ -776,7 +779,7 @@ bit_or(void) np = bit_xor(); while (accept('|')) np = integerop(OBOR, np, bit_xor()); - return np; + return simplify(np); } static Node * @@ -787,7 +790,7 @@ and(void) np = bit_or(); while (accept(AND)) np = logic(OAND, np, bit_or()); - return np; + return simplify(np); } static Node * @@ -798,7 +801,7 @@ or(void) np = and(); while (accept(OR)) np = logic(OOR, np, and()); - return np; + return simplify(np); } static Node *