qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

commit 7aceb24c50276322f79e7d13cbc6c9cd9251f447
parent 9fc0394d7ed2b86be9eae7f2b410e83fbe3ae497
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 10 Feb 2022 15:29:20 -0800

gas: put zero data into .bss by default

This allows frontends to use BSS generically, without knowledge of
platform-dependent details.

Diffstat:
Mall.h | 6++----
Mgas.c | 21++++++++++++++++-----
Mparse.c | 4++--
3 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/all.h b/all.h @@ -387,6 +387,8 @@ struct Dat { DL, DZ } type; + char *name; + Lnk *lnk; union { int64_t num; double fltd; @@ -396,10 +398,6 @@ struct Dat { char *name; int64_t off; } ref; - struct { - char *name; - Lnk *lnk; - } start; } u; char isref; char isstr; diff --git a/gas.c b/gas.c @@ -33,21 +33,32 @@ gasemitdat(Dat *d, FILE *f) [DW] = "\t.int", [DL] = "\t.quad" }; + static int64_t zero; char *p; switch (d->type) { case DStart: - gasemitlnk( - d->u.start.name, - d->u.start.lnk, - ".data", f); + zero = 0; break; case DEnd: + if (zero != -1) { + gasemitlnk(d->name, d->lnk, ".bss", f); + fprintf(f, "\t.fill %"PRId64",1,0\n", zero); + } break; case DZ: - fprintf(f, "\t.fill %"PRId64",1,0\n", d->u.num); + if (zero != -1) + zero += d->u.num; + else + fprintf(f, "\t.fill %"PRId64",1,0\n", d->u.num); break; default: + if (zero != -1) { + gasemitlnk(d->name, d->lnk, ".data", f); + if (zero > 0) + fprintf(f, "\t.fill %"PRId64",1,0\n", zero); + zero = -1; + } if (d->isstr) { if (d->type != DB) err("strings only supported for 'b' currently"); diff --git a/parse.c b/parse.c @@ -1010,8 +1010,8 @@ parsedat(void cb(Dat *), Lnk *lnk) t = nextnl(); } d.type = DStart; - d.u.start.name = name; - d.u.start.lnk = lnk; + d.name = name; + d.lnk = lnk; cb(&d); if (t != Tlbrace)