Skip to content

Commit 5606bdb

Browse files
author
H. Peter Anvin (Intel)
committed
listing: move the setting of options to one function
Disentangle the list option setting from the list option checking. This makes the code simpler for the compiler to grok, and centralizing code is usually a good idea. The option setting is hardly performance critical anyway. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1 parent fe9586f commit 5606bdb

3 files changed

Lines changed: 33 additions & 35 deletions

File tree

asm/listing.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -349,29 +349,37 @@ static void list_set_offset(uint64_t offset)
349349
listoffset = offset;
350350
}
351351

352-
static void list_update_options(const char *str)
352+
/*
353+
* from_cmdline is passed in to handle -L+ -> LIST_PLUS_OPTIONS,
354+
* and to prevent active_list_options from being set (that will
355+
* be done when list_init() is called.)
356+
*
357+
* As listing options are assumed non-critical, ignore errors
358+
* to help forward compatibility.
359+
*/
360+
void list_update_options(const char *str, bool from_cmdline)
353361
{
354-
bool state = true;
355362
unsigned char c;
356-
uint64_t mask;
363+
uint64_t setmask = LIST_ALL_OPTIONS_MASK;
364+
uint64_t amask = from_cmdline ? 0 : setmask;
357365

358366
while ((c = *str++)) {
367+
uint64_t mask = 0;
359368
switch (c) {
360369
case '+':
361-
state = true;
370+
if (from_cmdline && setmask)
371+
list_update_options(LIST_PLUS_OPTIONS, true);
372+
setmask = LIST_ALL_OPTIONS_MASK;
362373
break;
363374
case '-':
364-
state = false;
375+
setmask = 0;
365376
break;
366377
default:
367378
mask = list_option_mask(c);
368-
if (state) {
369-
list_options |= mask;
370-
active_list_options |= mask;
371-
} else {
372-
list_options &= ~mask;
373-
active_list_options &= ~mask;
374-
}
379+
list_options = (list_options & ~mask) | (setmask & mask);
380+
active_list_options =
381+
(active_list_options & ~mask) |
382+
(setmask & amask & mask);
375383
break;
376384
}
377385
}
@@ -381,7 +389,7 @@ enum directive_result list_pragma(const struct pragma *pragma)
381389
{
382390
switch (pragma->opcode) {
383391
case D_OPTIONS:
384-
list_update_options(pragma->tail);
392+
list_update_options(pragma->tail, false);
385393
return DIRR_OK;
386394

387395
default:

asm/listing.h

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
#include "nasm.h"
1212

13+
/* List options implied by -L+ */
14+
#define LIST_PLUS_OPTIONS "bdefFmps"
15+
1316
/*
1417
* List-file generators should look like this:
1518
*/
@@ -107,13 +110,10 @@ extern uint64_t list_options, active_list_options;
107110
* This isn't particularly efficient code, but just about every
108111
* instance of it should be fed a constant, so the entire function can
109112
* be precomputed at compile time. The only cases where the full
110-
* computation is needed is when parsing the -L option or %pragma list
111-
* options, neither of which is in any way performance critical.
112-
*
113-
* The character + represents ALL listing options except -Lw (flush
114-
* after every line.)
113+
* computation is needed is in list_update_options(), which is not
114+
* performance critical.
115115
*/
116-
static inline const_func uint64_t list_option_mask_val(unsigned char x)
116+
static inline const_func uint64_t list_option_mask(unsigned char x)
117117
{
118118
if (x >= 'a') {
119119
if (x > 'z')
@@ -134,18 +134,7 @@ static inline const_func uint64_t list_option_mask_val(unsigned char x)
134134
return UINT64_C(1) << x;
135135
}
136136

137-
static inline const_func uint64_t list_option_mask(unsigned char x)
138-
{
139-
if (x == '+') {
140-
const char *p = "bdefFmps";
141-
uint64_t v = 0;
142-
while (*p)
143-
v |= list_option_mask_val(*p++);
144-
return v;
145-
} else {
146-
return list_option_mask_val(x);
147-
}
148-
}
137+
#define LIST_ALL_OPTIONS_MASK (~UINT64_C(3))
149138

150139
/* Return true if the listing engine is active and a certain option is set. */
151140
static inline pure_func bool list_option(unsigned char x)
@@ -165,6 +154,9 @@ static inline pure_func bool list_active(void)
165154
return (active_list_options & 1);
166155
}
167156

157+
/* Change listing options */
158+
void list_update_options(const char *str, bool from_cmdline);
159+
168160
/* Pragma handler */
169161
enum directive_result list_pragma(const struct pragma *);
170162

asm/nasm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,10 +1052,8 @@ static bool process_arg(char *p, char *q, int pass)
10521052
break;
10531053

10541054
case 'L': /* listing options */
1055-
if (pass == 2) {
1056-
while (*param)
1057-
list_options |= list_option_mask(*param++);
1058-
}
1055+
if (pass == 2)
1056+
list_update_options(param, true);
10591057
break;
10601058

10611059
case 'Z': /* error messages file */

0 commit comments

Comments
 (0)