[hackers] [scc] Simplify expression like *& or &* || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 26 Aug 2015 22:32:48 +0200 (CEST)

commit 79ccb978a8d4f8c9c9700bb16d2b97625f3f1dd4
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Aug 26 22:25:35 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Aug 26 22:25:35 2015 +0200

    Simplify expression like *& or &*
    
    This kind of expressions are common in array expressions
    and the can simplify a lot the IR generated.

diff --git a/cc1/expr.c b/cc1/expr.c
index 7414c00..5f22825 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -358,6 +358,12 @@ decay(Node *np)
         switch (tp->op) {
         case ARY:
                 tp = tp->type;
+ if (np->op == OPTR) {
+ Node *new = np->left;
+ free(np);
+ new->type = mktype(tp, PTR, 0, NULL);
+ return new;
+ }
         case FTN:
                 break;
         default:
_AT_@ -539,14 +545,16 @@ parithmetic(char op, Node *lp, Node *rp)
         }
         if (BTYPE(rp) != INT)
                 goto incorrect;
+
         rp = convert(promote(rp), sizettype, 0);
- rp = node(OMUL, sizettype, rp, size);
- rp = node(OCAST, tp, rp, NULL);
+ rp = simplify(OMUL, sizettype, rp, size);
+ rp = convert(rp, tp, 1);
 
- return node(OADD, tp, lp, rp);
+ return simplify(OADD, tp, lp, rp);
 
 incorrect:
- error("incorrect arithmetic operands");
+ errorp("incorrect arithmetic operands");
+ return node(OADD, tp, lp, rp);
 }
 
 static Node *
_AT_@ -752,6 +760,11 @@ address(char op, Node *np)
                 error("lvalue required in unary expression");
         if (np->symbol && (np->sym->flags & ISREGISTER))
                 error("address of register variable '%s' requested", yytext);
+ if (np->op == OPTR) {
+ Node *new = np->left;
+ free(np);
+ return new;
+ }
         return node(op, mktype(np->type, PTR, 0, NULL), np, NULL);
 }
 
_AT_@ -761,8 +774,12 @@ content(char op, Node *np)
         switch (BTYPE(np)) {
         case ARY:
         case FTN:
- np = decay(np);
         case PTR:
+ if (np->op == OADDR) {
+ Node *new = np->left;
+ free(np);
+ return new;
+ }
                 np = node(op, np->type->type, np, NULL);
                 np->lvalue = 1;
                 return np;
Received on Wed Aug 26 2015 - 22:32:48 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 26 2015 - 22:36:22 CEST