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

From: <git_AT_suckless.org>
Date: Wed, 17 Aug 2016 14:29:50 +0200 (CEST)

commit 95f39a2d1f33854b19ff572846757860aef07ee9
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 16 09:10:13 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Aug 17 14:29:25 2016 +0200

    [cc2-qbe] Add abbrev()
    
    This code is directly taken and adapted from the old
    cgen for qbe.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 2e52dc4..9d5fe4a 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -210,6 +210,27 @@ cast(Type *td, Node *ns, Node *nd)
         return nd;
 }
 
+
+static Node *rhs(Node *np, Node *new);
+
+static Node *
+abbrev(Node *np, Node *ret)
+{
+ Node *tmp;
+
+ 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;
+}
+
 static Node *
 assign(Node *to, Node *from)
 {
_AT_@ -237,8 +258,6 @@ assign(Node *to, Node *from)
         return from;
 }
 
-static Node *rhs(Node *np, Node *new);
-
 static Node *
 lhs(Node *np, Node *new)
 {
_AT_@ -400,9 +419,10 @@ rhs(Node *np, Node *ret)
         case OCAST:
                 return cast(tp, rhs(l, &aux1), ret);
         case OASSIG:
- lhs(l, &aux1);
+ r = abbrev(np, &aux1);
+ lhs(l, &aux2);
                 rhs(r, ret);
- return assign(&aux1, ret);
+ return assign(&aux2, ret);
         default:
                 abort();
         }
Received on Wed Aug 17 2016 - 14:29:50 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 17 2016 - 14:36:39 CEST