scc

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

commit 199aaf23b5da8b9c77351d861fa37aa3f4f172e6
parent 5961728fea60e49b60b03fa3810cd18bc9ade20a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 27 Dec 2024 13:03:15 +0100

cc2: Do not expose sethi()

Using apply() in the main loop makes it a bit harder to
read and it imposes how to implement some high level
functionality and for that reason is better to hide sethi()
and use a genaddr() function that almost all the implementations
will implement using apply().

Diffstat:
Msrc/cmd/scc-cc/cc2/amd64-sysv/cgen.c | 4++--
Msrc/cmd/scc-cc/cc2/cc2.h | 2+-
Msrc/cmd/scc-cc/cc2/i386-sysv/cgen.c | 4++--
Msrc/cmd/scc-cc/cc2/main.c | 2+-
Msrc/cmd/scc-cc/cc2/qbe/cgen.c | 8+++++++-
Msrc/cmd/scc-cc/cc2/z80-scc/cgen.c | 20+++++++++++++-------
6 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/src/cmd/scc-cc/cc2/amd64-sysv/cgen.c b/src/cmd/scc-cc/cc2/amd64-sysv/cgen.c @@ -7,7 +7,7 @@ genasm(void) { } -Node * -sethi(Node *np) +void +genaddr(void) { } diff --git a/src/cmd/scc-cc/cc2/cc2.h b/src/cmd/scc-cc/cc2/cc2.h @@ -241,7 +241,7 @@ extern void error(unsigned nerror, ...); extern void parse(void); /* cgen.c */ -extern Node *sethi(Node *np); +extern void genaddr(void); extern void genasm(void); /* peep.c */ diff --git a/src/cmd/scc-cc/cc2/i386-sysv/cgen.c b/src/cmd/scc-cc/cc2/i386-sysv/cgen.c @@ -8,7 +8,7 @@ genasm(void) { } -Node * -sethi(Node *np) +void +genaddr(void) { } diff --git a/src/cmd/scc-cc/cc2/main.c b/src/cmd/scc-cc/cc2/main.c @@ -60,7 +60,7 @@ main(int argc, char *argv[]) while (moreinput()) { parse(); - apply(sethi); + genaddr(); genasm(); peephole(); writeout(); diff --git a/src/cmd/scc-cc/cc2/qbe/cgen.c b/src/cmd/scc-cc/cc2/qbe/cgen.c @@ -159,7 +159,7 @@ complex(Node *np) return np; } -Node * +static Node * sethi(Node *np) { Node *lp, *rp; @@ -844,3 +844,9 @@ genasm(void) apply(norm); apply(cgen); } + +void +genaddr(void) +{ + apply(sethi); +} diff --git a/src/cmd/scc-cc/cc2/z80-scc/cgen.c b/src/cmd/scc-cc/cc2/z80-scc/cgen.c @@ -558,12 +558,6 @@ cgen(Node *np) return np; } -void -genasm(void) -{ - apply(cgen); -} - /* * This is strongly influenced by * http://plan9.bell-labs.com/sys/doc/compiler.ps (/sys/doc/compiler.ps) @@ -573,7 +567,7 @@ genasm(void) * STATIC => 12 (value) * CONST => 20 $value */ -Node * +static Node * sethi(Node *np) { Node *lp, *rp; @@ -620,3 +614,15 @@ sethi(Node *np) ++np->complex; return np; } + +void +genasm(void) +{ + apply(cgen); +} + +void +genaddr(void) +{ + apply(sethi); +}