commit 8a8c59a63e23fd40382411d44b636bb00171718a
parent 6afeca7d7c61dc99d4074752573484662465a928
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 31 Dec 2024 10:19:29 +0100
cc2: Make delstmt() more generic
With the current form delstmt() had a very limited scope
and it only could be used in apply(). Adding a parameter
makes it more usable and it is going to be used a lot in
cfg.c.
Diffstat:
4 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/src/cmd/scc-cc/cc2/cc2.h b/src/cmd/scc-cc/cc2/cc2.h
@@ -265,7 +265,7 @@ extern void deltree(Node *np);
extern void prtree(Node *np), prforest(char *msg);
extern Node *node(int op);
extern Node *addstmt(Node *);
-extern Node *delstmt(void);
+extern Node *delstmt(Node *);
extern Node *insstmt(Node *, Node *);
extern void delrange(Node *, Node *);
extern Node *waftstmt(Node *);
diff --git a/src/cmd/scc-cc/cc2/cfg.c b/src/cmd/scc-cc/cc2/cfg.c
@@ -319,7 +319,7 @@ swtch_if(Node *idx)
break;
case ODEFAULT:
deflabel = np->u.sym;
- deltree(unlinkstmt(np));
+ delstmt(np);
break;
default:
abort();
diff --git a/src/cmd/scc-cc/cc2/node.c b/src/cmd/scc-cc/cc2/node.c
@@ -123,13 +123,13 @@ addstmt(Node *np)
}
Node *
-delstmt(void)
+delstmt(Node *np)
{
Node *next;
- next = curstmt->next;
+ next = np->next;
deltree(unlinkstmt(curstmt));
- return curstmt = next;
+ return next;
}
void
@@ -189,13 +189,8 @@ apply(Node *(*fun)(Node *))
{
Node *np;
- curstmt = curfun->u.stmt;
- while (curstmt) {
+ for (curstmt = curfun->u.stmt; curstmt; curstmt = np) {
np = (*fun)(curstmt);
- if (!np) {
- delstmt();
- } else {
- curstmt = np->next;
- }
+ np = (np) ? np->next : delstmt(curstmt);
}
}
diff --git a/src/cmd/scc-cc/cc2/qbe/cgen.c b/src/cmd/scc-cc/cc2/qbe/cgen.c
@@ -484,13 +484,12 @@ function(void)
}
static void
-swtch(Node *idx)
+swtch(Node *swt, Node *idx)
{
Node aux1, aux2, *np;
Symbol *deflabel = NULL;
- for (;;) {
- np = delstmt();
+ for (np = swt->next; ; np = np->next) {
setlabel(np->label);
switch (np->op) {
@@ -501,6 +500,7 @@ swtch(Node *idx)
aux1.label = NULL;
aux1.u.sym = deflabel;
cgen(&aux1);
+ delrange(swt->next, np);
return;
case OCASE:
aux1 = *np;
@@ -777,8 +777,7 @@ cgen(Node *np)
code(ASRET, NULL, p, NULL);
break;
case OBSWITCH:
- p = rhs(np->left);
- swtch(p);
+ swtch(np, rhs(np->left));
break;
default:
rhs(np);