aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2018-12-10 21:53:54 -0800
committerH. Peter Anvin <hpa@zytor.com>2018-12-10 22:46:20 -0800
commitd351efc97d83b1733ba1a11d1d661dcf3a14124b (patch)
tree9cf89d1acf794a04a3226a57c8996749f333f8f6
parent36e3c707908738ce15dfc75b5a6d57c3e2791e2a (diff)
downloadnasm-d351efc97d83b1733ba1a11d1d661dcf3a14124b.tar.gz
nasm-d351efc97d83b1733ba1a11d1d661dcf3a14124b.tar.xz
nasm-d351efc97d83b1733ba1a11d1d661dcf3a14124b.zip
error: add nasm_note() helper, clean up helper generation
It is fairly easy to more compactly create error helpers since we are using preprocessor hacks anyway, so do exactly that. Create nasm_note() helpers for the new NOTE severity class. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--asm/error.c91
-rw-r--r--include/error.h2
2 files changed, 27 insertions, 66 deletions
diff --git a/asm/error.c b/asm/error.c
index f99baaaf..88e3a1b2 100644
--- a/asm/error.c
+++ b/asm/error.c
@@ -82,76 +82,38 @@ uint8_t warning_state_init[ERR_WARN_ALL];
/* Global error handling function */
vefunc nasm_verror;
-void nasm_error(int severity, const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- nasm_verror(severity, fmt, ap);
+/* Common function body */
+#define nasm_do_error(s) \
+ va_list ap; \
+ va_start(ap, fmt); \
+ nasm_verror((s), fmt, 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, ...)
-{
- nasm_error_generator(ERR_FATAL, fmt);
- abort();
-}
-
-fatal_func nasm_fatalf(int flags, const char *fmt, ...)
+void nasm_error(int severity, const char *fmt, ...)
{
- nasm_error_generatorf(ERR_FATAL, flags, fmt);
- abort();
+ nasm_do_error(severity);
}
-fatal_func nasm_panic(const char *fmt, ...)
-{
- nasm_error_generator(ERR_PANIC, fmt);
- abort();
+#define nasm_err_helpers(_type, _name, _sev) \
+_type nasm_ ## _name ## f (int flags, const char *fmt, ...) \
+{ \
+ nasm_do_error((_sev)|flags); \
+ if (_sev >= ERR_FATAL) \
+ abort(); \
+} \
+_type nasm_ ## _name (const char *fmt, ...) \
+{ \
+ nasm_do_error(_sev); \
+ if (_sev >= ERR_FATAL) \
+ abort(); \
}
-fatal_func nasm_panicf(int flags, const char *fmt, ...)
-{
- nasm_error_generatorf(ERR_PANIC, flags, fmt);
- abort();
-}
+nasm_err_helpers(void, debug, ERR_DEBUG)
+nasm_err_helpers(void, note, ERR_NOTE)
+nasm_err_helpers(void, warn, ERR_WARNING)
+nasm_err_helpers(void, nonfatal, ERR_NONFATAL)
+nasm_err_helpers(fatal_func, fatal, ERR_FATAL)
+nasm_err_helpers(fatal_func, panic, ERR_PANIC)
fatal_func nasm_panic_from_macro(const char *file, int line)
{
@@ -163,9 +125,6 @@ fatal_func nasm_assert_failed(const char *file, int line, const char *msg)
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.
* Returns true if if the action was successful.
diff --git a/include/error.h b/include/error.h
index 5d3dc22e..cbd75e79 100644
--- a/include/error.h
+++ b/include/error.h
@@ -46,6 +46,8 @@
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_note(const char *fmt, ...);
+void printf_func(2, 3) nasm_notef(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, ...);