diff --git a/asm/preproc.c b/asm/preproc.c index ce0ff826f..0447b258d 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -8257,6 +8257,37 @@ err: return make_tok_num(NULL, val); } +/* + * Given the currently default or command-line default listing options + */ +static Token * +get_list_options(uint64_t optmask) +{ + static const char optchars[63] = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + char optbuf[65], *p; + unsigned int i; + + p = optbuf; + for (i = 0; i < 62; i++) { + if (optmask & 4) + *p++ = optchars[i]; + optmask >>= 1; + } + *p = '\0'; + + return make_tok_qstr_len(NULL, optbuf, p-optbuf); +} + +static Token * +stdmac_list_options(const SMacro *s, Token **params, int nparam) +{ + (void)s; + (void)params; + (void)nparam; + return get_list_options(active_list_options); +} + /* * Wrapper around define_smacro() which also checks to see if it is * a preprocessor directive, so that pp_op_may_be_function[] needs to @@ -8295,6 +8326,7 @@ static void pp_add_magic_simple(void) { "__?BITS?__", true, 0, 0, stdmac_bits }, { "__?PTR?__", true, 0, 0, stdmac_ptr }, { "__?DEFAULT?__", true, 0, 0, stdmac_default }, + { "__?LIST_OPTIONS?__", true, 0, 0, stdmac_list_options }, { "%abs", false, 1, SPARM_EVAL, stdmac_abs }, { "%chr", false, 1, SPARM_EVAL|SPARM_OPTIONAL|SPARM_VARADIC, stdmac_chr }, { "%count", false, 1, SPARM_VARADIC, stdmac_count }, @@ -8552,6 +8584,12 @@ static void pp_add_limits_stdmac(void) define_smacro("__?NASM_LIMITS?__", true, t, NULL); } +static void pp_add_list_options_default_stdmac(void) +{ + define_smacro("__?LIST_OPTIONS_DEFAULT?__", true, + get_list_options(cmdline_list_options), NULL); +} + static void pp_reset_stdmac(enum preproc_mode mode) { int apass; @@ -8569,6 +8607,7 @@ static void pp_reset_stdmac(enum preproc_mode mode) pp_add_limits_stdmac(); + pp_add_list_options_default_stdmac(); do_predef = true; /* diff --git a/doc/changes.src b/doc/changes.src index 2537beca3..efdd1b37b 100644 --- a/doc/changes.src +++ b/doc/changes.src @@ -133,10 +133,17 @@ It is the production version of NASM since 2025. \b Fix a crash when \c{-M} directives were used in response files. \b New listing option \c{-Lc} to include the contents of \c{INCBIN} - files. + files, see \k{opt-L}. \b New listing option \c{-Lt} to include the output from every - iteration of \c{TIMES} and \c{ALIGN} directives. + iteration of \c{TIMES} and \c{ALIGN} directives, see \k{opt-L}. + +\b The \c{%pragma list options} directive now support resetting + options to their command-line default, see \k{opt-L}. + +\b New predefined macros \c{__?LIST_OPTIONS?__} and + \c{__?LIST_OPTIONS_DEFAULT?__} to query the active and command-line + default listing options. See \k{opt-L}. \S{cl-3.01} Version 3.01 diff --git a/doc/running.src b/doc/running.src index da34a99dd..92bf6cb14 100644 --- a/doc/running.src +++ b/doc/running.src @@ -138,24 +138,52 @@ bug reporting), and not likely to be otherwise useful: \b \c{-L!} enable \e{all} listing options including debugging ones +For forward compatility reasons, an undefined flag will be +ignored. Thus, a new flag introduced in a newer version of NASM can be +specified without breaking older versions. Listing flags will always +be a single alphanumeric character and are case sensitive. + These options can be enabled or disabled at runtime using the \c{%pragma list options} directive: -\c %pragma list options [+|-]flags... +\c %pragma list options [+|-|*]{!|flags}... + +\c{+}, \c{-} and \c{*} adds, removes, or restores to the command-line +default the flags that follow. For example, to turn on the \c{d} and \c{m} flags but disable the \c{s} flag: \c %pragma list options +dm -s -The \c{+} and \c{!} shorthands available in on the command line are +The \c{+} and \c{++} shorthands available in on the command line are not available when using \c{%pragma list options}; each listing option -needs to be specified explicitly. +needs to be specified explicitly, or \c{!} can be used to specify all +options. -For forward compatility reasons, an undefined flag will be -ignored. Thus, a new flag introduced in a newer version of NASM can be -specified without breaking older versions. Listing flags will always -be a single alphanumeric character and are case sensitive. +Spaces, quotation marks, and commas in the argument are explicitly +ignored; thus, specifying the options as one or more quoted strings is +valid. + +The built-in macros \i\c{__?LIST_OPTIONS?__} and +\i\c{__?LIST_OPTIONS_DEFAULT?__} contain the currently active and the +command-line default listing options, respectively, as quoted strings. + +To save and restore the listing options, one can use: + +\c %macro ... +\c %define %%saved_list_options __?LIST_OPTIONS?__ +\c ; ... do stuff with special listing options ... +\c %pragma list options -! +%%saved_list_options +\c %endmacro + +The statement: + +\c %pragma list options -! +__?LIST_OPTIONS_DEFAULT?__ + +... is exactly equivalent to ... + +\c %pragma list options *! \S{opt-M} The \i\c{-M} Option: Generate \i{Makefile Dependencies} diff --git a/doc/stdmac.src b/doc/stdmac.src index eca17cbb2..2dcf2729f 100644 --- a/doc/stdmac.src +++ b/doc/stdmac.src @@ -227,6 +227,20 @@ For example, if the \c{altreg} package is included (see See also the \c{%ifusable} and \c{%ifusing} directives, \k{ifusing}. + +\H{list_options_macro} \i\c{__?LIST_OPTIONS?__}: Current Listing Options + +Contains a quoted string with the listing options currently in +effect. See \k{opt-L}. + + +\H{list_options_default_macro} \i\c{__?LIST_OPTIONS_DEFAULT?__}: +Default Listing Options + +Contains a quoted string with the listing options originally specified +by the user on the command line. See \k{opt-L}. + + \H{pass_macro} \i\c{__?PASS?__}: Assembly Pass The macro \c{__?PASS?__} is defined to be \c{1} on preparatory passes,