1 | /* ----------------------------------------------------------------------- * |
2 | * |
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. |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following |
9 | * conditions are met: |
10 | * |
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. |
17 | * |
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. |
31 | * |
32 | * ----------------------------------------------------------------------- */ |
33 | |
34 | /* |
35 | * Error reporting functions for the assembler |
36 | */ |
37 | |
38 | #ifndef NASM_ERROR_H |
39 | #define NASM_ERROR_H 1 |
40 | |
41 | #include "compiler.h" |
42 | |
43 | /* |
44 | * File pointer for error messages |
45 | */ |
46 | extern FILE *error_file; /* Error file descriptor */ |
47 | |
48 | /* |
49 | * An error reporting function should look like this. |
50 | */ |
51 | void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...); |
52 | fatal_func printf_func(2, 3) nasm_fatal(int flags, const char *fmt, ...); |
53 | fatal_func printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...); |
54 | fatal_func nasm_panic_from_macro(const char *file, int line); |
55 | #define panic() nasm_panic_from_macro(__FILE__, __LINE__); |
56 | |
57 | typedef void (*vefunc) (int severity, const char *fmt, va_list ap); |
58 | extern vefunc nasm_verror; |
59 | static inline vefunc nasm_set_verror(vefunc ve) |
60 | { |
61 | vefunc old_verror = nasm_verror; |
62 | nasm_verror = ve; |
63 | return old_verror; |
64 | } |
65 | |
66 | /* |
67 | * These are the error severity codes which get passed as the first |
68 | * argument to an efunc. |
69 | */ |
70 | |
71 | #define ERR_DEBUG 0x00000000 /* put out debugging message */ |
72 | #define ERR_NOTE 0x00000001 /* additional error information */ |
73 | #define ERR_WARNING 0x00000002 /* warn only: no further action */ |
74 | #define ERR_NONFATAL 0x00000003 /* terminate assembly after phase */ |
75 | #define ERR_FATAL 0x00000006 /* instantly fatal: exit with error */ |
76 | #define ERR_PANIC 0x00000007 /* internal error: panic instantly |
77 | * and dump core for reference */ |
78 | #define ERR_MASK 0x00000007 /* mask off the above codes */ |
79 | #define ERR_NOFILE 0x00000010 /* don't give source file name/line */ |
80 | #define ERR_HERE 0x00000020 /* point to a specific source location */ |
81 | #define ERR_USAGE 0x00000040 /* print a usage message */ |
82 | #define ERR_PASS1 0x00000080 /* only print this error on pass 1 */ |
83 | #define ERR_PASS2 0x00000100 /* only print this error on pass 2 */ |
84 | |
85 | #define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */ |
86 | #define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */ |
87 | #define ERR_PP_LISTMACRO 0x00000800 /* from preproc->error_list_macros() */ |
88 | |
89 | /* |
90 | * These codes define specific types of suppressible warning. |
91 | * They are assumed to occupy the most significant bits of the |
92 | * severity code. |
93 | */ |
94 | |
95 | #define WARN_SHR 12 /* how far to shift right */ |
96 | #define WARN(x) ((x) << WARN_SHR) |
97 | #define WARN_MASK WARN(~0) |
98 | #define WARN_IDX(x) ((x) >> WARN_SHR) |
99 | |
100 | #define WARN_MNP WARN( 1) /* macro-num-parameters warning */ |
101 | #define WARN_MSR WARN( 2) /* macro self-reference */ |
102 | #define WARN_MDP WARN( 3) /* macro default parameters check */ |
103 | #define WARN_OL WARN( 4) /* orphan label (no colon, and alone on line) */ |
104 | #define WARN_NOV WARN( 5) /* numeric overflow */ |
105 | #define WARN_GNUELF WARN( 6) /* using GNU ELF extensions */ |
106 | #define WARN_FL_OVERFLOW WARN( 7) /* FP overflow */ |
107 | #define WARN_FL_DENORM WARN( 8) /* FP denormal */ |
108 | #define WARN_FL_UNDERFLOW WARN( 9) /* FP underflow */ |
109 | #define WARN_FL_TOOLONG WARN(10) /* FP too many digits */ |
110 | #define WARN_USER WARN(11) /* %warning directives */ |
111 | #define WARN_LOCK WARN(12) /* bad LOCK prefixes */ |
112 | #define WARN_HLE WARN(13) /* bad HLE prefixes */ |
113 | #define WARN_BND WARN(14) /* bad BND prefixes */ |
114 | #define WARN_ZEXTRELOC WARN(15) /* relocation zero-extended */ |
115 | #define WARN_PTR WARN(16) /* not a NASM keyword */ |
116 | #define WARN_BAD_PRAGMA WARN(17) /* malformed pragma */ |
117 | #define WARN_UNKNOWN_PRAGMA WARN(18) /* unknown pragma */ |
118 | #define WARN_NOTMY_PRAGMA WARN(19) /* pragma inapplicable */ |
119 | #define WARN_UNK_WARNING WARN(20) /* unknown warning */ |
120 | #define WARN_NEG_REP WARN(21) /* negative repeat count */ |
121 | #define WARN_PHASE WARN(22) /* phase error in pass 1 */ |
122 | #define WARN_LABEL_REDEF WARN(23) /* label redefined, but consistent */ |
123 | #define WARN_LABEL_LATE WARN(24) /* label (re)defined during code generation */ |
124 | |
125 | /* These two should come last */ |
126 | #define WARN_ALL (24+2) /* Do not use WARN() here */ |
127 | #define WARN_OTHER WARN(WARN_ALL-1) /* any noncategorized warning */ |
128 | |
129 | /* This is a bitmask */ |
130 | #define WARN_ST_ENABLED 1 /* Warning is currently enabled */ |
131 | #define WARN_ST_ERROR 2 /* Treat this warning as an error */ |
132 | |
133 | struct warning { |
134 | const char *name; |
135 | const char *help; |
136 | uint8_t state; /* Default state for this warning */ |
137 | }; |
138 | extern const struct warning warnings[WARN_ALL+1]; |
139 | extern uint8_t warning_state[WARN_ALL]; |
140 | extern uint8_t warning_state_init[WARN_ALL]; |
141 | |
142 | /* Process a warning option or directive */ |
143 | bool set_warning_status(const char *); |
144 | |
145 | #endif /* NASM_ERROR_H */ |
146 | |