aboutsummaryrefslogtreecommitdiffstats
path: root/asm
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2020-07-10 17:22:47 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2020-07-10 17:22:47 -0700
commitfcd3cb88615a200fbee85e5906e37e265a8d297d (patch)
treebbde27d993ca40ff330530114f5cc458f347cf07 /asm
parenta79a700208d771fb3b8e6e7f03fcc195c2d1831c (diff)
downloadnasm-fcd3cb88615a200fbee85e5906e37e265a8d297d.tar.gz
nasm-fcd3cb88615a200fbee85e5906e37e265a8d297d.tar.xz
nasm-fcd3cb88615a200fbee85e5906e37e265a8d297d.zip
preproc: preserve %[...] in listings
When generating list output, preserve %[...] in the output if we list a TOK_INDIRECT. The tokenization process removes these deliminators, so we have to explicitly put them back. This doesn't affect assembly output, which will only ever be generated after all TOK_INDIRECT tokens have been removed, but it does affect some of the listing modes. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'asm')
-rw-r--r--asm/preproc.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/asm/preproc.c b/asm/preproc.c
index ccb00f3b..693cbcbb 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -2000,6 +2000,16 @@ static char *detoken(Token * tlist, bool expand_locals)
}
break;
+ case TOK_INDIRECT:
+ /*
+ * This won't happen in when emitting to the assembler,
+ * but can happen when emitting output for some of the
+ * list options. The token string doesn't actually include
+ * the brackets in this case.
+ */
+ len += 3; /* %[] */
+ break;
+
default:
break; /* No modifications */
}
@@ -2019,8 +2029,19 @@ static char *detoken(Token * tlist, bool expand_locals)
p = line = nasm_malloc(len + 1);
- list_for_each(t, tlist)
- p = mempcpy(p, tok_text(t), t->len);
+ list_for_each(t, tlist) {
+ switch (t->type) {
+ case TOK_INDIRECT:
+ *p++ = '%';
+ *p++ = '[';
+ p = mempcpy(p, tok_text(t), t->len);
+ *p++ = ']';
+ break;
+
+ default:
+ p = mempcpy(p, tok_text(t), t->len);
+ }
+ }
*p = '\0';
return line;