diff options
author | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-14 12:22:11 -0800 |
---|---|---|
committer | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-14 12:22:11 -0800 |
commit | 800c1686880acd74b964de00f58c7a2d8f14eff3 (patch) | |
tree | 7df3672f996677dc14079cbe107f7dc1945a771b | |
parent | 190e8465630e9e1fd8a211256a9fdcd6cc9176d7 (diff) | |
download | nasm-800c1686880acd74b964de00f58c7a2d8f14eff3.tar.gz |
--no-line: new option to ignore %line directives
For debugging preprocessed code, it is useful to be able to ignore
%line directives rather than having to filter them out externally.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
-rw-r--r-- | asm/nasm.c | 9 | ||||
-rw-r--r-- | asm/preproc-nop.c | 11 | ||||
-rw-r--r-- | asm/preproc.c | 4 | ||||
-rw-r--r-- | asm/preproc.h | 1 | ||||
-rw-r--r-- | doc/changes.src | 3 | ||||
-rw-r--r-- | doc/nasmdoc.src | 34 |
6 files changed, 40 insertions, 22 deletions
@@ -142,6 +142,7 @@ static const struct forwrefinfo *forwref; static const struct preproc_ops *preproc; static StrList *include_path; +bool pp_noline; /* Ignore %line directives */ #define OP_NORMAL (1U << 0) #define OP_PREPROCESS (1U << 1) @@ -839,7 +840,8 @@ enum text_options { OPT_PRAGMA, OPT_BEFORE, OPT_LIMIT, - OPT_KEEP_ALL + OPT_KEEP_ALL, + OPT_NO_LINE }; struct textargs { const char *label; @@ -863,6 +865,7 @@ static const struct textargs textopts[] = { {"before", OPT_BEFORE, true, 0}, {"limit-", OPT_LIMIT, true, 0}, {"keep-all", OPT_KEEP_ALL, false, 0}, + {"no-line", OPT_NO_LINE, false, 0}, {NULL, OPT_BOGUS, false, 0} }; @@ -1210,6 +1213,9 @@ static bool process_arg(char *p, char *q, int pass) case OPT_KEEP_ALL: keep_all = true; break; + case OPT_NO_LINE: + pp_noline = true; + break; case OPT_HELP: help(0); exit(0); @@ -2001,6 +2007,7 @@ static void help(const char xopt) " --lprefix str prepend the given string to all other symbols\n" " --lpostfix str append the given string to all other symbols\n" " --keep-all output files will not be removed even if an error happens\n" + " --no-line ignore %%line directives in input\n" " --limit-X val set execution limit X\n"); for (i = 0; i <= LIMIT_MAX; i++) { diff --git a/asm/preproc-nop.c b/asm/preproc-nop.c index 6f7aaf9e..3244889d 100644 --- a/asm/preproc-nop.c +++ b/asm/preproc-nop.c @@ -86,7 +86,6 @@ static char *nop_getline(void) src_set_linnum(src_get_linnum() + nop_lineinc); while (1) { /* Loop to handle %line */ - p = buffer; while (1) { /* Loop to handle long lines */ q = fgets(p, bufsize - (p - buffer), nop_fp); @@ -119,13 +118,15 @@ static char *nop_getline(void) int32_t ln; int li; char *nm = nasm_malloc(strlen(buffer)); - if (sscanf(buffer + 5, "%"PRId32"+%d %s", &ln, &li, nm) == 3) { - src_set(ln, nm); + int conv = sscanf(buffer + 5, "%"PRId32"+%d %s", &ln, &li, nm); + if (conv >= 2) { + if (!pp_noline) + src_set(ln, conv >= 3 ? nm : NULL); nop_lineinc = li; - nasm_free(nm); - continue; } nasm_free(nm); + if (conv >= 2) + continue; } break; } diff --git a/asm/preproc.c b/asm/preproc.c index b134414a..95ca56fc 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -3662,6 +3662,10 @@ issue_error: /* * Syntax is `%line nnn[+mmm] [filename]' */ + if (unlikely(pp_noline)) { + free_tlist(origline); + return DIRECTIVE_FOUND; + } tline = tline->next; skip_white_(tline); if (!tok_type_(tline, TOK_NUMBER)) { diff --git a/asm/preproc.h b/asm/preproc.h index fcf8695b..14d4cfd3 100644 --- a/asm/preproc.h +++ b/asm/preproc.h @@ -43,6 +43,7 @@ extern const char * const pp_directives[]; extern const uint8_t pp_directives_len[]; +extern bool pp_noline; /* Pointer to a macro chain */ typedef const unsigned char macros_t; diff --git a/doc/changes.src b/doc/changes.src index 8e0bc060..d279b0ad 100644 --- a/doc/changes.src +++ b/doc/changes.src @@ -37,6 +37,9 @@ failure instead which is very slow and not easy to debug. \b Duplicate definitions of the same label \e{with the same value} is now explicitly permitted (2.14 would allow it in some circumstances.) +\b Add the option \c{--no-line} to ignore \c{%line} directives in the +source. See \k{opt-no-line} and \k{line}. + \S{cl-2.14} Version 2.14 \b Changed \c{-I} option semantics by adding a trailing path separator diff --git a/doc/nasmdoc.src b/doc/nasmdoc.src index f1abc507..bdec6b6e 100644 --- a/doc/nasmdoc.src +++ b/doc/nasmdoc.src @@ -368,10 +368,10 @@ To get further usage instructions from NASM, try typing \c nasm -h -\c{--help} option is also the same. +The option \c{--help} is an alias for the \c{-h} option. -As \c{-hf}, this will also list the available output file formats, and what they -are. +The option \c{-hf} will also list the available output file formats, +and what they are. If you use Linux but aren't sure whether your system is \c{a.out} or \c{ELF}, type @@ -992,7 +992,14 @@ In example, running this limits the maximum line count to be 1000. \S{opt-keep-all} The \i\c{--keep-all} Option -This option doesn't delete any output files even if an error happens. +This option prevents NASM from deleting any output files even if an +error happens. + +\S{opt-no-line} The \i\c{--no-line} Option + +If this option is given, all \i\c{%line} directives in the source code +are ignored. This can be useful for debugging already preprocessed +code. See \k{line}. \S{nasmenv} The \i\c{NASMENV} \i{Environment} Variable @@ -3747,15 +3754,6 @@ the user. For example: \H{otherpreproc} \i{Other Preprocessor Directives} -NASM also has preprocessor directives which allow access to -information from external sources. Currently they include: - -\b\c{%line} enables NASM to correctly handle the output of another -preprocessor (see \k{line}). - -\b\c{%!} enables NASM to read in the value of an environment variable, -which can then be used in your program (see \k{getenv}). - \S{line} \i\c{%line} Directive The \c{%line} directive is used to notify NASM that the input line @@ -3766,9 +3764,9 @@ directive allows NASM to output messages which indicate the line number of the original source file, instead of the file that is being read by NASM. -This preprocessor directive is not generally of use to programmers, -by may be of interest to preprocessor authors. The usage of the -\c{%line} preprocessor directive is as follows: +This preprocessor directive is not generally used directly by +programmers, but may be of interest to preprocessor authors. The +usage of the \c{%line} preprocessor directive is as follows: \c %line nnn[+mmm] [filename] @@ -3783,6 +3781,10 @@ After reading a \c{%line} preprocessor directive, NASM will report all file name and line numbers relative to the values specified therein. +If the command line option \i\c{--no-line} is given, all \c{%line} +directives are ignored. This may be useful for debugging preprocessed +code. See \k{opt-no-line}. + \S{getenv} \i\c{%!}\e{variable}: Read an Environment Variable. |