struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / asxxsrc / assubr.c
blob528b503f91b21ba0748e290cc31db1c8af2c05e9
1 /* assubr.c */
3 /*
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/>.
20 * Alan R. Baldwin
21 * 721 Berkeley St.
22 * Kent, Ohio 44240
25 #include "sdas.h"
26 #include "asxxxx.h"
28 /*)Module assubr.c
30 * The module assubr.c contains the error
31 * processing routines.
33 * assubr.c contains the following functions:
34 * VOID aerr()
35 * VOID diag()
36 * VOID err()
37 * VOID qerr()
38 * VOID rerr()
39 * char * geterr()
40 * VOID xerr()
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()
51 * with a NULL string.
53 * functions called:
54 * VOID xerr() assubr.c
56 * side effects:
57 * The error code may be inserted into the
58 * error code array eb[].
61 VOID
62 err(int c)
64 xerr(c, NULL);
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.
77 * local variables:
78 * char * p pointer to the error array
80 * global variables:
81 * int aserr error counter
82 * char eb[] array of generated error codes
83 * char * ex[] array of error string pointers
85 * functions called:
86 * VOID longjmp() c_library
88 * side effects:
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.
95 VOID
96 xerr(int c, char *str)
98 char *p;
100 aserr++;
101 p = eb;
102 while (p < ep)
103 if (*p++ == c)
104 return;
105 if (p < &eb[NERR]) {
106 ex[(int) (p-eb)] = str;
107 *p++ = c;
108 ep = p;
110 if (c == 'q')
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.
119 * local variables:
120 * char * p pointer to error code array eb[]
122 * global variables:
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
129 * functions called:
130 * int fprintf() c_library
131 * char * geterr() assubr.c
132 * int getlnm() assubr.c
134 * side effects:
135 * Error strings output to stderr.
138 VOID
139 diag(void)
141 char *p,*errstr;
142 FILE *fp;
144 fp = stderr;
145 if (eb != ep) {
146 p = eb;
147 if (!is_sdas()) {
148 fprintf(fp, "?ASxxxx-Error-<");
149 while (p < ep) {
150 fprintf(fp, "%c", *p);
151 p++;
153 fprintf(fp, "> in line ");
154 fprintf(fp, "%d", getlnm());
155 fprintf(fp, " of %s\n", afn);
157 p = eb;
158 while (p < ep) {
159 if ((ex[(int) (p-eb)] != NULL) && (*ex[(int) (p-eb)] != 0)) {
160 if (!is_sdas()) {
161 fprintf(fp, " <%c> %s\n", *p, ex[(int) (p-eb)]);
162 } else {
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)]);
168 } else
169 if ((errstr = geterr(*p)) != NULL) {
170 if (!is_sdas()) {
171 fprintf(fp, " %s\n", errstr);
172 } else {
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);
179 p++;
185 /* sdas specific */
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
194 * text.
196 * local variables:
197 * none
199 * global variables:
200 * char afn[] afile() constructed filespec
201 * FILE * stderr c_library
203 * functions called:
204 * int fprintf() c_library
205 * int getlnm() assubr.c
207 * side effects:
208 * none
210 VOID
211 warnBanner(void)
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()
221 * VOID qerr()
222 * VOID rerr()
224 * The functions aerr(), qerr(), and rerr() report their
225 * respective error type. These are included only for
226 * convenience.
228 * local variables:
229 * none
231 * global variables:
232 * none
234 * functions called:
235 * VOID err() assubr.c
237 * side effects:
238 * The appropriate error code is inserted into the
239 * error array and the parse may be terminated.
243 * Note an 'r' error.
245 VOID
246 rerr(void)
248 err('r');
252 * Note an 'a' error.
254 VOID
255 aerr(void)
257 err('a');
261 * Note a 'q' error.
263 VOID
264 qerr(void)
266 err('q');
270 * Default ASxxxx assembler errors
272 char *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",
291 NULL
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.
301 * local variables:
302 * int i error index counter
304 * global variables:
305 * char *errors[] array of pointers to the
306 * error strings
307 * char erb[] Error string buffer
309 * functions called:
310 * none
312 * side effects:
313 * A pointer to the appropriate
314 * error code string is returned.
316 char *
317 geterr(int c)
319 int i;
321 for (i=0; errors[i]!=NULL; i++) {
322 if (c == errors[i][1]) {
323 return(errors[i]);
326 sprintf(erb, "<e> %.*s", (int) (sizeof(erb)-5), ib);
327 return(erb);