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 * $FreeBSD: src/gnu/usr.bin/as/messages.c,v 1.8 1999/08/27 23:34:19 peter Exp $
22 * $DragonFly: src/gnu/usr.bin/as/Attic/messages.c,v 1.3 2004/01/23 20:53:09 joerg Exp $
31 extern char *strerror ();
33 static void as_show_where PARAMS ((void));
34 static void as_warn_internal PARAMS ((char *, unsigned int, char *));
35 static void as_bad_internal PARAMS ((char *, unsigned int, char *));
38 * Despite the rest of the comments in this file, (FIXME-SOON),
39 * here is the current scheme for error messages etc:
41 * as_fatal() is used when gas is quite confused and
42 * continuing the assembly is pointless. In this case we
43 * exit immediately with error status.
45 * as_bad() is used to mark errors that result in what we
46 * presume to be a useless object file. Say, we ignored
47 * something that might have been vital. If we see any of
48 * these, assembly will continue to the end of the source,
49 * no object file will be produced, and we will terminate
50 * with error status. The new option, -Z, tells us to
51 * produce an object file anyway but we still exit with
52 * error status. The assumption here is that you don't want
53 * this object file but we could be wrong.
55 * as_warn() is used when we have an error from which we
56 * have a plausible error recovery. eg, masking the top
57 * bits of a constant that is longer than will fit in the
58 * destination. In this case we will continue to assemble
59 * the source, although we may have made a bad assumption,
60 * and we will produce an object file and return normal exit
61 * status (ie, no error). The new option -X tells us to
62 * treat all as_warn() errors as as_bad() errors. That is,
63 * no object file will be produced and we will exit with
64 * error status. The idea here is that we don't kill an
65 * entire make because of an error that we knew how to
66 * correct. On the other hand, sometimes you might want to
67 * stop the make at these points.
69 * as_tsktsk() is used when we see a minor error for which
70 * our error recovery action is almost certainly correct.
71 * In this case, we print a message and then assembly
72 * continues as though no error occurred.
78 static int identified;
89 fprintf (stderr, "%s: Assembler messages:\n", file);
92 static int warning_count; /* Count of number of warnings issued */
97 return (warning_count);
100 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
101 and exit with a nonzero error code */
103 static int error_count;
108 return (error_count);
112 /* Print the current location to stderr. */
120 as_where (&file, &line);
122 fprintf (stderr, "%s:%u: ", file, line);
128 * Like perror(3), but with more info.
132 as_perror (gripe, filename)
133 const char *gripe; /* Unpunctuated error theme. */
134 const char *filename;
139 fprintf (stderr, gripe, filename);
141 errtxt = bfd_errmsg (bfd_get_error ());
143 errtxt = strerror (errno);
145 fprintf (stderr, ": %s\n", errtxt);
148 bfd_set_error (bfd_error_no_error);
153 * a s _ t s k t s k ()
155 * Send to stderr a string as a warning, and locate warning
157 * Please only use this for when we have some recovery action.
158 * Please explain in string (which may have '\n's) what recovery was done.
162 as_tsktsk(const char *format, ...)
167 va_start (args, format);
168 vfprintf (stderr, format, args);
170 (void) putc ('\n', stderr);
173 /* The common portion of as_warn and as_warn_where. */
176 as_warn_internal (file, line, buffer)
184 as_where (&file, &line);
187 fprintf (stderr, "%s:%u: Warning: ", file, line);
188 fputs (buffer, stderr);
189 (void) putc ('\n', stderr);
191 listing_warning (buffer);
198 * Send to stderr a string as a warning, and locate warning
200 * Please only use this for when we have some recovery action.
201 * Please explain in string (which may have '\n's) what recovery was done.
205 #define flag_no_warnings (flagseen['W'])
209 as_warn (const char *format,...)
214 if (!flag_no_warnings)
216 va_start (args, format);
217 vsprintf (buffer, format, args);
219 as_warn_internal ((char *) NULL, 0, buffer);
223 /* as_warn_where, like as_bad but the file name and line number are
224 passed in. Unfortunately, we have to repeat the function in order
225 to handle the varargs correctly and portably. */
228 as_warn_where(char *file, unsigned int line, const char *format, ...)
233 if (!flag_no_warnings)
235 va_start (args, format);
236 vsprintf (buffer, format, args);
238 as_warn_internal (file, line, buffer);
242 /* The common portion of as_bad and as_bad_where. */
245 as_bad_internal (file, line, buffer)
253 as_where (&file, &line);
256 fprintf (stderr, "%s:%u: Error: ", file, line);
257 fputs (buffer, stderr);
258 (void) putc ('\n', stderr);
260 listing_error (buffer);
267 * Send to stderr a string as a warning, and locate warning in input file(s).
268 * Please us when there is no recovery, but we want to continue processing
269 * but not produce an object file.
270 * Please explain in string (which may have '\n's) what recovery was done.
274 as_bad (const char *format,...)
279 va_start (args, format);
280 vsprintf (buffer, format, args);
283 as_bad_internal ((char *) NULL, 0, buffer);
286 /* as_bad_where, like as_bad but the file name and line number are
287 passed in. Unfortunately, we have to repeat the function in order
288 to handle the varargs correctly and portably. */
291 as_bad_where (char *file, unsigned int line, const char *format,...)
296 va_start (args, format);
297 vsprintf (buffer, format, args);
300 as_bad_internal (file, line, buffer);
306 * Send to stderr a string as a fatal message, and print location of error in
308 * Please only use this for when we DON'T have some recovery action.
309 * It exit()s with a warning status.
313 as_fatal (const char *format,...)
318 va_start (args, format);
319 fprintf (stderr, "Fatal error:");
320 vfprintf (stderr, format, args);
321 (void) putc ('\n', stderr);
327 fprint_value (file, val)
331 if (sizeof (val) <= sizeof (long))
333 fprintf (file, "%ld", (long) val);
337 if (sizeof (val) <= sizeof (bfd_vma))
339 fprintf_vma (file, val);
347 sprint_value (buf, val)
351 if (sizeof (val) <= sizeof (long))
353 sprintf (buf, "%ld", (long) val);
357 if (sizeof (val) <= sizeof (bfd_vma))
359 sprintf_vma (buf, val);
366 /* end of messages.c */