shithub: scc

Download patch

ref: 61425722b9d96bd86e4c7405379f8cc1250669f0
parent: 136ad2f9afe68307b2056a256b319cb292017c3c
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Oct 3 09:39:43 EDT 2016

[cc2-qbe] Improve generation of or/and

Cgen() was calling rhs() to generate the code of the conditions
in branches, but it is better to call to log(), because it
already handles the case of having an expression.

--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -602,34 +602,30 @@
 Node *
 cgen(Node *np)
 {
-	Node ret, aux1, aux2, *p, *next, ifyes, ifno;
+	Node aux, *p, *next;
 
 	setlabel(np->label);
 	switch (np->op) {
 	case OJMP:
-		label2node(&ifyes, np->u.sym);
-		code(ASJMP, NULL, &ifyes, NULL);
+		label2node(&aux, np->u.sym);
+		code(ASJMP, NULL, &aux, NULL);
 		break;
 	case OBRANCH:
 		next = np->next;
 		if (!next->label)
 			next->label = newlabel();
-
-		label2node(&ifyes, np->u.sym);
-		label2node(&ifno, next->label);
-		rhs(np->left, &ret);
-		code(ASBRANCH, &ret, &ifyes, &ifno);
+		bool(np->left, np->u.sym, next->label);
 		break;
 	case ORET:
-		p = (np->left) ? rhs(np->left, &ret) : NULL;
+		p = (np->left) ? rhs(np->left, &aux) : NULL;
 		code(ASRET, NULL, p, NULL);
 		break;
 	case OBSWITCH:
-		p = rhs(np->left, &ret);
+		p = rhs(np->left, &aux);
 		swtch_if(p);
 		break;
 	default:
-		rhs(np, &ret);
+		rhs(np, &aux);
 		break;
 	}
 	return NULL;