scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 7efbe8681cbdbfe860296e32fa771f8d204757c1
parent 6c203246f0b7e3fa9ac8748b14e50e4381928d1a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 26 Dec 2024 22:09:09 +0100

cc2: Add a reference counter to symbols

This makes easy to detect labels not used for any jump
or branch.

Diffstat:
Msrc/cmd/scc-cc/cc2/cc2.h | 1+
Msrc/cmd/scc-cc/cc2/parser.c | 5++++-
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/cmd/scc-cc/cc2/cc2.h b/src/cmd/scc-cc/cc2/cc2.h @@ -165,6 +165,7 @@ struct symbol { Type rtype; unsigned short id; unsigned short numid; + int refcnt; char *name; char kind; union { diff --git a/src/cmd/scc-cc/cc2/parser.c b/src/cmd/scc-cc/cc2/parser.c @@ -413,6 +413,7 @@ ocase(char *token, union tokenop u) static void jump(char *token, union tokenop u) { + Symbol *label; Node *aux, *np = node(u.op); eval(strtok(NULL, "\t\n")); @@ -420,7 +421,9 @@ jump(char *token, union tokenop u) if (u.op == OBRANCH || u.op == OCASE) np->left = pop(); aux = pop(); - np->u.sym = aux->u.sym; + label = aux->u.sym; + label->refcnt++; + np->u.sym = label; delnode(aux); push(np); }