diff options
author | H. Peter Anvin <hpa@zytor.com> | 2019-08-09 22:31:45 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2019-08-09 22:31:45 -0700 |
commit | ab6f8319552f17d269a5bf2facea48ea1c338b71 (patch) | |
tree | 77f41f8eb26c872d5a884c21308824ce154baa85 | |
parent | ad1f50a50694b31539db5a24b0c2bc1090855094 (diff) | |
download | nasm-ab6f8319552f17d269a5bf2facea48ea1c338b71.tar.gz |
listing: when listing lines in macros and rep blocks, show the actual line
When printing lines coming from %rep blocks and macros, show the line
number corresponding to the line actually being printed.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | asm/listing.c | 7 | ||||
-rw-r--r-- | asm/listing.h | 5 | ||||
-rw-r--r-- | asm/preproc-nop.c | 2 | ||||
-rw-r--r-- | asm/preproc.c | 32 |
4 files changed, 25 insertions, 21 deletions
diff --git a/asm/listing.c b/asm/listing.c index 2e04bb6c..50e63d85 100644 --- a/asm/listing.c +++ b/asm/listing.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2018 The NASM Authors - All Rights Reserved + * Copyright 1996-2019 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -258,7 +258,7 @@ static void list_output(const struct out_data *data) } } -static void list_line(int type, char *line) +static void list_line(int type, int32_t lineno, const char *line) { if (!listp) return; @@ -276,7 +276,8 @@ static void list_line(int type, char *line) } } list_emit(); - listlineno = src_get_linnum(); + if (lineno >= 0) + listlineno = lineno; listlinep = true; strlcpy(listline, line, LIST_MAX_LEN-3); memcpy(listline + LIST_MAX_LEN-4, "...", 4); diff --git a/asm/listing.h b/asm/listing.h index 00326854..9d4a3353 100644 --- a/asm/listing.h +++ b/asm/listing.h @@ -70,8 +70,11 @@ struct lfmt { * `int' parameter is LIST_READ or LIST_MACRO depending on * whether the line came directly from an input file or is the * result of a multi-line macro expansion. + * + * If a line number is provided, print it; if the line number is + * -1 then use the same line number as the previous call. */ - void (*line)(int type, char *line); + void (*line)(int type, int32_t lineno, const char *line); /* * Called to change one of the various levelled mechanisms in the diff --git a/asm/preproc-nop.c b/asm/preproc-nop.c index 575896ed..a9a46b0f 100644 --- a/asm/preproc-nop.c +++ b/asm/preproc-nop.c @@ -128,7 +128,7 @@ static char *nop_getline(void) break; } - lfmt->line(LIST_READ, buffer); + lfmt->line(LIST_READ, src_get_linnum(), buffer); return buffer; } diff --git a/asm/preproc.c b/asm/preproc.c index 10cc2197..03176402 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -859,6 +859,7 @@ static char *read_line(void) unsigned int nr_cont = 0; bool cont = false; char *buffer, *p; + int32_t lineno; /* Standart macros set (predefined) goes first */ p = line_from_stdmac(); @@ -923,9 +924,10 @@ static char *read_line(void) *p++ = c; } while (c); - src_set_linnum(src_get_linnum() + istk->lineinc + - (nr_cont * istk->lineinc)); - lfmt->line(LIST_READ, buffer); + lineno = src_get_linnum() + istk->lineinc + + (nr_cont * istk->lineinc); + src_set_linnum(lineno); + lfmt->line(LIST_READ, lineno, buffer); return buffer; } @@ -3194,20 +3196,12 @@ issue_error: free_tlist(origline); tmp_defining = defining; - defining = nasm_malloc(sizeof(MMacro)); - defining->prev = NULL; - defining->name = NULL; /* flags this macro as a %rep block */ - defining->casesense = false; - defining->plus = false; + nasm_new(defining); defining->nolist = nolist; defining->in_progress = count; - defining->max_depth = 0; - defining->nparam_min = defining->nparam_max = 0; - defining->defaults = NULL; - defining->dlist = NULL; - defining->expansion = NULL; defining->next_active = istk->mstk; defining->rep_nest = tmp_defining; + src_get(&defining->xline, &defining->fname); return DIRECTIVE_FOUND; case PP_ENDREP: @@ -5484,13 +5478,19 @@ static Token *pp_tokline(void) if (istk->expansion) { /* from a macro expansion */ Line *l = istk->expansion; + int32_t lineno; + if (istk->mstk) - istk->mstk->lineno++; + lineno = ++istk->mstk->lineno + istk->mstk->xline; + else + lineno = src_get_linnum(); + tline = l->first; istk->expansion = l->next; nasm_free(l); + line = detoken(tline, false); - lfmt->line(LIST_MACRO, line); + lfmt->line(LIST_MACRO, lineno, line); nasm_free(line); } else if ((line = read_line())) { line = prepreproc(line); @@ -5602,7 +5602,7 @@ static char *pp_getline(void) if (list_option('e') && line && line[0]) { char *buf = nasm_strcat(" ;;; ", line); - lfmt->line(LIST_MACRO, buf); + lfmt->line(LIST_MACRO, -1, buf); nasm_free(buf); } |