aboutsummaryrefslogtreecommitdiffstats
path: root/asm
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2020-08-25 15:49:12 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2020-08-25 15:49:12 -0700
commit42de8879a20f5ef0c6308f47e562efd18dc9234c (patch)
treea1732dc974d92b50d1ed4855831783bf3378bb44 /asm
parent8c9b8ec2e21e10be73dcbfa8288a124a5f7b133d (diff)
downloadnasm-42de8879a20f5ef0c6308f47e562efd18dc9234c.tar.gz
nasm-42de8879a20f5ef0c6308f47e562efd18dc9234c.tar.xz
nasm-42de8879a20f5ef0c6308f47e562efd18dc9234c.zip
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@zytor.com>
Diffstat (limited to 'asm')
-rw-r--r--asm/listing.c3
-rw-r--r--asm/listing.h38
-rw-r--r--asm/nasm.c4
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;
}
}