commit 95f39a2d1f33854b19ff572846757860aef07ee9
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Aug 16 09:10:13 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
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
@@ -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)
 {
@@ -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)
 {
@@ -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();
        }

Reply via email to