shithub: scc

Download patch

ref: 2490562f2017eaf5097cfa6cd8353b986959b453
parent: d45810bfe48e161fd44f057763feef8b0ae471d6
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Nov 4 09:43:45 EDT 2021

cc2: Move tmpnode() to generic code

Tmpnode() is a generic function and it can be used in different
targets.

--- a/src/cmd/cc/cc2/cc2.h
+++ b/src/cmd/cc/cc2/cc2.h
@@ -229,6 +229,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 Symbol *newlabel(void);
 extern void pprint(char *s);
 
--- a/src/cmd/cc/cc2/code.c
+++ b/src/cmd/cc/cc2/code.c
@@ -135,6 +135,25 @@
 }
 
 Node *
+tmpnode(Node *np, Type *tp)
+{
+	char flags;
+	Symbol *sym;
+
+	if (!np)
+		np = node(OTMP);
+	sym = getsym(TMPSYM);
+	sym->type = np->type = *tp;
+	flags = tp->flags & ~(PARF|INITF);
+	sym->type.flags = np->type.flags = flags;
+	sym->kind = STMP;
+	np->left = np->right = NULL;
+	np->u.sym = sym;
+	np->op = OTMP;
+	return np;
+}
+
+Node *
 constnode(Node *np, TUINT n, Type *tp)
 {
 	if (!np)
--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -7,11 +7,6 @@
 #include "arch.h"
 #include "../../cc2.h"
 
-enum sflags {
-	ISTMP  = 1,
-	ISCONS = 2
-};
-
 static char opasmw[] = {
 	[OADD] = ASADDW,
 	[OSUB] = ASSUBW,
@@ -76,26 +71,6 @@
 };
 
 extern Type int32type, uint32type, ptrtype;
-
-static Node *
-tmpnode(Node *np, Type *tp)
-{
-	char flags;
-	Symbol *sym;
-
-	if (!np)
-		np = node(OTMP);
-	sym = getsym(TMPSYM);
-	sym->type = np->type = *tp;
-	flags = tp->flags & ~(PARF|INITF);
-	sym->type.flags = np->type.flags = flags;
-	sym->kind = STMP;
-	np->left = np->right = NULL;
-	np->u.sym = sym;
-	np->op = OTMP;
-	np->flags |= ISTMP;
-	return np;
-}
 
 static Node *
 complex(Node *np)