summaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2019-08-15 02:29:40 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2019-08-15 02:29:40 -0700
commit6d5c77c95fcbc582de14ed3ebce19e7cd462acb8 (patch)
treea3597b0f2cef1d83e926c11329b9d267a737c226 /asm
parent566a0f21875f2a39cbbee43cb7bbd15b685a3feb (diff)
downloadnasm-6d5c77c95fcbc582de14ed3ebce19e7cd462acb8.tar.gz
stdmac: handle up to 160 directives, make macros.c more readable
Handle up to 160 directives for stdmac compression. This is done by allowing the directive numbers to wrap around (128-255, 0-31), using 127 for end of line, and forcing any whitespace character to be space. Make macros.c a bit more legible by using #defines for the byte codes; strictly for the benefit of the human reader. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'asm')
-rw-r--r--asm/preproc.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/asm/preproc.c b/asm/preproc.c
index 9c84e505..251768ee 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -798,19 +798,26 @@ static char *line_from_stdmac(void)
if (!stdmacpos)
return NULL;
- while ((c = *p++)) {
- if (c >= 0x80)
- len += pp_directives_len[c - 0x80] + 1;
+ /*
+ * 32-126 is ASCII, 127 is end of line, 128-31 are directives
+ * (allowed to wrap around) corresponding to PP_* tokens 0-159.
+ */
+ while ((c = *p++) != 127) {
+ uint8_t ndir = c - 128;
+ if (ndir < 256-96)
+ len += pp_directives_len[ndir] + 1;
else
len++;
}
line = nasm_malloc(len + 1);
q = line;
- while ((c = *stdmacpos++)) {
- if (c >= 0x80) {
- memcpy(q, pp_directives[c - 0x80], pp_directives_len[c - 0x80]);
- q += pp_directives_len[c - 0x80];
+
+ while ((c = *stdmacpos++) != 127) {
+ uint8_t ndir = c - 128;
+ if (ndir < 256-96) {
+ memcpy(q, pp_directives[ndir], pp_directives_len[ndir]);
+ q += pp_directives_len[ndir];
*q++ = ' ';
} else {
*q++ = c;
@@ -819,7 +826,7 @@ static char *line_from_stdmac(void)
stdmacpos = p;
*q = '\0';
- if (!*stdmacpos) {
+ if (*stdmacpos == 127) {
/* This was the last of this particular macro set */
stdmacpos = NULL;
if (*stdmacnext) {