Mercurial > repo
comparison nasmbuild/nasm-2.13rc9/asm/error.c @ 10554:587a0a262d22
<moonythedwarf> ` cd nasmbuild; tar -xf nasm.tar.gz
author | HackBot |
---|---|
date | Thu, 30 Mar 2017 20:58:41 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
10553:93dc2a984de0 | 10554:587a0a262d22 |
---|---|
1 /* ----------------------------------------------------------------------- * | |
2 * | |
3 * Copyright 1996-2017 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.c - error message handling routines for the assembler | |
36 */ | |
37 | |
38 #include "compiler.h" | |
39 | |
40 #include <stdlib.h> | |
41 | |
42 #include "nasmlib.h" | |
43 #include "error.h" | |
44 | |
45 /* | |
46 * Description of the suppressible warnings for the command line and | |
47 * the [warning] directive. | |
48 */ | |
49 const struct warning warnings[ERR_WARN_ALL+1] = { | |
50 {"other", "any warning not specifially mentioned below", true}, | |
51 {"macro-params", "macro calls with wrong parameter count", true}, | |
52 {"macro-selfref", "cyclic macro references", false}, | |
53 {"macro-defaults", "macros with more default than optional parameters", true}, | |
54 {"orphan-labels", "labels alone on lines without trailing `:'", true}, | |
55 {"number-overflow", "numeric constant does not fit", true}, | |
56 {"gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false}, | |
57 {"float-overflow", "floating point overflow", true}, | |
58 {"float-denorm", "floating point denormal", false}, | |
59 {"float-underflow", "floating point underflow", false}, | |
60 {"float-toolong", "too many digits in floating-point number", true}, | |
61 {"user", "%warning directives", true}, | |
62 {"lock", "lock prefix on unlockable instructions", true}, | |
63 {"hle", "invalid hle prefixes", true}, | |
64 {"bnd", "invalid bnd prefixes", true}, | |
65 {"zext-reloc", "relocation zero-extended to match output format", true}, | |
66 {"ptr", "non-NASM keyword used in other assemblers", true}, | |
67 {"bad-pragma", "empty or malformed %pragma", false}, | |
68 {"unknown-pragma", "unknown %pragma facility or directive", false}, | |
69 {"not-my-pragma", "%pragma not applicable to this compilation", false}, | |
70 {"unknown-warning", "unknown warning in -W/-w or warning directive", false}, | |
71 | |
72 /* THIS ENTRY MUST COME LAST */ | |
73 {"all", "all possible warnings", false} | |
74 }; | |
75 | |
76 uint8_t warning_state[ERR_WARN_ALL];/* Current state */ | |
77 uint8_t warning_state_init[ERR_WARN_ALL]; /* Command-line state, for reset */ | |
78 | |
79 vefunc nasm_verror; /* Global error handling function */ | |
80 | |
81 void nasm_error(int severity, const char *fmt, ...) | |
82 { | |
83 va_list ap; | |
84 | |
85 va_start(ap, fmt); | |
86 nasm_verror(severity, fmt, ap); | |
87 va_end(ap); | |
88 } | |
89 | |
90 no_return nasm_fatal(int flags, const char *fmt, ...) | |
91 { | |
92 va_list ap; | |
93 | |
94 va_start(ap, fmt); | |
95 nasm_verror(flags | ERR_FATAL, fmt, ap); | |
96 abort(); /* We should never get here */ | |
97 } | |
98 | |
99 no_return nasm_panic(int flags, const char *fmt, ...) | |
100 { | |
101 va_list ap; | |
102 | |
103 va_start(ap, fmt); | |
104 nasm_verror(flags | ERR_PANIC, fmt, ap); | |
105 abort(); /* We should never get here */ | |
106 } | |
107 | |
108 no_return nasm_panic_from_macro(const char *file, int line) | |
109 { | |
110 nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", file, line); | |
111 } | |
112 | |
113 no_return nasm_assert_failed(const char *file, int line, const char *msg) | |
114 { | |
115 nasm_panic(0, "assertion %s failed at %s:%d", msg, file, line); | |
116 } | |
117 | |
118 /* | |
119 * This is called when processing a -w or -W option, or a warning directive. | |
120 * Returns true if if the action was successful. | |
121 */ | |
122 bool set_warning_status(const char *value) | |
123 { | |
124 enum warn_action { WID_OFF, WID_ON, WID_RESET }; | |
125 enum warn_action action; | |
126 uint8_t mask; | |
127 int i; | |
128 bool ok = false; | |
129 | |
130 value = nasm_skip_spaces(value); | |
131 switch (*value) { | |
132 case '-': | |
133 action = WID_OFF; | |
134 value++; | |
135 break; | |
136 case '+': | |
137 action = WID_ON; | |
138 value++; | |
139 break; | |
140 case '*': | |
141 action = WID_RESET; | |
142 value++; | |
143 break; | |
144 case 'N': | |
145 case 'n': | |
146 if (!nasm_strnicmp(value, "no-", 3)) { | |
147 action = WID_OFF; | |
148 value += 3; | |
149 break; | |
150 } else if (!nasm_stricmp(value, "none")) { | |
151 action = WID_OFF; | |
152 value = NULL; | |
153 break; | |
154 } | |
155 /* else fall through */ | |
156 default: | |
157 action = WID_ON; | |
158 break; | |
159 } | |
160 | |
161 mask = WARN_ST_ENABLED; | |
162 | |
163 if (value && !nasm_strnicmp(value, "error", 5)) { | |
164 switch (value[5]) { | |
165 case '=': | |
166 mask = WARN_ST_ERROR; | |
167 value += 6; | |
168 break; | |
169 case '\0': | |
170 mask = WARN_ST_ERROR; | |
171 value = NULL; | |
172 break; | |
173 default: | |
174 /* Just an accidental prefix? */ | |
175 break; | |
176 } | |
177 } | |
178 | |
179 if (value && !nasm_stricmp(value, "all")) | |
180 value = NULL; | |
181 | |
182 /* This is inefficient, but it shouldn't matter... */ | |
183 for (i = 0; i < ERR_WARN_ALL; i++) { | |
184 if (!value || !nasm_stricmp(value, warnings[i].name)) { | |
185 ok = true; /* At least one action taken */ | |
186 switch (action) { | |
187 case WID_OFF: | |
188 warning_state[i] &= ~mask; | |
189 break; | |
190 case WID_ON: | |
191 warning_state[i] |= mask; | |
192 break; | |
193 case WID_RESET: | |
194 warning_state[i] &= ~mask; | |
195 warning_state[i] |= warning_state_init[i] & mask; | |
196 break; | |
197 } | |
198 } | |
199 } | |
200 | |
201 return ok; | |
202 } |