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 /*****************************************************************************/
45 /*****************************************************************************/
47 /*****************************************************************************/
52 unsigned WarnLevel = 1;
54 /* Messages for internal compiler errors */
55 const char _MsgCheckFailed [] =
56 "Check failed: `%s' (= %d), file `%s', line %u\n";
57 const char _MsgPrecondition [] =
58 "Precondition violated: `%s' (= %d), file `%s', line %u\n";
59 const char _MsgFail [] =
60 "%s, file `%s', line %u\n";
64 unsigned ErrorCount = 0;
65 unsigned WarningCount = 0;
69 /*****************************************************************************/
71 /*****************************************************************************/
75 void WarningMsg (const FilePos* Pos, unsigned WarnNum, va_list ap)
76 /* Print warning message. */
81 } Warnings [WARN_COUNT-1] = {
83 { 2, "Symbol `%s' is defined but never used" },
84 { 2, "Symbol `%s' is imported but never used" },
85 { 1, "Cannot track processor status byte" },
86 { 0, "User warning: %s" },
89 if (Warnings [WarnNum-1].Level <= WarnLevel) {
90 fprintf (stderr, "%s(%lu): Warning #%u: ",
91 GetFileName (Pos->Name), Pos->Line, WarnNum);
92 vfprintf (stderr, Warnings [WarnNum-1].Msg, ap);
93 fprintf (stderr, "\n");
100 void Warning (unsigned WarnNum, ...)
101 /* Print warning message. */
104 va_start (ap, WarnNum);
105 WarningMsg (&CurPos, WarnNum, ap);
111 void PWarning (const FilePos* Pos, unsigned WarnNum, ...)
112 /* Print warning message giving an explicit file and position. */
115 va_start (ap, WarnNum);
116 WarningMsg (Pos, WarnNum, ap);
122 /*****************************************************************************/
124 /*****************************************************************************/
128 void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap)
129 /* Print an error message */
131 static const char* Msgs [ERR_COUNT-1] = {
132 "Command/operation not implemented",
133 "Cannot open include file `%s': %s",
134 "Include nesting too deep",
135 "Invalid input character: %02X",
136 "Hex digit expected",
138 "`0' or `1' expected",
139 "Numerical overflow",
140 "Control statement expected",
141 "Too many characters",
147 "Boolean switch value expected (on/off/+/-)",
150 "Integer constant expected",
151 "String constant expected",
152 "Character constant expected",
153 "Constant expression expected",
154 "Identifier expected",
155 "`.endmacro' expected",
156 "Option key expected",
157 "Command is only valid in 65816 mode",
159 "String constant too long",
160 "Newline in string constant",
161 "Illegal character constant",
162 "Illegal addressing mode",
163 "Illegal character to start local symbols",
164 "Illegal use of local symbol",
165 "Illegal segment name: `%s'",
166 "Illegal segment attribute",
167 "Illegal macro package name",
168 "Illegal emulation feature",
170 "Symbol `%s' is already defined",
171 "Undefined symbol `%s'",
172 "Symbol `%s' is marked as import",
173 "Symbol `%s' is marked as export",
174 "Exported symbol `%s' is undefined",
175 "Exported values must be constant",
176 ".IF nesting too deep",
177 "Unexpected end of file",
178 "Unexpected end of line",
181 "Modulo operation with zero",
183 "Too many macro parameters",
184 "Macro parameter expected",
185 "Circular reference in symbol definition",
186 "Symbol redeclaration mismatch",
187 "Alignment value must be a power of 2",
189 "Conditional assembly branch was never closed",
190 "Lexical level was not terminated correctly",
191 "Segment attribute mismatch",
198 fprintf (stderr, "%s(%lu): Error #%u: ",
199 GetFileName (Pos->Name), Pos->Line, ErrNum);
200 vfprintf (stderr, Msgs [ErrNum-1], ap);
201 fprintf (stderr, "\n");
207 void Error (unsigned ErrNum, ...)
208 /* Print an error message */
211 va_start (ap, ErrNum);
212 ErrorMsg (&CurPos, ErrNum, ap);
218 void PError (const FilePos* Pos, unsigned ErrNum, ...)
219 /* Print an error message giving an explicit file and position. */
222 va_start (ap, ErrNum);
223 ErrorMsg (Pos, ErrNum, ap);
229 void ErrorSkip (unsigned ErrNum, ...)
230 /* Print an error message and skip the rest of the line */
233 va_start (ap, ErrNum);
234 ErrorMsg (&CurPos, ErrNum, ap);
242 /*****************************************************************************/
244 /*****************************************************************************/
248 void Fatal (unsigned FatNum, ...)
249 /* Print a message about a fatal error and die */
251 static const char* Msgs [FAT_COUNT-1] = {
252 "Maximum number of input files reached",
256 "Cannot open input file `%s': %s",
257 "Cannot stat input file `%s': %s",
258 "Cannot open output file `%s': %s",
259 "Cannot write to output file `%s': %s",
260 "Cannot open listing file: %s",
261 "Cannot write to listing file: %s",
262 "Cannot read from listing file: %s",
263 "Too many nested constructs",
268 va_start (ap, FatNum);
269 fprintf (stderr, "Fatal #%u: ", FatNum);
270 vfprintf (stderr, Msgs [FatNum-1], ap);
271 fprintf (stderr, "\n");
280 void Internal (const char* Format, ...)
281 /* Print a message about an internal compiler error and die. */
284 va_start (ap, Format);
285 fprintf (stderr, "Internal assembler error\n");
286 vfprintf (stderr, Format, ap);
288 fprintf (stderr, "\n");