shithub: scc

Download patch

ref: 8bab7047ee0b8d7c786c84f6838d9fc64be579d5
parent: a6f27269f135c7f8f4d3ce30c9e15769f7201ed9
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Nov 11 11:26:03 EST 2021

cc2: Simplify tmpnode()

It used to take a parameter to place the temporary node,
but we already saw that it was better to just use dynamic
allocation for them and the parameter didn't make sense
anymore.

--- a/src/cmd/cc/cc2/cc2.h
+++ b/src/cmd/cc/cc2/cc2.h
@@ -231,7 +231,7 @@
 extern void setlabel(Symbol *sym), getbblocks(void);
 extern Node *label2node(Node *np, Symbol *sym);
 extern Node *constnode(Node *np, TUINT n, Type *tp);
-extern Node *tmpnode(Node *, Type *);
+extern Node *tmpnode(Type *);
 extern Symbol *newlabel(void);
 extern void pprint(char *s);
 
--- a/src/cmd/cc/cc2/code.c
+++ b/src/cmd/cc/cc2/code.c
@@ -135,13 +135,13 @@
 }
 
 Node *
-tmpnode(Node *np, Type *tp)
+tmpnode(Type *tp)
 {
 	char flags;
 	Symbol *sym;
+	Node *np;
 
-	if (!np)
-		np = node(OTMP);
+	np = node(OTMP);
 	sym = getsym(TMPSYM);
 	sym->type = np->type = *tp;
 	flags = tp->flags & ~(PARF|INITF);
--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -196,7 +196,7 @@
 	if ((flags & (INTF|SIGNF)) == INTF && tp->size < 8)
 		++op;
 
-	new = tmpnode(NULL, tp);
+	new = tmpnode(tp);
 	code(op, new, np, NULL);
 
 	return new;
@@ -273,7 +273,7 @@
 		op = (td->size == 4) ? ASEXTS : ASTRUNCD;
 	}
 
-	tmp = tmpnode(NULL, td);
+	tmp = tmpnode(td);
 	code(op, tmp, np, NULL);
 
 	return tmp;
@@ -290,12 +290,12 @@
 		pars[n++] = rhs(p->left);
 
 	tp = &np->type;
-	tmp = tmpnode(NULL, tp);
+	tmp = tmpnode(tp);
 	code(ASCALL, tmp, fun, NULL);
 
 	for (q = pars; q < &pars[n]; ++q) {
 		op = (q == &pars[n-1]) ? ASPARE : ASPAR;
-		code(op, NULL, *q, tmpnode(NULL, &(*q)->type));
+		code(op, NULL, *q, tmpnode(&(*q)->type));
 	}
 	code((np->op == OCALL) ? ASCALLE : ASCALLEX, NULL, NULL, NULL);
 
@@ -401,7 +401,7 @@
 {
 	Node ifyes, ifno, phi, *colon, *tmp;
 
-	tmp = tmpnode(NULL, &np->type);
+	tmp = tmpnode(&np->type);
 	label2node(&ifyes, NULL);
 	label2node(&ifno, NULL);
 	label2node(&phi, NULL);
@@ -587,7 +587,7 @@
 		true = newlabel();
 		false = newlabel();
 		phi = label2node(&aux1, NULL);
-		tmp = tmpnode(NULL, &int32type);
+		tmp = tmpnode(&int32type);
 
 		bool(np, true, false);
 
@@ -645,7 +645,7 @@
                         abort();
                 }
 		op = tbl[np->op] + off;
-		tmp = tmpnode(NULL, tp);
+		tmp = tmpnode(tp);
 		code(op, tmp, l, r);
 		return tmp;
 	case OCALL:
@@ -680,7 +680,7 @@
 			return NULL;
 		case BVA_ARG:
 			l = rhs(l);
-			tmp = tmpnode(NULL, tp);
+			tmp = tmpnode(tp);
 			code(ASVARG, tmp, l, NULL);
 			return tmp;
 		case BVA_COPY: