commit ffb83304fd6f90cfa5c6f476ad6d192f3887357a
parent 653ae89fd9c4709df73f586340c8d576bdffa96d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 4 Nov 2021 13:43:45 +0100
cc2: Move tmpnode() to generic code
Tmpnode() is a generic function and it can be used in different
targets.
Diffstat:
3 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/src/cmd/cc/cc2/cc2.h b/src/cmd/cc/cc2/cc2.h
@@ -229,6 +229,7 @@ extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
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);
diff --git a/src/cmd/cc/cc2/code.c b/src/cmd/cc/cc2/code.c
@@ -135,6 +135,25 @@ label2node(Node *np, Symbol *sym)
}
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)
diff --git 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,
@@ -78,26 +73,6 @@ static char opasmd[] = {
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)
{
Node *lp = np->left, *rp = np->right;