qbe

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

commit 9e7e5bffc4e4af37a6c29657ba87fbb6a1123cf2
parent 72f2e8445adaeeb4916690263f65d6b61ffa5c1d
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 14 May 2019 14:34:23 -0700

Allow specifying literal global names

Diffstat:
Mamd64/emit.c | 13++++++++-----
Mgas.c | 2+-
Mparse.c | 23+++++++++++++++--------
3 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/amd64/emit.c b/amd64/emit.c @@ -161,12 +161,13 @@ slot(int s, Fn *fn) static void emitcon(Con *con, FILE *f) { - char *p; + char *p, *l; switch (con->type) { case CAddr: - p = con->local ? gasloc : gassym; - fprintf(f, "%s%s", p, str(con->label)); + l = str(con->label); + p = con->local ? gasloc : l[0] == '"' ? "" : gassym; + fprintf(f, "%s%s", p, l); if (con->bits.i) fprintf(f, "%+"PRId64, con->bits.i); break; @@ -539,15 +540,17 @@ amd64_emitfn(Fn *fn, FILE *f) Ins *i, itmp; int *r, c, o, n, lbl; uint64_t fs; + char *p; + p = fn->name[0] == '"' ? "" : gassym; fprintf(f, ".text\n"); if (fn->export) - fprintf(f, ".globl %s%s\n", gassym, fn->name); + fprintf(f, ".globl %s%s\n", p, fn->name); fprintf(f, "%s%s:\n" "\tpushq %%rbp\n" "\tmovq %%rsp, %%rbp\n", - gassym, fn->name + p, fn->name ); fs = framesz(fn); if (fs) diff --git a/gas.c b/gas.c @@ -39,7 +39,7 @@ gasemitdat(Dat *d, FILE *f) if (d->isstr) { if (d->type != DB) err("strings only supported for 'b' currently"); - fprintf(f, "\t.ascii \"%s\"\n", d->u.str); + fprintf(f, "\t.ascii %s\n", d->u.str); } else if (d->isref) { fprintf(f, "%s %s%s%+"PRId64"\n", diff --git a/parse.c b/parse.c @@ -227,15 +227,20 @@ lex() return Tfltd; case '%': t = Ttmp; + c = fgetc(inf); goto Alpha; case '@': t = Tlbl; + c = fgetc(inf); goto Alpha; case '$': t = Tglo; + if ((c = fgetc(inf)) == '"') + goto Quoted; goto Alpha; case ':': t = Ttyp; + c = fgetc(inf); goto Alpha; case '#': while ((c=fgetc(inf)) != '\n' && c != EOF) @@ -251,23 +256,25 @@ lex() return Tint; } if (c == '"') { - tokval.str = vnew(0, 1, Pfn); + t = Tstr; + Quoted: + tokval.str = vnew(2, 1, Pfn); + tokval.str[0] = c; esc = 0; - for (i=0;; i++) { + for (i=1;; i++) { c = fgetc(inf); if (c == EOF) err("unterminated string"); - vgrow(&tokval.str, i+1); + vgrow(&tokval.str, i+2); + tokval.str[i] = c; if (c == '"' && !esc) { - tokval.str[i] = 0; - return Tstr; + tokval.str[i+1] = 0; + return t; } esc = (c == '\\' && !esc); - tokval.str[i] = c; } } - if (0) -Alpha: c = fgetc(inf); +Alpha: if (!isalpha(c) && c != '.' && c != '_') err("invalid character %c (%d)", c, c); i = 0;