summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-09-15 08:57:21 -0700
committerH. Peter Anvin <hpa@zytor.com>2010-09-15 08:57:21 -0700
commitb40992c9295fa8600b5a77285bac24ab766ffbc8 (patch)
treef452d72a408140a31bf877af55f40e2b19fe1139
parente6e6a9ae2c55751869968b6d1e9a96b0710c6283 (diff)
downloadnasm-b40992c9295fa8600b5a77285bac24ab766ffbc8.tar.gz
preproc: reverse the order of the tokens in %deftok
Smacros are apparently stored with the token stream reversed, so make sure %deftok matches that sense of relatity. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--preproc.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/preproc.c b/preproc.c
index 70e550d0..f7f0114a 100644
--- a/preproc.c
+++ b/preproc.c
@@ -488,6 +488,24 @@ static size_t nasm_unquote_cstr(char *qstr, enum preproc_token directive)
}
/*
+ * In-place reverse a list of tokens.
+ */
+static Token *reverse_tokens(Token *t)
+{
+ Token *prev = NULL;
+ Token *next;
+
+ while (t) {
+ next = t->next;
+ t->next = prev;
+ prev = t;
+ t = next;
+ }
+
+ return prev;
+}
+
+/*
* Handle TASM specific directives, which do not contain a % in
* front of them. We do it here because I could not find any other
* place to do it for the moment, and it is a hack (ideally it would
@@ -3186,8 +3204,13 @@ issue_error:
return DIRECTIVE_FOUND;
}
+ /*
+ * Convert the string to a token stream. Note that smacros
+ * are stored with the token stream reversed, so we have to
+ * reverse the output of tokenize().
+ */
nasm_unquote_cstr(t->text, i);
- macro_start = tokenize(t->text);
+ macro_start = reverse_tokens(tokenize(t->text));
/*
* We now have a macro name, an implicit parameter count of