[nasm:master] preproc: a negative number is actually two tokens
nasm-bot for H. Peter Anvin (Intel)
hpa at zytor.com
Fri Jul 10 01:15:04 PDT 2020
Commit-ID: fcb3d135ec3292f7875e5ad275f2490c544a7ecc
Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=fcb3d135ec3292f7875e5ad275f2490c544a7ecc
Author: H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Fri, 10 Jul 2020 01:08:47 -0700
Committer: H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Fri, 10 Jul 2020 01:08:47 -0700
preproc: a negative number is actually two tokens
A negative number is two tokens: a minus sign and a positive
number. For most uses we still want to generate signed numbers; for
specific uses there might be motivation for an unsigned output, but in
most cases it would be confusing.
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>
---
asm/preproc.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/asm/preproc.c b/asm/preproc.c
index 1c29b4c0..efa48cea 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -7180,12 +7180,23 @@ static void pp_extra_stdmac(macros_t *macros)
extrastdmac = macros;
}
-/* Create a numeric token */
+/* Create a numeric token, with possible - token in front */
static Token *make_tok_num(Token *next, int64_t val)
{
char numbuf[32];
- int len = snprintf(numbuf, sizeof(numbuf), "%"PRId64"", val);
- return new_Token(next, TOK_NUMBER, numbuf, len);
+ int len;
+ uint64_t uval;
+ bool minus = val < 0;
+
+ uval = minus ? -val : val;
+
+ len = snprintf(numbuf, sizeof numbuf, "%"PRIu64, uval);
+ next = new_Token(next, TOK_NUMBER, numbuf, len);
+
+ if (minus)
+ next = make_tok_char(next, '-');
+
+ return next;
}
/* Create a quoted string token */
More information about the Nasm-commits
mailing list