[hackers] [scc] Add simplify() to all binary operators || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 23 Jul 2015 12:14:45 +0200 (CEST)

commit eb5bf586bfe6b26995bb2ca24f13eee8cfb268ca
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Jul 23 12:13:11 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Jul 23 12:13:11 2015 +0200

    Add simplify() to all binary operators

diff --git a/cc1/code.c b/cc1/code.c
index 4aa6768..b4d5092 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -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
index 8432df1..000f2d5 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -705,6 +705,7 @@ shift(void)
                 }
                 next();
                 np = integerop(op, np, add());
+ np = simplify(np);
         }
 }
 
_AT_@ -725,6 +726,7 @@ relational(void)
                 }
                 next();
                 np = compare(op, np, shift());
+ np = simplify(np);
         }
 }
 
_AT_@ -743,6 +745,7 @@ eq(void)
                 }
                 next();
                 np = compare(op, np, relational());
+ np = simplify(np);
         }
 }
 
_AT_@ -754,7 +757,7 @@ bit_and(void)
         np = eq();
         while (accept('&'))
                 np = integerop(OBAND, np, eq());
- return np;
+ return simplify(np);
 }
 
 static Node *
_AT_@ -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 *
_AT_@ -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 *
_AT_@ -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 *
_AT_@ -798,7 +801,7 @@ or(void)
         np = and();
         while (accept(OR))
                 np = logic(OOR, np, and());
- return np;
+ return simplify(np);
 }
 
 static Node *
Received on Thu Jul 23 2015 - 12:14:45 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 23 2015 - 12:24:13 CEST