Merge branch 'nasm-2.14.xx'
[nasm.git] / include / error.h
blob08d562b8f7b595817f94d79e20480e0db6784dd0
1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2018 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 * An error reporting function should look like this.
46 void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
47 fatal_func printf_func(1, 2) nasm_fatal(const char *fmt, ...);
48 fatal_func printf_func(1, 2) nasm_panic(const char *fmt, ...);
49 fatal_func printf_func(2, 3) nasm_fatal_fl(int flags, const char *fmt, ...);
50 fatal_func printf_func(2, 3) nasm_panic_fl(int flags, const char *fmt, ...);
51 fatal_func nasm_panic_from_macro(const char *file, int line);
52 #define panic() nasm_panic_from_macro(__FILE__, __LINE__);
54 typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
55 extern vefunc nasm_verror;
56 static inline vefunc nasm_set_verror(vefunc ve)
58 vefunc old_verror = nasm_verror;
59 nasm_verror = ve;
60 return old_verror;
64 * These are the error severity codes which get passed as the first
65 * argument to an efunc.
68 #define ERR_DEBUG 0x00000000 /* put out debugging message */
69 #define ERR_WARNING 0x00000001 /* warn only: no further action */
70 #define ERR_NONFATAL 0x00000002 /* terminate assembly after phase */
71 #define ERR_FATAL 0x00000006 /* instantly fatal: exit with error */
72 #define ERR_PANIC 0x00000007 /* internal error: panic instantly
73 * and dump core for reference */
74 #define ERR_MASK 0x00000007 /* mask off the above codes */
75 #define ERR_NOFILE 0x00000010 /* don't give source file name/line */
76 #define ERR_TOPFILE 0x00000020 /* give the top input file name only */
77 #define ERR_USAGE 0x00000040 /* print a usage message */
78 #define ERR_PASS1 0x00000080 /* only print this error on pass one */
79 #define ERR_PASS2 0x00000100 /* only print this error on pass one */
81 #define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */
82 #define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */
83 #define ERR_PP_LISTMACRO 0x00000800 /* from preproc->error_list_macros() */
86 * These codes define specific types of suppressible warning.
89 #define ERR_WARN_MASK 0xFFFFF000 /* the mask for this feature */
90 #define ERR_WARN_SHR 12 /* how far to shift right */
92 #define WARN(x) ((x) << ERR_WARN_SHR)
93 #define WARN_IDX(x) (((x) & ERR_WARN_MASK) >> ERR_WARN_SHR)
95 #define ERR_WARN_OTHER WARN( 0) /* any noncategorized warning */
96 #define ERR_WARN_MNP WARN( 1) /* macro-num-parameters warning */
97 #define ERR_WARN_MSR WARN( 2) /* macro self-reference */
98 #define ERR_WARN_MDP WARN( 3) /* macro default parameters check */
99 #define ERR_WARN_OL WARN( 4) /* orphan label (no colon, and
100 * alone on line) */
101 #define ERR_WARN_NOV WARN( 5) /* numeric overflow */
102 #define ERR_WARN_GNUELF WARN( 6) /* using GNU ELF extensions */
103 #define ERR_WARN_FL_OVERFLOW WARN( 7) /* FP overflow */
104 #define ERR_WARN_FL_DENORM WARN( 8) /* FP denormal */
105 #define ERR_WARN_FL_UNDERFLOW WARN( 9) /* FP underflow */
106 #define ERR_WARN_FL_TOOLONG WARN(10) /* FP too many digits */
107 #define ERR_WARN_USER WARN(11) /* %warning directives */
108 #define ERR_WARN_LOCK WARN(12) /* bad LOCK prefixes */
109 #define ERR_WARN_HLE WARN(13) /* bad HLE prefixes */
110 #define ERR_WARN_BND WARN(14) /* bad BND prefixes */
111 #define ERR_WARN_ZEXTRELOC WARN(15) /* relocation zero-extended */
112 #define ERR_WARN_PTR WARN(16) /* not a NASM keyword */
113 #define ERR_WARN_BAD_PRAGMA WARN(17) /* malformed pragma */
114 #define ERR_WARN_UNKNOWN_PRAGMA WARN(18) /* unknown pragma */
115 #define ERR_WARN_NOTMY_PRAGMA WARN(19) /* pragma inapplicable */
116 #define ERR_WARN_UNK_WARNING WARN(20) /* unknown warning */
117 #define ERR_WARN_NEG_REP WARN(21) /* negative repeat count */
118 #define ERR_WARN_PHASE WARN(22) /* phase error in pass 1 */
120 /* The "all" warning acts as a global switch, it must come last */
121 #define ERR_WARN_ALL 23 /* Do not use WARN() here */
123 struct warning {
124 const char *name;
125 const char *help;
126 bool enabled;
128 extern const struct warning warnings[ERR_WARN_ALL+1];
130 /* This is a bitmask */
131 #define WARN_ST_ENABLED 1 /* Warning is currently enabled */
132 #define WARN_ST_ERROR 2 /* Treat this warning as an error */
134 extern uint8_t warning_state[ERR_WARN_ALL];
135 extern uint8_t warning_state_init[ERR_WARN_ALL];
137 /* Process a warning option or directive */
138 bool set_warning_status(const char *);
140 #endif /* NASM_ERROR_H */