shithub: scc

Download patch

ref: 1f25db197b3b6fc779dbcf4ec8710f23d091ef24
parent: 3332d6ca81b8731a34a70671a2b37aa05a193935
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Aug 17 13:49:51 EDT 2016

[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.

--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -259,19 +259,12 @@
 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 *
@@ -499,7 +492,9 @@
 	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);