1 /*****************************************************************************/
5 /* Error handling for the ca65 macroassembler */
9 /* (C) 1998-2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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] = {
76 { 2, "Symbol `%s' is defined but never used" },
77 { 2, "Symbol `%s' is imported but never used" },
78 { 1, "Cannot track processor status byte" },
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 "Include nesting too deep",
128 "Invalid input character: %02X",
129 "Hex digit expected",
131 "`0' or `1' expected",
132 "Numerical overflow",
133 "Control statement expected",
134 "Too many characters",
140 "Boolean switch value expected (on/off/+/-)",
143 "Integer constant expected",
144 "String constant expected",
145 "Character constant expected",
146 "Constant expression expected",
147 "Identifier expected",
148 "`.endmacro' expected",
149 "Option key expected",
150 "Command is only valid in 65816 mode",
152 "String constant too long",
153 "Newline in string constant",
154 "Illegal character constant",
155 "Illegal addressing mode",
156 "Illegal character to start local symbols",
157 "Illegal use of local symbol",
158 "Illegal segment name: `%s'",
159 "Illegal segment attribute",
160 "Illegal macro package name",
161 "Illegal emulation feature",
163 "Symbol `%s' is already defined",
164 "Undefined symbol `%s'",
165 "Symbol `%s' is marked as import",
166 "Symbol `%s' is marked as export",
167 "Exported symbol `%s' is undefined",
168 "Exported values must be constant",
169 ".IF nesting too deep",
170 "Unexpected end of file",
171 "Unexpected end of line",
174 "Modulo operation with zero",
176 "Too many macro parameters",
177 "Macro parameter expected",
178 "Circular reference in symbol definition",
179 "Symbol redeclaration mismatch",
180 "Alignment value must be a power of 2",
182 "Conditional assembly branch was never closed",
183 "Lexical level was not terminated correctly",
184 "Segment attribute mismatch",
189 "File name `%s' not found in file table",
192 fprintf (stderr, "%s(%lu): Error #%u: ",
193 GetFileName (Pos->Name), Pos->Line, ErrNum);
194 vfprintf (stderr, Msgs [ErrNum-1], ap);
195 fprintf (stderr, "\n");
201 void Error (unsigned ErrNum, ...)
202 /* Print an error message */
205 va_start (ap, ErrNum);
206 ErrorMsg (&CurPos, ErrNum, ap);
212 void PError (const FilePos* Pos, unsigned ErrNum, ...)
213 /* Print an error message giving an explicit file and position. */
216 va_start (ap, ErrNum);
217 ErrorMsg (Pos, ErrNum, ap);
223 void ErrorSkip (unsigned ErrNum, ...)
224 /* Print an error message and skip the rest of the line */
227 va_start (ap, ErrNum);
228 ErrorMsg (&CurPos, ErrNum, ap);
236 /*****************************************************************************/
238 /*****************************************************************************/
242 void Fatal (unsigned FatNum, ...)
243 /* Print a message about a fatal error and die */
245 static const char* Msgs [FAT_COUNT-1] = {
246 "Maximum number of input files reached",
250 "Cannot open input file `%s': %s",
251 "Cannot stat input file `%s': %s",
252 "Cannot open output file `%s': %s",
253 "Cannot write to output file `%s': %s",
254 "Cannot open listing file: %s",
255 "Cannot write to listing file: %s",
256 "Cannot read from listing file: %s",
257 "Too many nested constructs",
262 va_start (ap, FatNum);
263 fprintf (stderr, "Fatal #%u: ", FatNum);
264 vfprintf (stderr, Msgs [FatNum-1], ap);
265 fprintf (stderr, "\n");
274 void Internal (const char* Format, ...)
275 /* Print a message about an internal compiler error and die. */
278 va_start (ap, Format);
279 fprintf (stderr, "Internal assembler error\n");
280 vfprintf (stderr, Format, ap);
282 fprintf (stderr, "\n");