From 840a50439c4c140ca2bc09da4f16b5a9d4680917 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Thu, 11 Aug 2022 14:45:18 +1000 Subject: [PATCH] Implement -u for asxlat, for less readable but more robust locals handling --- as0.c | 65 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/as0.c b/as0.c index a26ca21..3a0b32f 100644 --- a/as0.c +++ b/as0.c @@ -686,9 +686,13 @@ void pass0() { psymbol->value = pdot->value; #ifdef TRANSLATE // reset locals - xlabnext = 0; - memset(xlabb, 0xff, 10 * sizeof(int)); - memset(xlabf, 0xff, 10 * sizeof(int)); + // for asxlat, -u means local labels will be changed to ordinary labels + // (use this when there is an inconvenient ordinary label within locals) + if (defund != FGLOBAL) { + xlabnext = 0; + memset(xlabb, 0xff, 10 * sizeof(int)); + memset(xlabf, 0xff, 10 * sizeof(int)); + } #endif continue; @@ -716,7 +720,12 @@ void pass0() { xlabb[label] = xlab; if (xstartpsave >= xbuf + 0xff0) abort(); - xbufp = xstartpsave + sprintf(xstartpsave, "%d$:", xlab); + // for asxlat, -u means local labels will be changed to ordinary labels + // (use this when there is an inconvenient ordinary label within locals) + if (defund == FGLOBAL) + xbufp = xstartpsave + sprintf(xstartpsave, "_%d:", xlab); + else + xbufp = xstartpsave + sprintf(xstartpsave, "%d$:", xlab); #endif /* cmp fbfree,$4 / room for another fb entry? */ @@ -2057,16 +2066,6 @@ int rsch() { /* 1: */ void p0xpr() { -#ifdef TRANSLATE - xrestn = xbufp - xstartp; - memcpy(xrest, xstartp, xrestn); - if (xstartp + xrestn >= xbuf + 0xff0) - abort(); - xbufp = xstartp + sprintf(xstartp, ".dw "); - xstartp = xbufp; // for local labels - memcpy(xbufp, xrest, xrestn); - xbufp += xrestn; -#endif p0expres(); pdot->value += 2; } @@ -2099,7 +2098,19 @@ void p0opline() { p0opl17(); } else + { +#ifdef TRANSLATE + xrestn = xbufp - xstartp; + memcpy(xrest, xstartp, xrestn); + if (xstartp + xrestn >= xbuf + 0xff0) + abort(); + xbufp = xstartp + sprintf(xstartp, ".dw "); + xstartp = xbufp; // for local labels + memcpy(xbufp, xrest, xrestn); + xbufp += xrestn; +#endif p0xpr(); + } return; } @@ -2114,6 +2125,18 @@ void p0opline() { psymbol = (struct symbol *)token; flags = psymbol->flags; if (flags <= FBSS || flags == FREGISTER || flags > FJCOND) { +#ifdef TRANSLATE + if (flags != FABS) { // assume for now that ABS symbol can only be an opcode + xrestn = xbufp - xstartp; + memcpy(xrest, xstartp, xrestn); + if (xstartp + xrestn >= xbuf + 0xff0) + abort(); + xbufp = xstartp + sprintf(xstartp, ".dw "); + xstartp = xbufp; // for local labels + memcpy(xbufp, xrest, xrestn); + xbufp += xrestn; + } +#endif p0xpr(); return; } @@ -2881,7 +2904,12 @@ void p0expres() { #ifdef TRANSLATE if (xstartp >= xbuf + 0xff0) abort(); - xbufp = xstartp + sprintf(xstartp, "%d$", xlabb[token - TLABEL]); + // for asxlat, -u means local labels will be changed to ordinary labels + // (use this when there is an inconvenient ordinary label within locals) + if (defund == FGLOBAL) + xbufp = xstartp + sprintf(xstartp, "_%d", xlabb[token - TLABEL]); + else + xbufp = xstartp + sprintf(xstartp, "%d$", xlabb[token - TLABEL]); #endif rightflags = curfbr[token - TLABEL]; /* bug!! should be rightvalue / rightflags below: */ @@ -2897,7 +2925,12 @@ void p0expres() { xlabf[xlab] = xlabnext++; if (xstartp >= xbuf + 0xff0) abort(); - xbufp = xstartp + sprintf(xstartp, "%d$", xlabf[xlab]); + // for asxlat, -u means local labels will be changed to ordinary labels + // (use this when there is an inconvenient ordinary label within locals) + if (defund == FGLOBAL) + xbufp = xstartp + sprintf(xstartp, "_%d", xlabf[xlab]); + else + xbufp = xstartp + sprintf(xstartp, "%d$", xlabf[xlab]); } #endif leftflags = 0; -- 2.34.1