* messages.c (as_fatal): Do mention that it's the assembler that
[platform/upstream/binutils.git] / gas / messages.c
1 /* messages.c - error reporter -
2    Copyright (C) 1987, 1991, 1992 Free Software Foundation, Inc.
3
4    This file is part of GAS, the GNU Assembler.
5
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
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
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.
15
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
20 #include <stdio.h>              /* define stderr */
21 #include <errno.h>
22
23 #include "as.h"
24
25 #ifndef __STDC__
26 #ifndef NO_STDARG
27 #define NO_STDARG
28 #endif
29 #endif
30
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
39 extern char *strerror ();
40
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
81
82   JF: this is now bogus.  We now print more standard error messages
83   that try to look like everyone else's.
84
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.
92
93   Optionally, we may die.
94   There is no need for a trailing '\n' in your error text format
95   because we supply one.
96
97   as_warn(fmt,args)  Like fprintf(stderr,fmt,args) but also call errwhere().
98
99   as_fatal(fmt,args) Like as_warn() but exit with a fatal status.
100
101   */
102
103 static int warning_count;       /* Count of number of warnings issued */
104
105 int 
106 had_warnings ()
107 {
108   return (warning_count);
109 }                               /* had_err() */
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
114 static int error_count;
115
116 int 
117 had_errors ()
118 {
119   return (error_count);
120 }                               /* had_errors() */
121
122
123 /*
124  *                      a s _ p e r r o r
125  *
126  * Like perror(3), but with more info.
127  */
128 void 
129 as_perror (gripe, filename)
130      char *gripe;               /* Unpunctuated error theme. */
131      char *filename;
132 {
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() */
138
139 /*
140  *                      a s _ t s k t s k ()
141  *
142  * Send to stderr a string as a warning, and locate warning
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
149 void 
150 as_tsktsk (const char *Format,...)
151 {
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
161 #else
162 #ifndef NO_VARARGS
163 void 
164 as_tsktsk (Format, va_alist)
165      char *Format;
166      va_dcl
167 {
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
177 #else
178 /*VARARGS1 */
179 as_tsktsk (Format, args)
180      char *Format;
181 {
182   as_where ();
183   _doprnt (Format, &args, stderr);
184   (void) putc ('\n', stderr);
185   /* as_where(); */
186 }                               /* as_tsktsk */
187
188 #endif /* not NO_VARARGS */
189 #endif /* not NO_STDARG */
190
191 /*
192  *                      a s _ w a r n ()
193  *
194  * Send to stderr a string as a warning, and locate warning
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
201 void 
202 as_warn (const char *Format,...)
203 {
204   va_list args;
205   char buffer[200];
206
207   if (!flag_suppress_warnings)
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);
215 #ifndef NO_LISTING
216       listing_warning (buffer);
217 #endif
218       va_end (args);
219       (void) putc ('\n', stderr);
220     }
221 }                               /* as_warn() */
222
223 #else
224 #ifndef NO_VARARGS
225 void 
226 as_warn (Format, va_alist)
227      char *Format;
228      va_dcl
229 {
230   va_list args;
231   char buffer[200];
232
233   if (!flag_suppress_warnings)
234     {
235       ++warning_count;
236       as_where ();
237       va_start (args);
238       fprintf (stderr, "Warning: ");
239       vsprintf (buffer, Format, args);
240       fputs (buffer, stderr);
241 #ifndef NO_LISTING
242       listing_warning (buffer);
243 #endif
244       va_end (args);
245       (void) putc ('\n', stderr);
246     }
247 }                               /* as_warn() */
248
249 #else
250 /*VARARGS1 */
251 as_warn (Format, args)
252      char *Format;
253 {
254   if (!flag_suppress_warnings)
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
264 #endif /* not NO_VARARGS */
265 #endif /* not NO_STDARG */
266
267 /*
268  *                      a s _ b a d ()
269  *
270  * Send to stderr a string as a warning, and locate warning in input file(s).
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
277 void 
278 as_bad (const char *Format,...)
279 {
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);
290 #ifndef NO_LISTING
291   listing_error (buffer);
292 #endif
293   va_end (args);
294   (void) putc ('\n', stderr);
295 }                               /* as_bad() */
296
297 #else
298 #ifndef NO_VARARGS
299 void 
300 as_bad (Format, va_alist)
301      char *Format;
302      va_dcl
303 {
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);
312 #ifndef NO_LISTING
313   listing_error (buffer);
314 #endif
315
316   va_end (args);
317   (void) putc ('\n', stderr);
318 }                               /* as_bad() */
319
320 #else
321 /*VARARGS1 */
322 as_bad (Format, args)
323      char *Format;
324 {
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
334 #endif /* not NO_VARARGS */
335 #endif /* not NO_STDARG */
336
337 /*
338  *                      a s _ f a t a l ()
339  *
340  * Send to stderr a string as a fatal message, and print location of error in
341  * input file(s).
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
347 void 
348 as_fatal (const char *Format,...)
349 {
350   va_list args;
351
352   as_where ();
353   va_start (args, Format);
354   fprintf (stderr, "Assembler fatal error:");
355   vfprintf (stderr, Format, args);
356   (void) putc ('\n', stderr);
357   va_end (args);
358   exit (33);
359 }                               /* as_fatal() */
360
361 #else
362 #ifndef NO_VARARGS
363 void 
364 as_fatal (Format, va_alist)
365      char *Format;
366      va_dcl
367 {
368   va_list args;
369
370   as_where ();
371   va_start (args);
372   fprintf (stderr, "Assembler fatal error:");
373   vfprintf (stderr, Format, args);
374   (void) putc ('\n', stderr);
375   va_end (args);
376   exit (33);
377 }                               /* as_fatal() */
378
379 #else
380 /*VARARGS1 */
381 as_fatal (Format, args)
382      char *Format;
383 {
384   as_where ();
385   fprintf (stderr, "Assembler fatal error:");
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
392 #endif /* not NO_VARARGS */
393 #endif /* not NO_STDARG */
394
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
435 /* end of messages.c */