scc

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

commit 88fc3500f2e31f5f1cd4bdf4c42440bf0e708e7f
parent 77a650bcc7e50297ceacee29cbf26292d13faf7b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 11 Dec 2024 10:56:47 +0100

cc2/qbe: Move getbblocks() to code.c

As getbblocks() is required only to format correctly the qbe
code it makes more sense to call it from writeout().

Diffstat:
Msrc/cmd/scc-cc/cc2/qbe/arch.h | 2--
Msrc/cmd/scc-cc/cc2/qbe/cgen.c | 1-
Msrc/cmd/scc-cc/cc2/qbe/code.c | 52+++++++++++++++++++++++++++-------------------------
3 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/src/cmd/scc-cc/cc2/qbe/arch.h b/src/cmd/scc-cc/cc2/qbe/arch.h @@ -145,5 +145,3 @@ enum asmop { ASVSTAR, ASVARG, }; - -extern void getbblocks(void); diff --git a/src/cmd/scc-cc/cc2/qbe/cgen.c b/src/cmd/scc-cc/cc2/qbe/cgen.c @@ -843,5 +843,4 @@ genasm(void) { apply(norm); apply(cgen); - getbblocks(); } diff --git a/src/cmd/scc-cc/cc2/qbe/code.c b/src/cmd/scc-cc/cc2/qbe/code.c @@ -374,6 +374,31 @@ deftype(Type *tp) tp->id, tp->align, tp->size); } +static void +getbblocks(void) +{ + Inst *i; + + if (!prog) + return; + + prog->flags |= BBENTRY; + for (pc = prog; pc; pc = pc->next) { + switch (pc->op) { + case ASBRANCH: + i = pc->from2.u.sym->u.inst; + i->flags |= BBENTRY; + case ASJMP: + i = pc->from1.u.sym->u.inst; + i->flags |= BBENTRY; + case ASRET: + if (pc->next) + pc->next->flags |= BBENTRY; + break; + } + } +} + void writeout(void) { @@ -384,6 +409,8 @@ writeout(void) if (!curfun) return; + getbblocks(); + if (curfun->kind == SGLOB) fputs("export ", stdout); printf("function %s %s(", size2stack(&curfun->rtype), symname(curfun)); @@ -583,28 +610,3 @@ endinit(void) { puts("}"); } - -void -getbblocks(void) -{ - Inst *i; - - if (!prog) - return; - - prog->flags |= BBENTRY; - for (pc = prog; pc; pc = pc->next) { - switch (pc->op) { - case ASBRANCH: - i = pc->from2.u.sym->u.inst; - i->flags |= BBENTRY; - case ASJMP: - i = pc->from1.u.sym->u.inst; - i->flags |= BBENTRY; - case ASRET: - if (pc->next) - pc->next->flags |= BBENTRY; - break; - } - } -}