1 /* messages.c - error reporter -
2 Copyright (C) 1987, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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)
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.
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. */
20 #include <stdio.h> /* define stderr */
36 #endif /* NO_VARARGS */
37 #endif /* NO_STDARG */
39 extern char *strerror ();
42 * Despite the rest of the comments in this file, (FIXME-SOON),
43 * here is the current scheme for error messages etc:
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.
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.
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.
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.
82 JF: this is now bogus. We now print more standard error messages
83 that try to look like everyone else's.
85 We print the error message 1st, beginning in column 1.
86 All ancillary info starts in column 2 on lines after the
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.
93 Optionally, we may die.
94 There is no need for a trailing '\n' in your error text format
95 because we supply one.
97 as_warn(fmt,args) Like fprintf(stderr,fmt,args) but also call errwhere().
99 as_fatal(fmt,args) Like as_warn() but exit with a fatal status.
103 static int warning_count; /* Count of number of warnings issued */
108 return (warning_count);
111 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
112 and exit with a nonzero error code */
114 static int error_count;
119 return (error_count);
126 * Like perror(3), but with more info.
129 as_perror (gripe, filename)
130 char *gripe; /* Unpunctuated error theme. */
134 fprintf (stderr, gripe, filename);
135 fprintf (stderr, ": %s\n", strerror (errno));
136 errno = 0; /* After reporting, clear it. */
140 * a s _ t s k t s k ()
142 * Send to stderr a string as a warning, and locate warning
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.
150 as_tsktsk (const char *Format,...)
155 va_start (args, Format);
156 vfprintf (stderr, Format, args);
158 (void) putc ('\n', stderr);
164 as_tsktsk (Format, va_alist)
172 vfprintf (stderr, Format, args);
174 (void) putc ('\n', stderr);
179 as_tsktsk (Format, args)
183 _doprnt (Format, &args, stderr);
184 (void) putc ('\n', stderr);
188 #endif /* not NO_VARARGS */
189 #endif /* not NO_STDARG */
194 * Send to stderr a string as a warning, and locate warning
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.
202 as_warn (const char *Format,...)
207 if (!flag_suppress_warnings)
211 va_start (args, Format);
212 fprintf (stderr, "Warning: ");
213 vsprintf (buffer, Format, args);
214 fputs (buffer, stderr);
216 listing_warning (buffer);
219 (void) putc ('\n', stderr);
226 as_warn (Format, va_alist)
233 if (!flag_suppress_warnings)
238 fprintf (stderr, "Warning: ");
239 vsprintf (buffer, Format, args);
240 fputs (buffer, stderr);
242 listing_warning (buffer);
245 (void) putc ('\n', stderr);
251 as_warn (Format, args)
254 if (!flag_suppress_warnings)
258 _doprnt (Format, &args, stderr);
259 (void) putc ('\n', stderr);
264 #endif /* not NO_VARARGS */
265 #endif /* not NO_STDARG */
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.
278 as_bad (const char *Format,...)
285 va_start (args, Format);
286 fprintf (stderr, "Error: ");
288 vsprintf (buffer, Format, args);
289 fputs (buffer, stderr);
291 listing_error (buffer);
294 (void) putc ('\n', stderr);
300 as_bad (Format, va_alist)
310 vsprintf (buffer, Format, args);
311 fputs (buffer, stderr);
313 listing_error (buffer);
317 (void) putc ('\n', stderr);
322 as_bad (Format, args)
328 fprintf (stderr, "Error: ");
329 _doprnt (Format, &args, stderr);
330 (void) putc ('\n', stderr);
334 #endif /* not NO_VARARGS */
335 #endif /* not NO_STDARG */
340 * Send to stderr a string as a fatal message, and print location of error in
342 * Please only use this for when we DON'T have some recovery action.
343 * It exit()s with a warning status.
348 as_fatal (const char *Format,...)
353 va_start (args, Format);
354 fprintf (stderr, "Assembler fatal error:");
355 vfprintf (stderr, Format, args);
356 (void) putc ('\n', stderr);
364 as_fatal (Format, va_alist)
372 fprintf (stderr, "Assembler fatal error:");
373 vfprintf (stderr, Format, args);
374 (void) putc ('\n', stderr);
381 as_fatal (Format, args)
385 fprintf (stderr, "Assembler fatal error:");
386 _doprnt (Format, &args, stderr);
387 (void) putc ('\n', stderr);
389 exit (33); /* What is a good exit status? */
392 #endif /* not NO_VARARGS */
393 #endif /* not NO_STDARG */
396 fprint_value (file, val)
400 if (sizeof (val) <= sizeof (long))
402 fprintf (file, "%ld", val);
406 if (sizeof (val) <= sizeof (bfd_vma))
408 fprintf_vma (file, val);
416 sprint_value (buf, val)
420 if (sizeof (val) <= sizeof (long))
422 sprintf (buf, "%ld", val);
426 if (sizeof (val) <= sizeof (bfd_vma))
428 sprintf_vma (buf, val);
435 /* end of messages.c */