[nasm:master] listing: make "list engine active" part of the list options
nasm-bot for H. Peter Anvin (Intel)
hpa at zytor.com
Tue Aug 25 16:18:06 PDT 2020
Commit-ID: 42de8879a20f5ef0c6308f47e562efd18dc9234c
Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=42de8879a20f5ef0c6308f47e562efd18dc9234c
Author: H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Tue, 25 Aug 2020 15:49:12 -0700
Committer: H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Tue, 25 Aug 2020 15:49:12 -0700
listing: make "list engine active" part of the list options
List engine active is useful information in its own right.
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>
---
asm/listing.c | 3 +++
asm/listing.h | 38 ++++++++++++++++++++++++--------------
asm/nasm.c | 4 +---
3 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/asm/listing.c b/asm/listing.c
index f6ef6d1b..49b76401 100644
--- a/asm/listing.c
+++ b/asm/listing.c
@@ -130,6 +130,7 @@ static void list_cleanup(void)
list_emit();
fclose(listfp);
listfp = NULL;
+ active_list_options = 0;
}
static void list_init(const char *fname)
@@ -153,6 +154,8 @@ static void list_init(const char *fname)
return;
}
+ active_list_options = list_options | 1;
+
*listline = '\0';
listlineno = 0;
list_errors = NULL;
diff --git a/asm/listing.h b/asm/listing.h
index 351fc69e..cb64119b 100644
--- a/asm/listing.h
+++ b/asm/listing.h
@@ -126,35 +126,38 @@ extern bool user_nolist;
extern uint64_t list_options, active_list_options;
/*
- * This maps the characters a-z, A-Z and 0-9 onto a 64-bit bitmask
- * (with two bits left over for future use! This isn't particularly
- * efficient code, but just about every instance of it should be
- * fed a constant, so the entire function can be precomputed at
- * compile time. The only cases where the full computation is needed
- * is when parsing the -L option or %pragma list options, neither of
- * which is in any way performance critical.
+ * This maps the characters a-z, A-Z and 0-9 onto a 64-bit bitmask.
+ * Bit 0 is used to indicate that the listing engine is active, and
+ * bit 1 is reserved, so this will only return mask bits 2 and higher;
+ * as there are 62 possible characters this fits nicely.
*
- * The character + represents ALL listing options.
+ * The mask returned is 0 for invalid characters, accessing no bits at
+ * all.
+ *
+ * This isn't particularly efficient code, but just about every
+ * instance of it should be fed a constant, so the entire function can
+ * be precomputed at compile time. The only cases where the full
+ * computation is needed is when parsing the -L option or %pragma list
+ * options, neither of which is in any way performance critical.
*
- * This returns 0 for invalid values, so that no bit is accessed
- * for unsupported characters.
+ * The character + represents ALL listing options.
*/
static inline const_func uint64_t list_option_mask(unsigned char x)
{
if (x >= 'a') {
if (x > 'z')
return 0;
- x = x - 'a';
+ x = x - 'a' + 2;
} else if (x >= 'A') {
if (x > 'Z')
return 0;
- x = x - 'A' + 26;
+ x = x - 'A' + 2 + 26;
} else if (x >= '0') {
if (x > '9')
return 0;
- x = x - '0' + 26*2;
+ x = x - '0' + 2 + 26*2;
} else if (x == '+') {
- return ~UINT64_C(0);
+ return ~UINT64_C(1);
} else {
return 0;
}
@@ -162,6 +165,7 @@ static inline const_func uint64_t list_option_mask(unsigned char x)
return UINT64_C(1) << x;
}
+/* Return true if the listing engine is active and a certain option is set. */
static inline pure_func bool list_option(unsigned char x)
{
return unlikely(active_list_options & list_option_mask(x));
@@ -173,6 +177,12 @@ static inline pure_func bool list_on_every_pass(void)
return unlikely(list_options & list_option_mask('p'));
}
+/* Is the listing engine active? */
+static inline pure_func bool list_active(void)
+{
+ return (active_list_options & 1);
+}
+
/* Pragma handler */
enum directive_result list_pragma(const struct pragma *);
diff --git a/asm/nasm.c b/asm/nasm.c
index 5155f35b..a7ad4510 100644
--- a/asm/nasm.c
+++ b/asm/nasm.c
@@ -1685,9 +1685,8 @@ static void assemble_file(const char *fname, struct strlist *depend_list)
cpu = cmd_cpu;
if (listname) {
if (pass_final() || list_on_every_pass()) {
- active_list_options = list_options;
lfmt->init(listname);
- } else if (active_list_options) {
+ } else if (list_active()) {
/*
* Looks like we used the list engine on a previous pass,
* but now it is turned off, presumably via %pragma -p
@@ -1695,7 +1694,6 @@ static void assemble_file(const char *fname, struct strlist *depend_list)
lfmt->cleanup();
if (!keep_all)
remove(listname);
- active_list_options = 0;
}
}
More information about the Nasm-commits
mailing list