Skip to content

Commit 8d62e99

Browse files
author
H. Peter Anvin
committed
Add %note directive to add a note in the list file
This differs from a plain old comment in the following ways: 1. It is optionally macro-expanded; 2. It has a dash prefix; 3. It can be used inside .nolist macros. Suggested-by: <[email protected]> Resolves: https://bugzilla.nasm.us/show_bug.cgi?id=3392915 Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 6ad3bab commit 8d62e99

File tree

8 files changed

+85
-43
lines changed

8 files changed

+85
-43
lines changed

asm/error.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ----------------------------------------------------------------------- *
22
*
3-
* Copyright 1996-2019 The NASM Authors - All Rights Reserved
3+
* Copyright 1996-2024 The NASM Authors - All Rights Reserved
44
* See the file AUTHORS included with the NASM distribution for
55
* the specific copyright holders.
66
*
@@ -70,6 +70,7 @@ _type nasm_ ## _name (const char *fmt, ...) \
7070
}
7171

7272
nasm_err_helpers(void, listmsg, ERR_LISTMSG)
73+
nasm_err_helpers(void, note, ERR_NOTE)
7374
nasm_err_helpers(void, debug, ERR_DEBUG)
7475
nasm_err_helpers(void, info, ERR_INFO)
7576
nasm_err_helpers(void, nonfatal, ERR_NONFATAL)

asm/listing.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ static int listlevel, listlevel_e;
7171

7272
static FILE *listfp;
7373

74+
static inline char err_fill_char(errflags severity)
75+
{
76+
severity &= ERR_MASK;
77+
78+
if (severity < ERR_NOTE)
79+
return ' ';
80+
else if (severity < ERR_WARNING)
81+
return '-';
82+
else if (severity < ERR_CRITICAL)
83+
return '*';
84+
else
85+
return 'X';
86+
}
87+
7488
static void list_emit(void)
7589
{
7690
int i;
@@ -100,12 +114,11 @@ static void list_emit(void)
100114
}
101115

102116
if (list_errors) {
103-
static const char fillchars[] = " --***XX";
104-
char fillchar;
105-
106117
strlist_for_each(e, list_errors) {
118+
char fillchar;
119+
107120
fprintf(listfp, "%6"PRId32" ", listlineno);
108-
fillchar = fillchars[e->pvt.u & ERR_MASK];
121+
fillchar = err_fill_char(e->pvt.u);
109122
for (i = 0; i < LIST_HEXBIT; i++)
110123
putc(fillchar, listfp);
111124

asm/nasm.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,11 +1852,11 @@ static bool skip_this_pass(errflags severity)
18521852
return false;
18531853

18541854
/*
1855-
* ERR_LISTMSG messages are always skipped; the list file
1856-
* receives them anyway as this function is not consulted
1857-
* for sending to the list file.
1855+
* ERR_LISTMSG and ERR_NOTE messages are always skipped; the list
1856+
* file receives them anyway as this function is not consulted for
1857+
* sending to the list file.
18581858
*/
1859-
if (type == ERR_LISTMSG)
1859+
if (type <= ERR_NOTE)
18601860
return true;
18611861

18621862
/*
@@ -1920,10 +1920,31 @@ static errflags true_error_type(errflags severity)
19201920
/*
19211921
* The various error type prefixes
19221922
*/
1923-
static const char * const error_pfx_table[ERR_MASK+1] = {
1924-
";;; ", "debug: ", "info: ", "warning: ",
1925-
"error: ", "fatal: ", "critical: ", "panic: "
1926-
};
1923+
static inline const char *error_pfx(errflags severity)
1924+
{
1925+
switch (severity & ERR_MASK) {
1926+
case ERR_LISTMSG:
1927+
return ";;; ";
1928+
case ERR_NOTE:
1929+
return "note: ";
1930+
case ERR_DEBUG:
1931+
return "debug: ";
1932+
case ERR_INFO:
1933+
return "info: ";
1934+
case ERR_WARNING:
1935+
return "warning: ";
1936+
case ERR_NONFATAL:
1937+
return "error: ";
1938+
case ERR_FATAL:
1939+
return "fatal: ";
1940+
case ERR_CRITICAL:
1941+
return "critical: ";
1942+
case ERR_PANIC:
1943+
return "panic: ";
1944+
default:
1945+
return "internal error: ";
1946+
}
1947+
}
19271948
static const char no_file_name[] = "nasm"; /* What to print if no file name */
19281949

19291950
/*
@@ -1996,7 +2017,7 @@ fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list args
19962017
if (!where.filename)
19972018
where.filename = no_file_name;
19982019

1999-
fputs(error_pfx_table[severity], error_file);
2020+
fputs(error_pfx(severity), error_file);
20002021
fputs(where.filename, error_file);
20012022
if (where.lineno) {
20022023
fprintf(error_file, "%s%"PRId32"%s",
@@ -2138,7 +2159,7 @@ static void nasm_issue_error(struct nasm_errtext *et)
21382159
if (severity & ERR_NO_SEVERITY)
21392160
pfx = "";
21402161
else
2141-
pfx = error_pfx_table[true_type];
2162+
pfx = error_pfx(true_type);
21422163

21432164
*warnsuf = 0;
21442165
if ((severity & (ERR_MASK|ERR_HERE|ERR_PP_LISTMACRO)) == ERR_WARNING) {

asm/pptok.dat

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## --------------------------------------------------------------------------
2-
##
3-
## Copyright 1996-2019 The NASM Authors - All Rights Reserved
2+
##
3+
## Copyright 1996-2024 The NASM Authors - All Rights Reserved
44
## See the file AUTHORS included with the NASM distribution for
55
## the specific copyright holders.
66
##
@@ -14,7 +14,7 @@
1414
## copyright notice, this list of conditions and the following
1515
## disclaimer in the documentation and/or other materials provided
1616
## with the distribution.
17-
##
17+
##
1818
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
1919
## CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
2020
## INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -91,6 +91,7 @@
9191
%line
9292
%local
9393
%null
94+
%note
9495
%pop
9596
%pragma
9697
%push

asm/preproc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ----------------------------------------------------------------------- *
22
*
3-
* Copyright 1996-2023 The NASM Authors - All Rights Reserved
3+
* Copyright 1996-2024 The NASM Authors - All Rights Reserved
44
* See the file AUTHORS included with the NASM distribution for
55
* the specific copyright holders.
66
*
@@ -4437,6 +4437,9 @@ static int do_directive(Token *tline, Token **output)
44374437
*/
44384438
severity = ERR_WARNING|WARN_USER|ERR_PASS2;
44394439
goto issue_error;
4440+
case PP_NOTE:
4441+
severity = ERR_NOTE;
4442+
goto issue_error;
44404443

44414444
issue_error:
44424445
{

doc/preproc.src

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,8 @@ the construction of an appropriately sized ENTER instruction
22512251
as shown in the example.
22522252

22532253

2254-
\H{pperror} Reporting \i{User-Defined Errors}: \i\c{%error}, \i\c{%warning}, \i\c{%fatal}
2254+
\H{pperror} Reporting \i{User-generated Diagnostics}: \i\c{%error},
2255+
\i\c{%warning}, \i\c{%fatal}, \i\c{%note}
22552256

22562257
The preprocessor directive \c{%error} will cause NASM to report an
22572258
error if it occurs in assembled code. So if other users are going to
@@ -2282,6 +2283,9 @@ Similarly, \c{%warning} issues a warning, but allows assembly to continue:
22822283
\c %define F1
22832284
\c %endif
22842285

2286+
User-defined error messages can be suppressed with the \c{-w-user}
2287+
option, and promoted to errors with \c{-w+error=user}.
2288+
22852289
\c{%error} and \c{%warning} are issued only on the final assembly
22862290
pass. This makes them safe to use in conjunction with tests that
22872291
depend on symbol values.
@@ -2291,10 +2295,13 @@ is useful when there is no point in continuing the assembly further,
22912295
and doing so is likely just going to cause a spew of confusing error
22922296
messages.
22932297

2294-
It is optional for the message string after \c{%error}, \c{%warning}
2295-
or \c{%fatal} to be quoted. If it is \e{not}, then single-line macros
2296-
are expanded in it, which can be used to display more information to
2297-
the user. For example:
2298+
\c{%note} adds an output line to the list file; it does not output
2299+
anything on the console or error file.
2300+
2301+
It is optional for the message string after \c{%error}, \c{%warning},
2302+
\c{%fatal}, or \c{%note} to be quoted. If it is \e{not}, then
2303+
single-line macros are expanded in it, which can be used to display
2304+
more information to the user. For example:
22982305

22992306
\c %if foo > 64
23002307
\c %assign foo_over foo-64
@@ -2459,7 +2466,3 @@ compatibility aliases)
24592466

24602467
In NASM 2.14 and earlier, only the single syntax \c{%clear} was
24612468
supported, which is equivalent to \c{%clear global all}.
2462-
2463-
2464-
2465-

include/error.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ----------------------------------------------------------------------- *
22
*
3-
* Copyright 1996-2023 The NASM Authors - All Rights Reserved
3+
* Copyright 1996-2024 The NASM Authors - All Rights Reserved
44
* See the file AUTHORS included with the NASM distribution for
55
* the specific copyright holders.
66
*
@@ -79,20 +79,21 @@ fatal_func vprintf_func(2) nasm_verror_critical(errflags severity, const char *f
7979
* These are the error severity codes which get passed as the first
8080
* argument to an efunc.
8181
*/
82-
#define ERR_LISTMSG 0x00000000 /* for the listing file only */
83-
#define ERR_DEBUG 0x00000001 /* debugging message */
84-
#define ERR_INFO 0x00000002 /* information for the list file */
85-
#define ERR_WARNING 0x00000003 /* warn only: no further action */
86-
#define ERR_NONFATAL 0x00000004 /* terminate assembly after phase */
87-
#define ERR_FATAL 0x00000005 /* instantly fatal: exit with error */
88-
#define ERR_CRITICAL 0x00000006 /* fatal, but minimize code before exit */
89-
#define ERR_PANIC 0x00000007 /* internal error: panic instantly
82+
#define ERR_LISTMSG 0x00000000 /* for the listing file only (no prefix) */
83+
#define ERR_NOTE 0x00000001 /* for the listing file only (with prefix) */
84+
#define ERR_DEBUG 0x00000002 /* debugging message */
85+
#define ERR_INFO 0x00000003 /* information for the list file */
86+
#define ERR_WARNING 0x00000004 /* warn only: no further action */
87+
#define ERR_NONFATAL 0x00000008 /* terminate assembly after phase */
88+
#define ERR_FATAL 0x00000009 /* instantly fatal: exit with error */
89+
#define ERR_CRITICAL 0x0000000e /* fatal, but minimize code before exit */
90+
#define ERR_PANIC 0x0000000f /* internal error: panic instantly
9091
* and dump core for reference */
91-
#define ERR_MASK 0x00000007 /* mask off the above codes */
92-
#define ERR_UNDEAD 0x00000008 /* skip if we already have errors */
93-
#define ERR_NOFILE 0x00000010 /* don't give source file name/line */
94-
#define ERR_HERE 0x00000020 /* point to a specific source location */
95-
#define ERR_USAGE 0x00000040 /* print a usage message */
92+
#define ERR_MASK 0x0000000f /* mask off the above codes */
93+
#define ERR_UNDEAD 0x00000010 /* skip if we already have errors */
94+
#define ERR_NOFILE 0x00000020 /* don't give source file name/line */
95+
#define ERR_HERE 0x00000040 /* point to a specific source location */
96+
#define ERR_USAGE 0x00000080 /* print a usage message */
9697
#define ERR_PASS2 0x00000100 /* ignore unless on pass_final */
9798

9899
#define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */

nasmlib/errfile.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#include "compiler.h"
22

33
FILE *error_file;
4-

0 commit comments

Comments
 (0)