Added support for the gb, touched some files in testing the port.
[fw/sdcc] / as / z80 / assubr.c
1 /* assubr.c */
2
3 /*
4  * (C) Copyright 1989-1995
5  * All Rights Reserved
6  *
7  * Alan R. Baldwin
8  * 721 Berkeley St.
9  * Kent, Ohio  44240
10  */
11
12 /*
13  * Extensions: P. Felber, M. Hope
14  */
15
16 #include <stdio.h>
17 #include <setjmp.h>
18 #include <string.h>
19 #include <alloc.h>
20 #include "asm.h"
21
22 /*)Module       assubr.c
23  *
24  *      The module assubr.c contains the error
25  *      processing routines.
26  *
27  *      assubr.c contains the following functions:
28  *              VOID    aerr()
29  *              VOID    diag()
30  *              VOID    err()
31  *              VOID    qerr()
32  *              VOID    rerr()
33  *
34  *      assubr.c contains the local array of *error[]
35  */
36
37 /*)Function     VOID    err(c)
38  *
39  *              int     c               error type character
40  *
41  *      The function err() logs the error code character
42  *      suppressing duplicate errors.  If the error code
43  *      is 'q' then the parse of the current assembler-source
44  *      text line is terminated.
45  *
46  *      local variables:
47  *              char *  p               pointer to the error array
48  *
49  *      global variables:
50  *              char    eb[]            array of generated error codes
51  *
52  *      functions called:
53  *              VOID    longjmp()       c_library
54  *
55  *      side effects:
56  *              The error code may be inserted into the
57  *              error code array eb[] or the parse terminated.
58  */
59
60 VOID
61 err(c)
62 register c;
63 {
64         register char *p;
65
66 #ifndef SDK
67         aserr++;
68 #endif /* SDK */
69         p = eb;
70         while (p < ep)
71                 if (*p++ == c)
72                         return;
73         if (p < &eb[NERR]) {
74                 *p++ = c;
75                 ep = p;
76         }
77         if (c == 'q')
78                 longjmp(jump_env, -1);
79 }
80
81 /*)Function     VOID    diag()
82  *
83  *      The function diag() prints any error codes and
84  *      the source line number to the stderr output device.
85  *
86  *      local variables:
87  *              char *  p               pointer to error code array eb[]
88  *
89  *      global variables:
90  *              int     cfile           current source file index
91  *              char    eb[]            array of generated error codes
92  *              char *  ep              pointer into error list
93  *              int     incfile         current include file index
94  *              char    incfn[]         array of include file names
95  *              int     incline[]       array of include line numbers
96  *              char    srcfn[]         array of source file names
97  *              int     srcline[]       array of source line numbers
98  *              FILE *  stderr          c_library
99  *
100  *      functions called:
101  *              int     fprintf()       c_library
102  *              char *  geterr()        assubr.c
103  *
104  *      side effects:
105  *              none
106  */
107
108 VOID
109 diag()
110 {
111         register char *p,*errstr;
112
113         if (eb != ep) {
114                 p = eb;
115 #ifndef SDK
116                 fprintf(stderr, "?ASxxxx-Error-<");
117                 while (p < ep) {
118                         fprintf(stderr, "%c", *p++);
119                 }
120                 fprintf(stderr, "> in line ");
121                 if (incfil >= 0) {
122                         fprintf(stderr, "%d", incline[incfil]);
123                         fprintf(stderr, " of %s\n", incfn[incfil]);
124                 } else {
125                         fprintf(stderr, "%d", srcline[cfile]);
126                         fprintf(stderr, " of %s\n", srcfn[cfile]);
127                 }
128                 p = eb;
129 #endif /* SDK */
130                 while (p < ep) {
131                         if ((errstr = geterr(*p++)) != NULL) {
132 #ifdef SDK
133                                 /* Modified to conform to gcc error standard, M. Hope, 7 Feb 98. */
134                                 if (incfil >= 0) {
135                                         fprintf(stderr, "%s:", incfn[incfil]);
136                                         fprintf(stderr, "%d: Error:", incline[incfil]);
137                                 }
138                                 else {
139                                         fprintf(stderr, "%s:", srcfn[cfile]);
140                                         fprintf(stderr, "%d: Error:", srcline[cfile]);
141                                 }
142                                 fprintf(stderr, " %s\n", errstr);
143 #else
144                                 fprintf(stderr, "              %s\n", errstr);
145 #endif /* SDK */
146                         }
147                 }
148 #ifdef SDK
149                 aserr++;
150 #endif /* SDK */
151         }
152 }
153
154 /*)Functions:   VOID    aerr()
155  *              VOID    qerr()
156  *              VOID    rerr()
157  *
158  *      The functions aerr(), qerr(), and rerr() report their
159  *      respective error type.  These are included only for
160  *      convenience.
161  *
162  *      local variables:
163  *              none
164  *
165  *      global variables:
166  *              none
167  *
168  *      functions called:
169  *              VOID    err()           assubr.c
170  *
171  *      side effects:
172  *              The appropriate error code is inserted into the
173  *              error array and the parse may be terminated.
174  */
175
176 /*
177  * Note an 'r' error.
178  */
179 VOID
180 rerr()
181 {
182         err('r');
183 }
184
185 /*
186  * Note an 'a' error.
187  */
188 VOID
189 aerr()
190 {
191         err('a');
192 }
193
194 /*
195  * Note a 'q' error.
196  */
197 VOID
198 qerr()
199 {
200         err('q');
201 }
202
203 /*
204  * ASxxxx assembler errors
205  */
206 char *errors[] = {
207         "<.> use \". = . + <arg>\" not \". = <arg>\"",
208         "<a> machine specific addressing or addressing mode error",
209         "<b> direct page boundary error",
210         "<d> direct page addressing error",
211         "<i> .include file error or an .if/.endif mismatch",
212         "<m> multiple definitions error",
213         "<o> .org in REL area or directive / mnemonic error",
214         "<p> phase error: label location changing between passes 2 and 3",
215         "<q> missing or improper operators, terminators, or delimiters",
216         "<r> relocation error",
217         "<u> undefined symbol encountered during assembly",
218         NULL
219 };
220         
221 /*)Function:    char    *getarr(c)
222  *
223  *              int     c               the error code character
224  *
225  *      The function geterr() scans the list of errors returning the
226  *      error string corresponding to the input error character.
227  *
228  *      local variables:
229  *              int     i               error index counter
230  *
231  *      global variables:
232  *              char    *errors[]       array of pointers to the
233  *                                      error strings
234  *
235  *      functions called:
236  *              none
237  *
238  *      side effects:
239  *              A pointer to the appropriate
240  *              error code string is returned.
241  */
242 char *
243 geterr(c)
244 int c;
245 {
246         int     i;
247
248         for (i=0; errors[i]!=NULL; i++) {
249                 if (c == errors[i][1]) {
250                         return(errors[i]);
251                 }
252         }
253         return(NULL);
254 }
255