[hackers] [scc/qbe] [cc2-qbe] Simplify abbrev() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 17 Aug 2016 17:55:49 +0200 (CEST)

commit d8a15f012e8b7c75c9034e7d42d9766126fb68dc
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Aug 17 17:49:51 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Aug 17 17:49:51 2016 +0200

    [cc2-qbe] Simplify abbrev()
    
    We do not need to allocate memory in abbrev, because we can use a
    temporary variable. This code came from the old qbe backend, but
    it can be done better with the new code.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 6438396..96dac16 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -259,19 +259,12 @@ call(Node *np, Node *ret)
 static Node *
 abbrev(Node *np, Node *ret)
 {
- Node *tmp;
+ Node aux;
 
- if (np->u.subop == 0)
- return np->right;
-
- tmp = newnode(np->u.subop);
- tmp->type = np->type;
- tmp->right = np->right;
- tmp->left = np->left;
- rhs(tmp, ret);
- deltree(tmp);
-
- return ret;
+ tmpnode(&aux, &np->type);
+ aux.right = np->right;
+ aux.left = np->left;
+ return rhs(&aux, ret);
 }
 
 static Node *
_AT_@ -499,7 +492,9 @@ rhs(Node *np, Node *ret)
         case OCAST:
                 return cast(tp, rhs(l, &aux1), ret);
         case OASSIG:
- r = abbrev(np, &aux1);
+ /* TODO: see what is the more difficult */
+ if (np->u.subop != 0)
+ r = abbrev(np, &aux1);
                 lhs(l, &aux2);
                 rhs(r, ret);
                 return assign(&aux2, ret);
Received on Wed Aug 17 2016 - 17:55:49 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 17 2016 - 18:00:31 CEST