ref: eb5bf586bfe6b26995bb2ca24f13eee8cfb268ca
parent: 022b66c883b41558202c1e602ee98c44e8c6a146
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Jul 23 08:13:11 EDT 2015
Add simplify() to all binary operators
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -425,6 +425,45 @@
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();
}
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -705,6 +705,7 @@
}
next();
np = integerop(op, np, add());
+ np = simplify(np);
}
}
@@ -725,6 +726,7 @@
}
next();
np = compare(op, np, shift());
+ np = simplify(np);
}
}
@@ -743,6 +745,7 @@
}
next();
np = compare(op, np, relational());
+ np = simplify(np);
}
}
@@ -754,7 +757,7 @@
np = eq();
while (accept('&'))
np = integerop(OBAND, np, eq());
- return np;
+ return simplify(np);
}
static Node *
@@ -765,7 +768,7 @@
np = bit_and();
while (accept('^'))
np = integerop(OBXOR, np, bit_and());
- return np;
+ return simplify(np);
}
static Node *
@@ -776,7 +779,7 @@
np = bit_xor();
while (accept('|'))
np = integerop(OBOR, np, bit_xor());
- return np;
+ return simplify(np);
}
static Node *
@@ -787,7 +790,7 @@
np = bit_or();
while (accept(AND))
np = logic(OAND, np, bit_or());
- return np;
+ return simplify(np);
}
static Node *
@@ -798,7 +801,7 @@
np = and();
while (accept(OR))
np = logic(OOR, np, and());
- return np;
+ return simplify(np);
}
static Node *