ld64 with ppc
[darwin-xtools.git] / cctools / as / messages.c
blobb2873e6c2cc0797f07b9351be6c99ba138bee49a
1 /* messages.c - error reporter -
2 Copyright (C) 1987 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 1, or (at your option)
9 any later version.
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>
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <mach/mach.h>
25 #include <mach/mach_init.h>
26 #if defined(__OPENSTEP__) || defined(__GONZO_BUNSEN_BEAKER__)
27 #include <servers/netname.h>
28 #else
29 #ifndef __has_extension
30 # define __has_extension(x) 0
31 #endif
32 #ifndef __has_feature
33 #define __has_feature(x) 0
34 #endif
35 #include <servers/bootstrap.h>
36 #endif
37 #include "as.h"
38 #include "input-scrub.h"
39 #include "messages.h"
42 ERRORS
44 We print the error message 1st, beginning in column 1.
45 All ancillary info starts in column 2 on lines after the
46 key error text.
47 We try to print a location in logical and physical file
48 just after the main error text.
49 Caller then prints any appendices after that, begining all
50 lines with at least 1 space.
52 Optionally, we may die.
53 There is no need for a trailing '\n' in your error text format
54 because we supply one.
56 as_warn(fmt,args) Like fprintf(stderr,fmt,args) but also call errwhere().
58 as_fatal(fmt,args) Like as_warn() but exit with a fatal status.
64 * Nonzero if we've hit a 'bad error', and should not write an obj file,
65 * and exit with a nonzero error code.
67 int bad_error = 0;
70 * If set to non-zero in main() -arch_multiple as been specified so if any
71 * error messages are printed print a single line first to start which errors
72 * the architectures are for.
74 int arch_multiple = 0;
77 * architecture_banner() returns the string to say what target we are assembling
78 * for.
80 static
81 const char *
82 architecture_banner(void)
84 #ifdef M68K
85 return("as: for architecture m68k\n");
86 #endif
87 #ifdef M88K
88 return("as: for architecture m88k\n");
89 #endif
90 #ifdef PPC
91 return("as: for architecture ppc\n");
92 #endif
93 #ifdef I860
94 return("as: for architecture i860\n");
95 #endif
96 #ifdef I386
97 return("as: for architecture i386\n");
98 #endif
99 #ifdef HPPA
100 return("as: for architecture hppa\n");
101 #endif
102 #ifdef SPARC
103 return("as: for architecture sparc\n");
104 #endif
105 #ifdef ARM
106 return("as: for architecture arm\n");
107 #endif
111 * print_architecture_banner() prints what architecture we are assembling for
112 * if it has not previously been printed.
114 static
115 void
116 print_architecture_banner(void)
118 static int printed = 0;
120 if(arch_multiple && !printed){
121 printf("%s", architecture_banner());
122 printed = 1;
127 * a s _ w a r n ( )
129 * Send to stderr a string as a warning, and locate warning in input file(s).
130 * Please only use this for when we have some recovery action.
131 * Please explain in string (which may have '\n's) what recovery was done.
133 void
134 as_warn(
135 const char *format,
136 ...)
138 va_list ap;
140 if(!flagseen['W']){
141 print_architecture_banner();
142 as_where();
143 va_start(ap, format);
144 vfprintf(stderr, format, ap);
145 fprintf(stderr, "\n");
146 va_end(ap);
150 /* Like as_bad but the file name and line number are passed in. */
151 void
152 as_warn_where (char *file, unsigned int line, const char *format, ...)
154 va_list args;
156 if (!flagseen['W'])
158 print_architecture_banner();
159 fprintf(stderr,"%s:%u:", file, line);
160 va_start (args, format);
161 vfprintf(stderr, format, args);
162 va_end (args);
167 * Like as_warn_where but the file name and optional line number and column
168 * are passed in.
170 void
171 as_warn_where_with_column (char *file, unsigned int line, unsigned int column, const char *format, ...)
173 va_list args;
175 if (!flagseen['W'])
177 print_architecture_banner();
178 fprintf(stderr, "%s:", file);
179 if (line)
181 fprintf(stderr, "%u:", line);
182 if (column)
183 fprintf(stderr, "%u:", column);
185 va_start (args, format);
186 vfprintf(stderr, format, args);
187 fprintf(stderr, "\n");
188 va_end (args);
193 * a s _ b a d ( )
195 * Send to stderr a string as a warning, * and locate warning in input file(s).
196 * Please us when there is no recovery, but we want to continue processing
197 * but not produce an object file.
198 * Please explain in string (which may have '\n's) what recovery was done.
200 void
201 as_bad(
202 const char *format,
203 ...)
205 va_list ap;
207 print_architecture_banner();
208 bad_error = 1;
209 as_where();
210 va_start(ap, format);
211 vfprintf(stderr, format, ap);
212 fprintf(stderr, "\n");
213 va_end(ap);
217 * a s _ f a t a l ( )
219 * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a fatal
220 * message, and locate stdsource in input file(s).
221 * Please only use this for when we DON'T have some recovery action.
222 * It exit()s with a warning status.
224 void
225 as_fatal(
226 const char *format,
227 ...)
229 va_list ap;
231 print_architecture_banner();
232 bad_error = 1;
233 as_where();
234 va_start(ap, format);
235 fprintf (stderr, "FATAL:");
236 vfprintf(stderr, format, ap);
237 fprintf(stderr, "\n");
238 va_end(ap);
239 exit(1);
242 void
243 sprint_value (char *buf, signed_expr_t val)
245 sprintf (buf, "%qd", val);