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. */
21 static char rcsid[] = "$FreeBSD: src/gnu/usr.bin/as/messages.c,v 1.8 1999/08/27 23:34:19 peter Exp $";
40 #endif /* NO_VARARGS */
41 #endif /* NO_STDARG */
43 extern char *strerror ();
45 static void as_show_where PARAMS ((void));
46 static void as_warn_internal PARAMS ((char *, unsigned int, char *));
47 static void as_bad_internal PARAMS ((char *, unsigned int, char *));
50 * Despite the rest of the comments in this file, (FIXME-SOON),
51 * here is the current scheme for error messages etc:
53 * as_fatal() is used when gas is quite confused and
54 * continuing the assembly is pointless. In this case we
55 * exit immediately with error status.
57 * as_bad() is used to mark errors that result in what we
58 * presume to be a useless object file. Say, we ignored
59 * something that might have been vital. If we see any of
60 * these, assembly will continue to the end of the source,
61 * no object file will be produced, and we will terminate
62 * with error status. The new option, -Z, tells us to
63 * produce an object file anyway but we still exit with
64 * error status. The assumption here is that you don't want
65 * this object file but we could be wrong.
67 * as_warn() is used when we have an error from which we
68 * have a plausible error recovery. eg, masking the top
69 * bits of a constant that is longer than will fit in the
70 * destination. In this case we will continue to assemble
71 * the source, although we may have made a bad assumption,
72 * and we will produce an object file and return normal exit
73 * status (ie, no error). The new option -X tells us to
74 * treat all as_warn() errors as as_bad() errors. That is,
75 * no object file will be produced and we will exit with
76 * error status. The idea here is that we don't kill an
77 * entire make because of an error that we knew how to
78 * correct. On the other hand, sometimes you might want to
79 * stop the make at these points.
81 * as_tsktsk() is used when we see a minor error for which
82 * our error recovery action is almost certainly correct.
83 * In this case, we print a message and then assembly
84 * continues as though no error occurred.
91 static int identified;
102 fprintf (stderr, "%s: Assembler messages:\n", file);
105 static int warning_count; /* Count of number of warnings issued */
110 return (warning_count);
113 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
114 and exit with a nonzero error code */
116 static int error_count;
121 return (error_count);
125 /* Print the current location to stderr. */
133 as_where (&file, &line);
135 fprintf (stderr, "%s:%u: ", file, line);
141 * Like perror(3), but with more info.
145 as_perror (gripe, filename)
146 const char *gripe; /* Unpunctuated error theme. */
147 const char *filename;
152 fprintf (stderr, gripe, filename);
154 errtxt = bfd_errmsg (bfd_get_error ());
156 errtxt = strerror (errno);
158 fprintf (stderr, ": %s\n", errtxt);
161 bfd_set_error (bfd_error_no_error);
166 * a s _ t s k t s k ()
168 * Send to stderr a string as a warning, and locate warning
170 * Please only use this for when we have some recovery action.
171 * Please explain in string (which may have '\n's) what recovery was done.
176 as_tsktsk (const char *format,...)
181 va_start (args, format);
182 vfprintf (stderr, format, args);
184 (void) putc ('\n', stderr);
190 as_tsktsk (format, va_alist)
198 vfprintf (stderr, format, args);
200 (void) putc ('\n', stderr);
205 as_tsktsk (format, args)
209 _doprnt (format, &args, stderr);
210 (void) putc ('\n', stderr);
213 #endif /* not NO_VARARGS */
214 #endif /* not NO_STDARG */
216 /* The common portion of as_warn and as_warn_where. */
219 as_warn_internal (file, line, buffer)
227 as_where (&file, &line);
230 fprintf (stderr, "%s:%u: Warning: ", file, line);
231 fputs (buffer, stderr);
232 (void) putc ('\n', stderr);
234 listing_warning (buffer);
241 * Send to stderr a string as a warning, and locate warning
243 * Please only use this for when we have some recovery action.
244 * Please explain in string (which may have '\n's) what recovery was done.
248 #define flag_no_warnings (flagseen['W'])
253 as_warn (const char *format,...)
258 if (!flag_no_warnings)
260 va_start (args, format);
261 vsprintf (buffer, format, args);
263 as_warn_internal ((char *) NULL, 0, buffer);
270 as_warn (format, va_alist)
277 if (!flag_no_warnings)
280 vsprintf (buffer, format, args);
282 as_warn_internal ((char *) NULL, 0, buffer);
288 as_warn (format, args)
291 if (!flag_no_warnings)
295 fprintf (stderr, "Warning: ");
296 _doprnt (format, &args, stderr);
297 (void) putc ('\n', stderr);
301 #endif /* not NO_VARARGS */
302 #endif /* not NO_STDARG */
304 /* as_warn_where, like as_bad but the file name and line number are
305 passed in. Unfortunately, we have to repeat the function in order
306 to handle the varargs correctly and portably. */
310 as_warn_where (char *file, unsigned int line, const char *format,...)
315 if (!flag_no_warnings)
317 va_start (args, format);
318 vsprintf (buffer, format, args);
320 as_warn_internal (file, line, buffer);
327 as_warn_where (file, line, format, va_alist)
336 if (!flag_no_warnings)
339 vsprintf (buffer, format, args);
341 as_warn_internal (file, line, buffer);
347 as_warn_where (file, line, format, args)
352 if (!flag_no_warnings)
356 fprintf (stderr, "%s:%u: Warning: ", file, line);
357 _doprnt (format, &args, stderr);
358 (void) putc ('\n', stderr);
362 #endif /* not NO_VARARGS */
363 #endif /* not NO_STDARG */
365 /* The common portion of as_bad and as_bad_where. */
368 as_bad_internal (file, line, buffer)
376 as_where (&file, &line);
379 fprintf (stderr, "%s:%u: Error: ", file, line);
380 fputs (buffer, stderr);
381 (void) putc ('\n', stderr);
383 listing_error (buffer);
390 * Send to stderr a string as a warning, and locate warning in input file(s).
391 * Please us when there is no recovery, but we want to continue processing
392 * but not produce an object file.
393 * Please explain in string (which may have '\n's) what recovery was done.
398 as_bad (const char *format,...)
403 va_start (args, format);
404 vsprintf (buffer, format, args);
407 as_bad_internal ((char *) NULL, 0, buffer);
413 as_bad (format, va_alist)
421 vsprintf (buffer, format, args);
424 as_bad_internal ((char *) NULL, 0, buffer);
429 as_bad (format, args)
435 fprintf (stderr, "Error: ");
436 _doprnt (format, &args, stderr);
437 (void) putc ('\n', stderr);
440 #endif /* not NO_VARARGS */
441 #endif /* not NO_STDARG */
443 /* as_bad_where, like as_bad but the file name and line number are
444 passed in. Unfortunately, we have to repeat the function in order
445 to handle the varargs correctly and portably. */
449 as_bad_where (char *file, unsigned int line, const char *format,...)
454 va_start (args, format);
455 vsprintf (buffer, format, args);
458 as_bad_internal (file, line, buffer);
464 as_bad_where (file, line, format, va_alist)
474 vsprintf (buffer, format, args);
477 as_bad_internal (file, line, buffer);
482 as_bad_where (file, line, format, args)
490 fprintf (stderr, "%s:%u: Error: ", file, line);
491 _doprnt (format, &args, stderr);
492 (void) putc ('\n', stderr);
495 #endif /* not NO_VARARGS */
496 #endif /* not NO_STDARG */
501 * Send to stderr a string as a fatal message, and print location of error in
503 * Please only use this for when we DON'T have some recovery action.
504 * It exit()s with a warning status.
509 as_fatal (const char *format,...)
514 va_start (args, format);
515 fprintf (stderr, "Fatal error:");
516 vfprintf (stderr, format, args);
517 (void) putc ('\n', stderr);
525 as_fatal (format, va_alist)
533 fprintf (stderr, "Fatal error:");
534 vfprintf (stderr, format, args);
535 (void) putc ('\n', stderr);
542 as_fatal (format, args)
546 fprintf (stderr, "Fatal error:");
547 _doprnt (format, &args, stderr);
548 (void) putc ('\n', stderr);
549 exit (33); /* What is a good exit status? */
552 #endif /* not NO_VARARGS */
553 #endif /* not NO_STDARG */
556 fprint_value (file, val)
560 if (sizeof (val) <= sizeof (long))
562 fprintf (file, "%ld", (long) val);
566 if (sizeof (val) <= sizeof (bfd_vma))
568 fprintf_vma (file, val);
576 sprint_value (buf, val)
580 if (sizeof (val) <= sizeof (long))
582 sprintf (buf, "%ld", (long) val);
586 if (sizeof (val) <= sizeof (bfd_vma))
588 sprintf_vma (buf, val);
595 /* end of messages.c */