qbe

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

commit 83c210834197b7ad3208214a4f9d8669134c4a3c
parent cdee1d81c4c73113eb293bf2ac816bee53047f36
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 10 Aug 2020 12:28:48 -0400

add data $name = section "section" ...

This allows you to explicitly specify the section to emit the data
directive for, allowing for sections other than .data: for example, .bss
or .init_array.

Diffstat:
Mgas.c | 6+++++-
Mparse.c | 27++++++++++++++++++---------
Mtools/lexh.c | 6+++---
3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/gas.c b/gas.c @@ -19,7 +19,11 @@ gasemitdat(Dat *d, FILE *f) switch (d->type) { case DStart: align = 0; - fprintf(f, ".data\n"); + if (d->u.str) { + fprintf(f, ".section %s\n", d->u.str); + } else { + fprintf(f, ".data\n"); + } break; case DEnd: break; diff --git a/parse.c b/parse.c @@ -41,6 +41,7 @@ enum { Tfunc, Ttype, Tdata, + Tsection, Talign, Tl, Tw, @@ -90,6 +91,7 @@ static char *kwmap[Ntok] = { [Tfunc] = "function", [Ttype] = "type", [Tdata] = "data", + [Tsection] = "section", [Talign] = "align", [Tl] = "l", [Tw] = "w", @@ -984,29 +986,36 @@ parsedatstr(Dat *d) static void parsedat(void cb(Dat *), int export) { - char s[NString]; + char name[NString] = {0}; int t; Dat d; - d.type = DStart; - d.isstr = 0; - d.isref = 0; - d.export = export; - cb(&d); if (nextnl() != Tglo || nextnl() != Teq) err("data name, then = expected"); - strcpy(s, tokval.str); + strncpy(name, tokval.str, NString-1); t = nextnl(); + d.u.str = 0; + if (t == Tsection) { + if (nextnl() != Tstr) + err("section \"name\" expected"); + d.u.str = tokval.str; + t = nextnl(); + } + d.type = DStart; + cb(&d); if (t == Talign) { if (nextnl() != Tint) err("alignment expected"); d.type = DAlign; d.u.num = tokval.num; + d.isstr = 0; + d.isref = 0; cb(&d); t = nextnl(); } d.type = DName; - d.u.str = s; + d.u.str = name; + d.export = export; cb(&d); if (t != Tlbrace) @@ -1025,8 +1034,8 @@ parsedat(void cb(Dat *), int export) } t = nextnl(); do { - d.isref = 0; d.isstr = 0; + d.isref = 0; memset(&d.u, 0, sizeof d.u); if (t == Tflts) d.u.flts = tokval.flts; diff --git a/tools/lexh.c b/tools/lexh.c @@ -25,9 +25,9 @@ char *tok[] = { "vaarg", "vastart", "...", "env", "call", "phi", "jmp", "jnz", "ret", "export", - "function", "type", "data", "align", "l", "w", - "h", "b", "d", "s", "z", "loadw", "loadl", "loads", - "loadd", "alloc1", "alloc2", + "function", "type", "data", "section", "align", + "l", "w", "h", "b", "d", "s", "z", "loadw", "loadl", + "loads", "loadd", "alloc1", "alloc2", }; enum {