4 * Copyright (C) 1989-2021 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 * The module assubr.c contains the error
31 * processing routines.
33 * assubr.c contains the following functions:
42 * assubr.c contains the local array of *error[]
45 /*)Function VOID err(c)
47 * int c error type character
49 * The legacy function err() reports errors using
50 * the default error descriptions by calling xerr()
54 * VOID xerr() assubr.c
57 * The error code may be inserted into the
58 * error code array eb[].
67 /*)Function VOID xerr(c, str)
69 * int c error type character
70 * char * str the error message string
72 * The function xerr() logs the error code character
73 * suppressing duplicate errors. If the error code
74 * is 'q' then the parse of the current assembler-source
75 * text line is terminated.
78 * char * p pointer to the error array
81 * int aserr error counter
82 * char eb[] array of generated error codes
83 * char * ex[] array of error string pointers
86 * VOID longjmp() c_library
89 * The error code may be inserted into the
90 * error code array eb[], a pointer to the
91 * optional error message inserted into the
92 * array ex[], or the parse terminated.
96 xerr(int c
, char *str
)
106 ex
[(int) (p
-eb
)] = str
;
111 longjmp(jump_env
, -1);
114 /*)Function VOID diag()
116 * The function diag() prints any error codes and
117 * the source line number to the stderr output device.
120 * char * p pointer to error code array eb[]
123 * char eb[] array of generated error codes
124 * char * ep pointer into error list
125 * int incline include file line number
126 * char afn[] afile() constructed filespec
127 * FILE * stderr c_library
130 * int fprintf() c_library
131 * char * geterr() assubr.c
132 * int getlnm() assubr.c
135 * Error strings output to stderr.
148 fprintf(fp
, "?ASxxxx-Error-<");
150 fprintf(fp
, "%c", *p
);
153 fprintf(fp
, "> in line ");
154 fprintf(fp
, "%d", getlnm());
155 fprintf(fp
, " of %s\n", afn
);
159 if ((ex
[(int) (p
-eb
)] != NULL
) && (*ex
[(int) (p
-eb
)] != 0)) {
161 fprintf(fp
, " <%c> %s\n", *p
, ex
[(int) (p
-eb
)]);
163 /* Modified to conform to gcc error standard, basxto, 24 Mar '22. */
164 fprintf(stderr
, "%s:", afn
);
165 fprintf(stderr
, "%d: Error:", getlnm());
166 fprintf(stderr
, " <%c> %s\n", *p
, ex
[(int) (p
-eb
)]);
169 if ((errstr
= geterr(*p
)) != NULL
) {
171 fprintf(fp
, " %s\n", errstr
);
173 /* Modified to conform to gcc error standard, M. Hope, 7 Feb 98. */
174 fprintf(stderr
, "%s:", afn
);
175 fprintf(stderr
, "%d: Error:", getlnm());
176 fprintf(stderr
, " %s\n", errstr
);
186 /*)Function VOID warnBanner()
188 * The function warnBanner() prints a generic warning message
189 * header (including the current source file/line) and positions
190 * the output for a more specific warning message.
192 * It is assumed that the call to warnBanner will be followed with
193 * a fprintf to stderr (or equivalent) with the specific warning
200 * char afn[] afile() constructed filespec
201 * FILE * stderr c_library
204 * int fprintf() c_library
205 * int getlnm() assubr.c
213 fprintf(stderr
, "?ASxxxx-Warning in line ");
214 fprintf(stderr
, "%d", getlnm());
215 fprintf(stderr
, " of %s\n", afn
);
216 fprintf(stderr
, " ");
218 /* end sdas specific */
220 /*)Functions: VOID aerr()
224 * The functions aerr(), qerr(), and rerr() report their
225 * respective error type. These are included only for
235 * VOID err() assubr.c
238 * The appropriate error code is inserted into the
239 * error array and the parse may be terminated.
270 * Default ASxxxx assembler errors
273 "<.> use \". = . + <arg>\" not \". = <arg>\"",
274 "<a> machine specific addressing or addressing mode error",
275 "<b> address / direct page boundary error",
276 "<c> .bndry offset error",
277 "<d> direct page addressing error",
278 "<e> .error/.assume programmed error",
279 "<i> .include/.incbin file error or an .if/.endif mismatch",
280 "<k> numerical conversion error",
281 "<m> multiple definitions error or macro recursion error",
282 "<n> .endm, .mexit, or .narg outside of a macro",
283 "<o> .org in REL area or directive / mnemonic error",
284 "<p> phase error: label location changing between passes 2 and 3",
285 "<q> missing or improper operators, terminators, or delimiters",
286 "<r> relocation error",
287 "<s> string substitution / recursion error",
288 "<u> undefined symbol encountered during assembly",
289 "<v> out of range signed / unsigned value",
290 "<z> divide by zero or mod of zero error",
294 /*)Function: char *geterr(c)
296 * int c the error code character
298 * The function geterr() scans the list of errors returning the
299 * error string corresponding to the input error character.
302 * int i error index counter
305 * char *errors[] array of pointers to the
307 * char erb[] Error string buffer
313 * A pointer to the appropriate
314 * error code string is returned.
321 for (i
=0; errors
[i
]!=NULL
; i
++) {
322 if (c
== errors
[i
][1]) {
326 sprintf(erb
, "<e> %.*s", (int) (sizeof(erb
)-5), ib
);