1 /*****************************************************************************/
5 /* Error handling for the ca65 macroassembler */
9 /* (C) 1998-2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
47 /*****************************************************************************/
49 /*****************************************************************************/
54 unsigned WarnLevel = 1;
57 unsigned ErrorCount = 0;
58 unsigned WarningCount = 0;
62 /*****************************************************************************/
64 /*****************************************************************************/
68 void WarningMsg (const FilePos* Pos, unsigned WarnNum, va_list ap)
69 /* Print warning message. */
74 } Warnings [WARN_COUNT-1] = {
75 { 2, "Symbol `%s' is defined but never used" },
76 { 2, "Symbol `%s' is imported but never used" },
77 { 1, "Cannot track processor status byte" },
78 { 1, "Suspicious address expression" },
79 { 0, "Unnamed .PROCs are deprecated, please use .SCOPE" },
80 { 1, "Address size mismatch for symbol `%s'" },
81 { 0, "User warning: %s" },
84 if (Warnings [WarnNum-1].Level <= WarnLevel) {
85 fprintf (stderr, "%s(%lu): Warning #%u: ",
86 GetFileName (Pos->Name), Pos->Line, WarnNum);
87 vfprintf (stderr, Warnings [WarnNum-1].Msg, ap);
88 fprintf (stderr, "\n");
95 void Warning (unsigned WarnNum, ...)
96 /* Print warning message. */
99 va_start (ap, WarnNum);
100 WarningMsg (&CurPos, WarnNum, ap);
106 void PWarning (const FilePos* Pos, unsigned WarnNum, ...)
107 /* Print warning message giving an explicit file and position. */
110 va_start (ap, WarnNum);
111 WarningMsg (Pos, WarnNum, ap);
117 /*****************************************************************************/
119 /*****************************************************************************/
123 void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap)
124 /* Print an error message */
126 static const char* Msgs [ERR_COUNT-1] = {
127 "Command/operation not implemented",
128 "Cannot open include file `%s': %s",
129 "Cannot read from include file `%s': %s",
130 "Include nesting too deep",
131 "Invalid input character: %02X",
132 "Hex digit expected",
134 "`0' or `1' expected",
135 "Numerical overflow",
136 "Control statement expected",
137 "Too many characters",
143 "Boolean switch value expected (on/off/+/-)",
146 "Integer constant expected",
147 "String constant expected",
148 "Character constant expected",
149 "Constant expression expected",
150 "Identifier expected",
151 "`.ENDMACRO' expected",
152 "Option key expected",
154 "Address size specifier expected",
155 "Command is only valid in 65816 mode",
157 "String constant too long",
158 "Newline in string constant",
159 "Illegal character constant",
160 "Illegal addressing mode",
161 "Illegal character to start local symbols",
162 "Illegal use of local symbol",
163 "Illegal segment name: `%s'",
164 "Illegal macro package name",
165 "Illegal emulation feature",
166 "Illegal scope specifier",
167 "Illegal assert action",
169 "Symbol `%s' is already defined",
170 "Undefined symbol `%s'",
171 "Symbol `%s' is already marked as import",
172 "Symbol `%s' is already marked as export",
173 "Exported symbol `%s' is undefined",
174 "Exported values must be constant",
175 "Unexpected end of file",
176 "Unexpected end of line",
179 "Modulo operation with zero",
181 "Too many macro parameters",
182 "Macro parameter expected",
183 "Circular reference in symbol definition",
184 "Symbol `%s' redeclaration mismatch",
185 "Address size mismatch for symbol `%s'",
186 "Alignment value must be a power of 2",
188 "Conditional assembly branch was never closed",
189 "Lexical level was not terminated correctly",
190 "No open lexical level",
191 "Segment attribute mismatch",
192 "Segment stack overflow",
193 "Segment stack is empty",
194 "Segment stack is not empty at end of assembly",
199 "File name `%s' not found in file table",
202 fprintf (stderr, "%s(%lu): Error #%u: ",
203 GetFileName (Pos->Name), Pos->Line, ErrNum);
204 vfprintf (stderr, Msgs [ErrNum-1], ap);
205 fprintf (stderr, "\n");
211 void Error (unsigned ErrNum, ...)
212 /* Print an error message */
215 va_start (ap, ErrNum);
216 ErrorMsg (&CurPos, ErrNum, ap);
222 void PError (const FilePos* Pos, unsigned ErrNum, ...)
223 /* Print an error message giving an explicit file and position. */
226 va_start (ap, ErrNum);
227 ErrorMsg (Pos, ErrNum, ap);
233 void ErrorSkip (unsigned ErrNum, ...)
234 /* Print an error message and skip the rest of the line */
237 va_start (ap, ErrNum);
238 ErrorMsg (&CurPos, ErrNum, ap);
246 /*****************************************************************************/
248 /*****************************************************************************/
252 void Fatal (unsigned FatNum, ...)
253 /* Print a message about a fatal error and die */
255 static const char* Msgs [FAT_COUNT-1] = {
256 "Maximum number of input files reached",
260 "Cannot open input file `%s': %s",
261 "Cannot stat input file `%s': %s",
262 "Cannot open output file `%s': %s",
263 "Cannot write to output file `%s': %s",
264 "Cannot open listing file: %s",
265 "Cannot write to listing file: %s",
266 "Cannot read from listing file: %s",
267 "Too many nested constructs",
268 ".IF nesting too deep",
273 va_start (ap, FatNum);
274 fprintf (stderr, "Fatal #%u: ", FatNum);
275 vfprintf (stderr, Msgs [FatNum-1], ap);
276 fprintf (stderr, "\n");
285 void Internal (const char* Format, ...)
286 /* Print a message about an internal compiler error and die. */
289 va_start (ap, Format);
290 fprintf (stderr, "Internal assembler error\n");
291 vfprintf (stderr, Format, ap);
293 fprintf (stderr, "\n");