shithub: scc

Download patch

ref: db49af2f1032c50d3b428b7ef5bfaa7e3391572f
parent: 38da5860529e4b248b4c80d6c539e1eab5bb3bc4
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Aug 16 05:10:13 EDT 2016

[cc2-qbe] Add abbrev()

This code is directly taken and adapted from the old
cgen for qbe.

--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -210,7 +210,28 @@
 	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)
 {
 	Type *tp;
@@ -237,8 +258,6 @@
 	return from;
 }
 
-static Node *rhs(Node *np, Node *new);
-
 static Node *
 lhs(Node *np, Node *new)
 {
@@ -400,9 +419,10 @@
 	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();
 	}