]>
Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* messages.c - error reporter - |
c1c28543 | 2 | Copyright (C) 1987, 1991, 1992 Free Software Foundation, Inc. |
6efd877d | 3 | |
fecd2382 | 4 | This file is part of GAS, the GNU Assembler. |
6efd877d | 5 | |
fecd2382 RP |
6 | GAS is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
a39116f1 | 8 | the Free Software Foundation; either version 2, or (at your option) |
fecd2382 | 9 | any later version. |
6efd877d | 10 | |
fecd2382 RP |
11 | GAS 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. | |
6efd877d | 15 | |
fecd2382 RP |
16 | You should have received a copy of the GNU General Public License |
17 | along with GAS; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
6efd877d | 20 | #include <stdio.h> /* define stderr */ |
fecd2382 RP |
21 | #include <errno.h> |
22 | ||
23 | #include "as.h" | |
24 | ||
4959cb7b KR |
25 | #ifndef __STDC__ |
26 | #ifndef NO_STDARG | |
27 | #define NO_STDARG | |
28 | #endif | |
29 | #endif | |
30 | ||
fecd2382 RP |
31 | #ifndef NO_STDARG |
32 | #include <stdarg.h> | |
33 | #else | |
34 | #ifndef NO_VARARGS | |
35 | #include <varargs.h> | |
36 | #endif /* NO_VARARGS */ | |
37 | #endif /* NO_STDARG */ | |
38 | ||
8d3be803 KR |
39 | extern char *strerror (); |
40 | ||
fecd2382 RP |
41 | /* |
42 | * Despite the rest of the comments in this file, (FIXME-SOON), | |
43 | * here is the current scheme for error messages etc: | |
44 | * | |
45 | * as_fatal() is used when gas is quite confused and | |
46 | * continuing the assembly is pointless. In this case we | |
47 | * exit immediately with error status. | |
48 | * | |
49 | * as_bad() is used to mark errors that result in what we | |
50 | * presume to be a useless object file. Say, we ignored | |
51 | * something that might have been vital. If we see any of | |
52 | * these, assembly will continue to the end of the source, | |
53 | * no object file will be produced, and we will terminate | |
54 | * with error status. The new option, -Z, tells us to | |
55 | * produce an object file anyway but we still exit with | |
56 | * error status. The assumption here is that you don't want | |
57 | * this object file but we could be wrong. | |
58 | * | |
59 | * as_warn() is used when we have an error from which we | |
60 | * have a plausible error recovery. eg, masking the top | |
61 | * bits of a constant that is longer than will fit in the | |
62 | * destination. In this case we will continue to assemble | |
63 | * the source, although we may have made a bad assumption, | |
64 | * and we will produce an object file and return normal exit | |
65 | * status (ie, no error). The new option -X tells us to | |
66 | * treat all as_warn() errors as as_bad() errors. That is, | |
67 | * no object file will be produced and we will exit with | |
68 | * error status. The idea here is that we don't kill an | |
69 | * entire make because of an error that we knew how to | |
70 | * correct. On the other hand, sometimes you might want to | |
71 | * stop the make at these points. | |
72 | * | |
73 | * as_tsktsk() is used when we see a minor error for which | |
74 | * our error recovery action is almost certainly correct. | |
75 | * In this case, we print a message and then assembly | |
76 | * continues as though no error occurred. | |
77 | */ | |
78 | ||
79 | /* | |
80 | ERRORS | |
6efd877d | 81 | |
fecd2382 RP |
82 | JF: this is now bogus. We now print more standard error messages |
83 | that try to look like everyone else's. | |
6efd877d | 84 | |
fecd2382 RP |
85 | We print the error message 1st, beginning in column 1. |
86 | All ancillary info starts in column 2 on lines after the | |
87 | key error text. | |
88 | We try to print a location in logical and physical file | |
89 | just after the main error text. | |
90 | Caller then prints any appendices after that, begining all | |
91 | lines with at least 1 space. | |
6efd877d | 92 | |
fecd2382 RP |
93 | Optionally, we may die. |
94 | There is no need for a trailing '\n' in your error text format | |
95 | because we supply one. | |
6efd877d | 96 | |
fecd2382 | 97 | as_warn(fmt,args) Like fprintf(stderr,fmt,args) but also call errwhere(). |
6efd877d | 98 | |
fecd2382 | 99 | as_fatal(fmt,args) Like as_warn() but exit with a fatal status. |
6efd877d | 100 | |
a39116f1 | 101 | */ |
fecd2382 | 102 | |
6efd877d | 103 | static int warning_count; /* Count of number of warnings issued */ |
fecd2382 | 104 | |
6efd877d KR |
105 | int |
106 | had_warnings () | |
107 | { | |
108 | return (warning_count); | |
109 | } /* had_err() */ | |
fecd2382 RP |
110 | |
111 | /* Nonzero if we've hit a 'bad error', and should not write an obj file, | |
112 | and exit with a nonzero error code */ | |
113 | ||
09952cd9 | 114 | static int error_count; |
fecd2382 | 115 | |
6efd877d KR |
116 | int |
117 | had_errors () | |
118 | { | |
119 | return (error_count); | |
120 | } /* had_errors() */ | |
fecd2382 RP |
121 | |
122 | ||
123 | /* | |
124 | * a s _ p e r r o r | |
125 | * | |
126 | * Like perror(3), but with more info. | |
127 | */ | |
6efd877d KR |
128 | void |
129 | as_perror (gripe, filename) | |
130 | char *gripe; /* Unpunctuated error theme. */ | |
131 | char *filename; | |
fecd2382 | 132 | { |
6efd877d KR |
133 | as_where (); |
134 | fprintf (stderr, gripe, filename); | |
135 | fprintf (stderr, ": %s\n", strerror (errno)); | |
136 | errno = 0; /* After reporting, clear it. */ | |
137 | } /* as_perror() */ | |
fecd2382 RP |
138 | |
139 | /* | |
140 | * a s _ t s k t s k () | |
141 | * | |
6efd877d | 142 | * Send to stderr a string as a warning, and locate warning |
fecd2382 RP |
143 | * in input file(s). |
144 | * Please only use this for when we have some recovery action. | |
145 | * Please explain in string (which may have '\n's) what recovery was done. | |
146 | */ | |
147 | ||
148 | #ifndef NO_STDARG | |
6efd877d KR |
149 | void |
150 | as_tsktsk (const char *Format,...) | |
fecd2382 | 151 | { |
6efd877d KR |
152 | va_list args; |
153 | ||
154 | as_where (); | |
155 | va_start (args, Format); | |
156 | vfprintf (stderr, Format, args); | |
157 | va_end (args); | |
158 | (void) putc ('\n', stderr); | |
159 | } /* as_tsktsk() */ | |
160 | ||
fecd2382 RP |
161 | #else |
162 | #ifndef NO_VARARGS | |
6efd877d KR |
163 | void |
164 | as_tsktsk (Format, va_alist) | |
165 | char *Format; | |
166 | va_dcl | |
fecd2382 | 167 | { |
6efd877d KR |
168 | va_list args; |
169 | ||
170 | as_where (); | |
171 | va_start (args); | |
172 | vfprintf (stderr, Format, args); | |
173 | va_end (args); | |
174 | (void) putc ('\n', stderr); | |
175 | } /* as_tsktsk() */ | |
176 | ||
fecd2382 RP |
177 | #else |
178 | /*VARARGS1 */ | |
6efd877d KR |
179 | as_tsktsk (Format, args) |
180 | char *Format; | |
fecd2382 | 181 | { |
6efd877d KR |
182 | as_where (); |
183 | _doprnt (Format, &args, stderr); | |
184 | (void) putc ('\n', stderr); | |
185 | /* as_where(); */ | |
186 | } /* as_tsktsk */ | |
187 | ||
fecd2382 RP |
188 | #endif /* not NO_VARARGS */ |
189 | #endif /* not NO_STDARG */ | |
190 | ||
fecd2382 RP |
191 | /* |
192 | * a s _ w a r n () | |
193 | * | |
09952cd9 | 194 | * Send to stderr a string as a warning, and locate warning |
fecd2382 RP |
195 | * in input file(s). |
196 | * Please only use this for when we have some recovery action. | |
197 | * Please explain in string (which may have '\n's) what recovery was done. | |
198 | */ | |
199 | ||
200 | #ifndef NO_STDARG | |
6efd877d KR |
201 | void |
202 | as_warn (const char *Format,...) | |
fecd2382 | 203 | { |
6efd877d KR |
204 | va_list args; |
205 | char buffer[200]; | |
206 | ||
8d3be803 | 207 | if (!flag_suppress_warnings) |
6efd877d KR |
208 | { |
209 | ++warning_count; | |
210 | as_where (); | |
211 | va_start (args, Format); | |
212 | fprintf (stderr, "Warning: "); | |
213 | vsprintf (buffer, Format, args); | |
214 | fputs (buffer, stderr); | |
a39116f1 | 215 | #ifndef NO_LISTING |
6efd877d | 216 | listing_warning (buffer); |
a39116f1 | 217 | #endif |
6efd877d KR |
218 | va_end (args); |
219 | (void) putc ('\n', stderr); | |
220 | } | |
221 | } /* as_warn() */ | |
222 | ||
fecd2382 RP |
223 | #else |
224 | #ifndef NO_VARARGS | |
6efd877d KR |
225 | void |
226 | as_warn (Format, va_alist) | |
227 | char *Format; | |
228 | va_dcl | |
fecd2382 | 229 | { |
6efd877d KR |
230 | va_list args; |
231 | char buffer[200]; | |
232 | ||
8d3be803 | 233 | if (!flag_suppress_warnings) |
6efd877d KR |
234 | { |
235 | ++warning_count; | |
236 | as_where (); | |
237 | va_start (args); | |
238 | fprintf (stderr, "Warning: "); | |
239 | vsprintf (buffer, Format, args); | |
240 | fputs (buffer, stderr); | |
a39116f1 | 241 | #ifndef NO_LISTING |
6efd877d KR |
242 | listing_warning (buffer); |
243 | #endif | |
244 | va_end (args); | |
245 | (void) putc ('\n', stderr); | |
246 | } | |
247 | } /* as_warn() */ | |
248 | ||
fecd2382 RP |
249 | #else |
250 | /*VARARGS1 */ | |
6efd877d KR |
251 | as_warn (Format, args) |
252 | char *Format; | |
fecd2382 | 253 | { |
8d3be803 | 254 | if (!flag_suppress_warnings) |
6efd877d KR |
255 | { |
256 | ++warning_count; | |
257 | as_where (); | |
258 | _doprnt (Format, &args, stderr); | |
259 | (void) putc ('\n', stderr); | |
260 | /* as_where(); */ | |
261 | } | |
262 | } /* as_warn() */ | |
263 | ||
fecd2382 RP |
264 | #endif /* not NO_VARARGS */ |
265 | #endif /* not NO_STDARG */ | |
266 | ||
fecd2382 RP |
267 | /* |
268 | * a s _ b a d () | |
269 | * | |
6efd877d | 270 | * Send to stderr a string as a warning, and locate warning in input file(s). |
fecd2382 RP |
271 | * Please us when there is no recovery, but we want to continue processing |
272 | * but not produce an object file. | |
273 | * Please explain in string (which may have '\n's) what recovery was done. | |
274 | */ | |
275 | ||
276 | #ifndef NO_STDARG | |
6efd877d KR |
277 | void |
278 | as_bad (const char *Format,...) | |
fecd2382 | 279 | { |
6efd877d KR |
280 | va_list args; |
281 | char buffer[200]; | |
282 | ||
283 | ++error_count; | |
284 | as_where (); | |
285 | va_start (args, Format); | |
286 | fprintf (stderr, "Error: "); | |
287 | ||
288 | vsprintf (buffer, Format, args); | |
289 | fputs (buffer, stderr); | |
a39116f1 | 290 | #ifndef NO_LISTING |
6efd877d | 291 | listing_error (buffer); |
a39116f1 | 292 | #endif |
6efd877d KR |
293 | va_end (args); |
294 | (void) putc ('\n', stderr); | |
295 | } /* as_bad() */ | |
296 | ||
fecd2382 RP |
297 | #else |
298 | #ifndef NO_VARARGS | |
6efd877d KR |
299 | void |
300 | as_bad (Format, va_alist) | |
301 | char *Format; | |
302 | va_dcl | |
fecd2382 | 303 | { |
6efd877d KR |
304 | va_list args; |
305 | char buffer[200]; | |
306 | ||
307 | ++error_count; | |
308 | as_where (); | |
309 | va_start (args); | |
310 | vsprintf (buffer, Format, args); | |
311 | fputs (buffer, stderr); | |
a39116f1 | 312 | #ifndef NO_LISTING |
6efd877d | 313 | listing_error (buffer); |
a39116f1 | 314 | #endif |
6efd877d KR |
315 | |
316 | va_end (args); | |
317 | (void) putc ('\n', stderr); | |
a39116f1 | 318 | } /* as_bad() */ |
6efd877d | 319 | |
fecd2382 RP |
320 | #else |
321 | /*VARARGS1 */ | |
6efd877d KR |
322 | as_bad (Format, args) |
323 | char *Format; | |
fecd2382 | 324 | { |
6efd877d KR |
325 | ++error_count; |
326 | ||
327 | as_where (); | |
328 | fprintf (stderr, "Error: "); | |
329 | _doprnt (Format, &args, stderr); | |
330 | (void) putc ('\n', stderr); | |
331 | /* as_where(); */ | |
332 | } /* as_bad() */ | |
333 | ||
fecd2382 RP |
334 | #endif /* not NO_VARARGS */ |
335 | #endif /* not NO_STDARG */ | |
336 | ||
fecd2382 RP |
337 | /* |
338 | * a s _ f a t a l () | |
339 | * | |
6efd877d KR |
340 | * Send to stderr a string as a fatal message, and print location of error in |
341 | * input file(s). | |
fecd2382 RP |
342 | * Please only use this for when we DON'T have some recovery action. |
343 | * It exit()s with a warning status. | |
344 | */ | |
345 | ||
346 | #ifndef NO_STDARG | |
6efd877d KR |
347 | void |
348 | as_fatal (const char *Format,...) | |
fecd2382 | 349 | { |
6efd877d KR |
350 | va_list args; |
351 | ||
352 | as_where (); | |
353 | va_start (args, Format); | |
8d3be803 | 354 | fprintf (stderr, "Assembler fatal error:"); |
6efd877d KR |
355 | vfprintf (stderr, Format, args); |
356 | (void) putc ('\n', stderr); | |
357 | va_end (args); | |
358 | exit (33); | |
359 | } /* as_fatal() */ | |
360 | ||
fecd2382 RP |
361 | #else |
362 | #ifndef NO_VARARGS | |
6efd877d KR |
363 | void |
364 | as_fatal (Format, va_alist) | |
365 | char *Format; | |
366 | va_dcl | |
fecd2382 | 367 | { |
6efd877d KR |
368 | va_list args; |
369 | ||
370 | as_where (); | |
371 | va_start (args); | |
8d3be803 | 372 | fprintf (stderr, "Assembler fatal error:"); |
6efd877d KR |
373 | vfprintf (stderr, Format, args); |
374 | (void) putc ('\n', stderr); | |
375 | va_end (args); | |
376 | exit (33); | |
377 | } /* as_fatal() */ | |
378 | ||
fecd2382 RP |
379 | #else |
380 | /*VARARGS1 */ | |
6efd877d KR |
381 | as_fatal (Format, args) |
382 | char *Format; | |
fecd2382 | 383 | { |
6efd877d | 384 | as_where (); |
8d3be803 | 385 | fprintf (stderr, "Assembler fatal error:"); |
6efd877d KR |
386 | _doprnt (Format, &args, stderr); |
387 | (void) putc ('\n', stderr); | |
388 | /* as_where(); */ | |
389 | exit (33); /* What is a good exit status? */ | |
390 | } /* as_fatal() */ | |
391 | ||
fecd2382 RP |
392 | #endif /* not NO_VARARGS */ |
393 | #endif /* not NO_STDARG */ | |
394 | ||
8d3be803 KR |
395 | void |
396 | fprint_value (file, val) | |
397 | FILE *file; | |
398 | valueT val; | |
399 | { | |
400 | if (sizeof (val) <= sizeof (long)) | |
401 | { | |
402 | fprintf (file, "%ld", val); | |
403 | return; | |
404 | } | |
405 | #ifdef BFD_ASSEMBLER | |
406 | if (sizeof (val) <= sizeof (bfd_vma)) | |
407 | { | |
408 | fprintf_vma (file, val); | |
409 | return; | |
410 | } | |
411 | #endif | |
412 | abort (); | |
413 | } | |
414 | ||
415 | void | |
416 | sprint_value (buf, val) | |
417 | char *buf; | |
418 | valueT val; | |
419 | { | |
420 | if (sizeof (val) <= sizeof (long)) | |
421 | { | |
422 | sprintf (buf, "%ld", val); | |
423 | return; | |
424 | } | |
425 | #ifdef BFD_ASSEMBLER | |
426 | if (sizeof (val) <= sizeof (bfd_vma)) | |
427 | { | |
428 | sprintf_vma (buf, val); | |
429 | return; | |
430 | } | |
431 | #endif | |
432 | abort (); | |
433 | } | |
434 | ||
8b228fe9 | 435 | /* end of messages.c */ |