rbtree: add rb_search_exact()
[nasm.git] / include / error.h
blobd5dc65da4ef4877758fd410d1fef1a1ab0deb05d
1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2020 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
9 * conditions are met:
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * Error reporting functions for the assembler
38 #ifndef NASM_ERROR_H
39 #define NASM_ERROR_H 1
41 #include "compiler.h"
44 * File pointer for error messages
46 extern FILE *error_file; /* Error file descriptor */
49 * Typedef for the severity field
51 typedef uint32_t errflags;
54 * An error reporting function should look like this.
56 void printf_func(2, 3) nasm_error(errflags severity, const char *fmt, ...);
57 void printf_func(1, 2) nasm_listmsg(const char *fmt, ...);
58 void printf_func(2, 3) nasm_listmsgf(errflags flags, const char *fmt, ...);
59 void printf_func(1, 2) nasm_debug(const char *fmt, ...);
60 void printf_func(2, 3) nasm_debugf(errflags flags, const char *fmt, ...);
61 void printf_func(1, 2) nasm_info(const char *fmt, ...);
62 void printf_func(2, 3) nasm_infof(errflags flags, const char *fmt, ...);
63 void printf_func(2, 3) nasm_warn(errflags flags, const char *fmt, ...);
64 void printf_func(1, 2) nasm_nonfatal(const char *fmt, ...);
65 void printf_func(2, 3) nasm_nonfatalf(errflags flags, const char *fmt, ...);
66 fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...);
67 fatal_func printf_func(2, 3) nasm_fatalf(errflags flags, const char *fmt, ...);
68 fatal_func printf_func(1, 2) nasm_critical(const char *fmt, ...);
69 fatal_func printf_func(2, 3) nasm_criticalf(errflags flags, const char *fmt, ...);
70 fatal_func printf_func(1, 2) nasm_panic(const char *fmt, ...);
71 fatal_func printf_func(2, 3) nasm_panicf(errflags flags, const char *fmt, ...);
72 fatal_func nasm_panic_from_macro(const char *file, int line);
73 #define panic() nasm_panic_from_macro(__FILE__, __LINE__);
75 void nasm_verror(errflags severity, const char *fmt, va_list ap);
76 fatal_func nasm_verror_critical(errflags severity, const char *fmt, va_list ap);
79 * These are the error severity codes which get passed as the first
80 * argument to an efunc.
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
90 * 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 */
96 #define ERR_PASS1 0x00000080 /* message on pass_first */
97 #define ERR_PASS2 0x00000100 /* ignore unless on pass_final */
99 #define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */
100 #define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */
101 #define ERR_PP_LISTMACRO 0x00000800 /* from preproc->error_list_macros() */
102 #define ERR_HOLD 0x00001000 /* this error/warning can be held */
105 * These codes define specific types of suppressible warning.
106 * They are assumed to occupy the most significant bits of the
107 * severity code.
109 #define WARN_SHR 16 /* how far to shift right */
110 #define WARN_IDX(x) (((errflags)(x)) >> WARN_SHR)
111 #define WARN_MASK ((~(errflags)0) << WARN_SHR)
113 /* This is a bitmask */
114 #define WARN_ST_ENABLED 1 /* Warning is currently enabled */
115 #define WARN_ST_ERROR 2 /* Treat this warning as an error */
117 /* Possible initial state for warnings */
118 #define WARN_INIT_OFF 0
119 #define WARN_INIT_ON WARN_ST_ENABLED
120 #define WARN_INIT_ERR (WARN_ST_ENABLED|WARN_ST_ERROR)
122 /* Process a warning option or directive */
123 bool set_warning_status(const char *value);
125 /* Warning stack management */
126 void push_warnings(void);
127 void pop_warnings(void);
128 void init_warnings(void);
129 void reset_warnings(void);
132 * Tentative error hold for warnings/errors indicated with ERR_HOLD.
134 * This is a stack; the "hold" argument *must*
135 * match the value returned from nasm_error_hold_push().
136 * If "issue" is true the errors are committed (or promoted to the next
137 * higher stack level), if false then they are discarded.
139 * Errors stronger than ERR_NONFATAL cannot be held.
141 struct nasm_errhold;
142 typedef struct nasm_errhold *errhold;
143 errhold nasm_error_hold_push(void);
144 void nasm_error_hold_pop(errhold hold, bool issue);
146 /* Should be included from within error.h only */
147 #include "warnings.h"
149 /* By defining MAX_DEBUG, we can compile out messages entirely */
150 #ifndef MAX_DEBUG
151 # define MAX_DEBUG (~0U)
152 #endif
154 /* Debug level checks */
155 static inline bool debug_level(unsigned int level)
157 extern unsigned int debug_nasm;
158 if (is_constant(level) && level > MAX_DEBUG)
159 return false;
160 return unlikely(level <= debug_nasm);
163 #endif /* NASM_ERROR_H */