mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-07-24 10:25:42 -04:00
error: Cover all levels with helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
3351072306
commit
c3527dd6b2
65
asm/error.c
65
asm/error.c
@ -91,39 +91,65 @@ void nasm_error(int severity, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define nasm_error_generatorf(__sev, __flags, __fmt) \
|
||||||
|
va_list __ap; \
|
||||||
|
va_start(__ap, __fmt); \
|
||||||
|
nasm_verror(__sev | __flags, __fmt, __ap)
|
||||||
|
|
||||||
|
#define nasm_error_generator(__sev, __fmt) \
|
||||||
|
nasm_error_generatorf(__sev, 0, __fmt)
|
||||||
|
|
||||||
|
void nasm_debug(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
nasm_error_generator(ERR_DEBUG, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nasm_debugf(int flags, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
nasm_error_generatorf(ERR_DEBUG, flags, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nasm_warn(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
nasm_error_generator(ERR_WARNING, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nasm_warnf(int flags, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
nasm_error_generatorf(ERR_WARNING, flags, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nasm_nonfatal(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
nasm_error_generator(ERR_NONFATAL, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nasm_nonfatalf(int flags, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
nasm_error_generatorf(ERR_NONFATAL, flags, fmt);
|
||||||
|
}
|
||||||
|
|
||||||
fatal_func nasm_fatal(const char *fmt, ...)
|
fatal_func nasm_fatal(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
nasm_error_generator(ERR_FATAL, fmt);
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
nasm_verror(ERR_FATAL, fmt, ap);
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
fatal_func nasm_fatal_fl(int flags, const char *fmt, ...)
|
fatal_func nasm_fatalf(int flags, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
nasm_error_generatorf(ERR_FATAL, flags, fmt);
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
nasm_verror(flags | ERR_FATAL, fmt, ap);
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
fatal_func nasm_panic(const char *fmt, ...)
|
fatal_func nasm_panic(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
nasm_error_generator(ERR_PANIC, fmt);
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
nasm_verror(ERR_PANIC, fmt, ap);
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
fatal_func nasm_panic_fl(int flags, const char *fmt, ...)
|
fatal_func nasm_panicf(int flags, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
nasm_error_generatorf(ERR_PANIC, flags, fmt);
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
nasm_verror(flags | ERR_PANIC, fmt, ap);
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +163,9 @@ fatal_func nasm_assert_failed(const char *file, int line, const char *msg)
|
|||||||
nasm_panic("assertion %s failed at %s:%d", msg, file, line);
|
nasm_panic("assertion %s failed at %s:%d", msg, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef nasm_error_generator
|
||||||
|
#undef nasm_error_generatorf
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is called when processing a -w or -W option, or a warning directive.
|
* This is called when processing a -w or -W option, or a warning directive.
|
||||||
* Returns true if if the action was successful.
|
* Returns true if if the action was successful.
|
||||||
|
16
asm/nasm.c
16
asm/nasm.c
@ -489,7 +489,7 @@ int main(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
dfmt = dfmt_find(ofmt, debug_format);
|
dfmt = dfmt_find(ofmt, debug_format);
|
||||||
if (!dfmt) {
|
if (!dfmt) {
|
||||||
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
|
nasm_fatalf(ERR_NOFILE | ERR_USAGE,
|
||||||
"unrecognized debug format `%s' for"
|
"unrecognized debug format `%s' for"
|
||||||
" output format `%s'",
|
" output format `%s'",
|
||||||
debug_format, ofmt->shortname);
|
debug_format, ofmt->shortname);
|
||||||
@ -549,7 +549,7 @@ int main(int argc, char **argv)
|
|||||||
if (outname) {
|
if (outname) {
|
||||||
ofile = nasm_open_write(outname, NF_TEXT);
|
ofile = nasm_open_write(outname, NF_TEXT);
|
||||||
if (!ofile)
|
if (!ofile)
|
||||||
nasm_fatal_fl(ERR_NOFILE,
|
nasm_fatalf(ERR_NOFILE,
|
||||||
"unable to open output file `%s'",
|
"unable to open output file `%s'",
|
||||||
outname);
|
outname);
|
||||||
} else
|
} else
|
||||||
@ -594,7 +594,7 @@ int main(int argc, char **argv)
|
|||||||
if (operating_mode & OP_NORMAL) {
|
if (operating_mode & OP_NORMAL) {
|
||||||
ofile = nasm_open_write(outname, (ofmt->flags & OFMT_TEXT) ? NF_TEXT : NF_BINARY);
|
ofile = nasm_open_write(outname, (ofmt->flags & OFMT_TEXT) ? NF_TEXT : NF_BINARY);
|
||||||
if (!ofile)
|
if (!ofile)
|
||||||
nasm_fatal_fl(ERR_NOFILE,
|
nasm_fatalf(ERR_NOFILE,
|
||||||
"unable to open output file `%s'", outname);
|
"unable to open output file `%s'", outname);
|
||||||
|
|
||||||
ofmt->init();
|
ofmt->init();
|
||||||
@ -892,7 +892,7 @@ static bool process_arg(char *p, char *q, int pass)
|
|||||||
if (pass == 1) {
|
if (pass == 1) {
|
||||||
ofmt = ofmt_find(param, &ofmt_alias);
|
ofmt = ofmt_find(param, &ofmt_alias);
|
||||||
if (!ofmt) {
|
if (!ofmt) {
|
||||||
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
|
nasm_fatalf(ERR_NOFILE | ERR_USAGE,
|
||||||
"unrecognised output format `%s' - "
|
"unrecognised output format `%s' - "
|
||||||
"use -hf for a list", param);
|
"use -hf for a list", param);
|
||||||
}
|
}
|
||||||
@ -992,7 +992,7 @@ static bool process_arg(char *p, char *q, int pass)
|
|||||||
else if (nasm_stricmp("gnu", param) == 0)
|
else if (nasm_stricmp("gnu", param) == 0)
|
||||||
nasm_set_verror(nasm_verror_gnu);
|
nasm_set_verror(nasm_verror_gnu);
|
||||||
else
|
else
|
||||||
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
|
nasm_fatalf(ERR_NOFILE | ERR_USAGE,
|
||||||
"unrecognized error reporting format `%s'",
|
"unrecognized error reporting format `%s'",
|
||||||
param);
|
param);
|
||||||
}
|
}
|
||||||
@ -1391,19 +1391,19 @@ static void parse_cmdline(int argc, char **argv, int pass)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!inname)
|
if (!inname)
|
||||||
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE, "no input file specified");
|
nasm_fatalf(ERR_NOFILE | ERR_USAGE, "no input file specified");
|
||||||
|
|
||||||
else if ((errname && !strcmp(inname, errname)) ||
|
else if ((errname && !strcmp(inname, errname)) ||
|
||||||
(outname && !strcmp(inname, outname)) ||
|
(outname && !strcmp(inname, outname)) ||
|
||||||
(listname && !strcmp(inname, listname)) ||
|
(listname && !strcmp(inname, listname)) ||
|
||||||
(depend_file && !strcmp(inname, depend_file)))
|
(depend_file && !strcmp(inname, depend_file)))
|
||||||
nasm_fatal_fl(ERR_USAGE, "will not overwrite input file");
|
nasm_fatalf(ERR_USAGE, "will not overwrite input file");
|
||||||
|
|
||||||
if (errname) {
|
if (errname) {
|
||||||
error_file = nasm_open_write(errname, NF_TEXT);
|
error_file = nasm_open_write(errname, NF_TEXT);
|
||||||
if (!error_file) {
|
if (!error_file) {
|
||||||
error_file = stderr; /* Revert to default! */
|
error_file = stderr; /* Revert to default! */
|
||||||
nasm_fatal_fl(ERR_NOFILE | ERR_USAGE,
|
nasm_fatalf(ERR_NOFILE | ERR_USAGE,
|
||||||
"cannot open file `%s' for error messages",
|
"cannot open file `%s' for error messages",
|
||||||
errname);
|
errname);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ static void nop_reset(const char *file, int pass, struct strlist *deplist)
|
|||||||
nop_fp = nasm_open_read(file, NF_TEXT);
|
nop_fp = nasm_open_read(file, NF_TEXT);
|
||||||
|
|
||||||
if (!nop_fp)
|
if (!nop_fp)
|
||||||
nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file);
|
nasm_fatalf(ERR_NOFILE, "unable to open input file `%s'", file);
|
||||||
(void)pass; /* placate compilers */
|
(void)pass; /* placate compilers */
|
||||||
|
|
||||||
strlist_add(deplist, file);
|
strlist_add(deplist, file);
|
||||||
|
@ -4950,7 +4950,7 @@ pp_reset(const char *file, int apass, struct strlist *dep_list)
|
|||||||
src_set(0, file);
|
src_set(0, file);
|
||||||
istk->lineinc = 1;
|
istk->lineinc = 1;
|
||||||
if (!istk->fp)
|
if (!istk->fp)
|
||||||
nasm_fatal_fl(ERR_NOFILE, "unable to open input file `%s'", file);
|
nasm_fatalf(ERR_NOFILE, "unable to open input file `%s'", file);
|
||||||
defining = NULL;
|
defining = NULL;
|
||||||
nested_mac_count = 0;
|
nested_mac_count = 0;
|
||||||
nested_rep_count = 0;
|
nested_rep_count = 0;
|
||||||
|
@ -44,10 +44,16 @@
|
|||||||
* An error reporting function should look like this.
|
* An error reporting function should look like this.
|
||||||
*/
|
*/
|
||||||
void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
|
void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
|
||||||
|
void printf_func(1, 2) nasm_debug(const char *fmt, ...);
|
||||||
|
void printf_func(2, 3) nasm_debugf(int flags, const char *fmt, ...);
|
||||||
|
void printf_func(1, 2) nasm_warn(const char *fmt, ...);
|
||||||
|
void printf_func(2, 3) nasm_warnf(int flags, const char *fmt, ...);
|
||||||
|
void printf_func(1, 2) nasm_nonfatal(const char *fmt, ...);
|
||||||
|
void printf_func(2, 3) nasm_nonfatalf(int flags, const char *fmt, ...);
|
||||||
fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...);
|
fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...);
|
||||||
|
fatal_func printf_func(2, 3) nasm_fatalf(int flags, const char *fmt, ...);
|
||||||
fatal_func printf_func(1, 2) nasm_panic(const char *fmt, ...);
|
fatal_func printf_func(1, 2) nasm_panic(const char *fmt, ...);
|
||||||
fatal_func printf_func(2, 3) nasm_fatal_fl(int flags, const char *fmt, ...);
|
fatal_func printf_func(2, 3) nasm_panicf(int flags, const char *fmt, ...);
|
||||||
fatal_func printf_func(2, 3) nasm_panic_fl(int flags, const char *fmt, ...);
|
|
||||||
fatal_func nasm_panic_from_macro(const char *file, int line);
|
fatal_func nasm_panic_from_macro(const char *file, int line);
|
||||||
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);
|
#define panic() nasm_panic_from_macro(__FILE__, __LINE__);
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ FILE *nasm_open_read(const char *filename, enum file_flags flags)
|
|||||||
f = fopen(filename, (flags & NF_TEXT) ? "rt" : "rb");
|
f = fopen(filename, (flags & NF_TEXT) ? "rt" : "rb");
|
||||||
|
|
||||||
if (!f && (flags & NF_FATAL))
|
if (!f && (flags & NF_FATAL))
|
||||||
nasm_fatal_fl(ERR_NOFILE, "unable to open input file: `%s': %s",
|
nasm_fatalf(ERR_NOFILE, "unable to open input file: `%s': %s",
|
||||||
filename, strerror(errno));
|
filename, strerror(errno));
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
@ -132,7 +132,7 @@ FILE *nasm_open_write(const char *filename, enum file_flags flags)
|
|||||||
f = fopen(filename, (flags & NF_TEXT) ? "wt" : "wb");
|
f = fopen(filename, (flags & NF_TEXT) ? "wt" : "wb");
|
||||||
|
|
||||||
if (!f && (flags & NF_FATAL))
|
if (!f && (flags & NF_FATAL))
|
||||||
nasm_fatal_fl(ERR_NOFILE, "unable to open output file: `%s': %s",
|
nasm_fatalf(ERR_NOFILE, "unable to open output file: `%s': %s",
|
||||||
filename, strerror(errno));
|
filename, strerror(errno));
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user