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, "User warning: %s" },
82 if (Warnings [WarnNum-1].Level <= WarnLevel) {
83 fprintf (stderr, "%s(%lu): Warning #%u: ",
84 GetFileName (Pos->Name), Pos->Line, WarnNum);
85 vfprintf (stderr, Warnings [WarnNum-1].Msg, ap);
86 fprintf (stderr, "\n");
93 void Warning (unsigned WarnNum, ...)
94 /* Print warning message. */
97 va_start (ap, WarnNum);
98 WarningMsg (&CurPos, WarnNum, ap);
104 void PWarning (const FilePos* Pos, unsigned WarnNum, ...)
105 /* Print warning message giving an explicit file and position. */
108 va_start (ap, WarnNum);
109 WarningMsg (Pos, WarnNum, ap);
115 /*****************************************************************************/
117 /*****************************************************************************/
121 void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap)
122 /* Print an error message */
124 static const char* Msgs [ERR_COUNT-1] = {
125 "Command/operation not implemented",
126 "Cannot open include file `%s': %s",
127 "Cannot read from include file `%s': %s",
128 "Include nesting too deep",
129 "Invalid input character: %02X",
130 "Hex digit expected",
132 "`0' or `1' expected",
133 "Numerical overflow",
134 "Control statement expected",
135 "Too many characters",
141 "Boolean switch value expected (on/off/+/-)",
144 "Integer constant expected",
145 "String constant expected",
146 "Character constant expected",
147 "Constant expression expected",
148 "Identifier expected",
149 "`.ENDMACRO' expected",
150 "Option key expected",
152 "Command is only valid in 65816 mode",
154 "String constant too long",
155 "Newline in string constant",
156 "Illegal character constant",
157 "Illegal addressing mode",
158 "Illegal character to start local symbols",
159 "Illegal use of local symbol",
160 "Illegal segment name: `%s'",
161 "Illegal segment attribute",
162 "Illegal macro package name",
163 "Illegal emulation feature",
164 "Illegal scope specifier",
165 "Illegal assert action",
167 "Symbol `%s' is already defined",
168 "Undefined symbol `%s'",
169 "Symbol `%s' is already marked as import",
170 "Symbol `%s' is already marked as export",
171 "Exported symbol `%s' is undefined",
172 "Exported values must be constant",
173 "Unexpected end of file",
174 "Unexpected end of line",
177 "Modulo operation with zero",
179 "Too many macro parameters",
180 "Macro parameter expected",
181 "Circular reference in symbol definition",
182 "Symbol `%s' redeclaration mismatch",
183 "Alignment value must be a power of 2",
185 "Conditional assembly branch was never closed",
186 "Lexical level was not terminated correctly",
187 "No open lexical level",
188 "Segment attribute mismatch",
189 "Segment stack overflow",
190 "Segment stack is empty",
191 "Segment stack is not empty at end of assembly",
196 "File name `%s' not found in file table",
199 fprintf (stderr, "%s(%lu): Error #%u: ",
200 GetFileName (Pos->Name), Pos->Line, ErrNum);
201 vfprintf (stderr, Msgs [ErrNum-1], ap);
202 fprintf (stderr, "\n");
208 void Error (unsigned ErrNum, ...)
209 /* Print an error message */
212 va_start (ap, ErrNum);
213 ErrorMsg (&CurPos, ErrNum, ap);
219 void PError (const FilePos* Pos, unsigned ErrNum, ...)
220 /* Print an error message giving an explicit file and position. */
223 va_start (ap, ErrNum);
224 ErrorMsg (Pos, ErrNum, ap);
230 void ErrorSkip (unsigned ErrNum, ...)
231 /* Print an error message and skip the rest of the line */
234 va_start (ap, ErrNum);
235 ErrorMsg (&CurPos, ErrNum, ap);
243 /*****************************************************************************/
245 /*****************************************************************************/
249 void Fatal (unsigned FatNum, ...)
250 /* Print a message about a fatal error and die */
252 static const char* Msgs [FAT_COUNT-1] = {
253 "Maximum number of input files reached",
257 "Cannot open input file `%s': %s",
258 "Cannot stat input file `%s': %s",
259 "Cannot open output file `%s': %s",
260 "Cannot write to output file `%s': %s",
261 "Cannot open listing file: %s",
262 "Cannot write to listing file: %s",
263 "Cannot read from listing file: %s",
264 "Too many nested constructs",
265 ".IF nesting too deep",
270 va_start (ap, FatNum);
271 fprintf (stderr, "Fatal #%u: ", FatNum);
272 vfprintf (stderr, Msgs [FatNum-1], ap);
273 fprintf (stderr, "\n");
282 void Internal (const char* Format, ...)
283 /* Print a message about an internal compiler error and die. */
286 va_start (ap, Format);
287 fprintf (stderr, "Internal assembler error\n");
288 vfprintf (stderr, Format, ap);
290 fprintf (stderr, "\n");