1/* messages.c - error reporter - 2 Copyright (C) 1987 Free Software Foundation, Inc. 3 4This file is part of GAS, the GNU Assembler. 5 6GAS is free software; you can redistribute it and/or modify 7it under the terms of the GNU General Public License as published by 8the Free Software Foundation; either version 1, or (at your option) 9any later version. 10 11GAS is distributed in the hope that it will be useful, 12but WITHOUT ANY WARRANTY; without even the implied warranty of 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14GNU General Public License for more details. 15 16You should have received a copy of the GNU General Public License 17along with GAS; see the file COPYING. If not, write to 18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 19 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#include <servers/bootstrap.h> 30#endif 31#include "as.h" 32#include "input-scrub.h" 33#include "messages.h" 34 35/* 36 ERRORS 37 38 We print the error message 1st, beginning in column 1. 39 All ancillary info starts in column 2 on lines after the 40 key error text. 41 We try to print a location in logical and physical file 42 just after the main error text. 43 Caller then prints any appendices after that, begining all 44 lines with at least 1 space. 45 46 Optionally, we may die. 47 There is no need for a trailing '\n' in your error text format 48 because we supply one. 49 50as_warn(fmt,args) Like fprintf(stderr,fmt,args) but also call errwhere(). 51 52as_fatal(fmt,args) Like as_warn() but exit with a fatal status. 53 54*/ 55 56 57/* 58 * Nonzero if we've hit a 'bad error', and should not write an obj file, 59 * and exit with a nonzero error code. 60 */ 61int bad_error = 0; 62 63/* 64 * If set to non-zero in main() -arch_multiple as been specified so if any 65 * error messages are printed print a single line first to start which errors 66 * the architectures are for. 67 */ 68int arch_multiple = 0; 69 70/* 71 * architecture_banner() returns the string to say what target we are assembling 72 * for. 73 */ 74static 75const char * 76architecture_banner(void) 77{ 78#ifdef M68K 79 return("as: for architecture m68k\n"); 80#endif 81#ifdef M88K 82 return("as: for architecture m88k\n"); 83#endif 84#ifdef PPC 85 return("as: for architecture ppc\n"); 86#endif 87#ifdef I860 88 return("as: for architecture i860\n"); 89#endif 90#ifdef I386 91 return("as: for architecture i386\n"); 92#endif 93#ifdef HPPA 94 return("as: for architecture hppa\n"); 95#endif 96#ifdef SPARC 97 return("as: for architecture sparc\n"); 98#endif 99#ifdef ARM 100 return("as: for architecture arm\n"); 101#endif 102} 103 104/* 105 * print_architecture_banner() prints what architecture we are assembling for 106 * if it has not previously been printed. 107 */ 108static 109void 110print_architecture_banner(void) 111{ 112 static int printed = 0; 113 114 if(arch_multiple && !printed){ 115 printf("%s", architecture_banner()); 116 printed = 1; 117 } 118} 119 120/* 121 * a s _ w a r n ( ) 122 * 123 * Send to stderr a string as a warning, and locate warning in input file(s). 124 * Please only use this for when we have some recovery action. 125 * Please explain in string (which may have '\n's) what recovery was done. 126 */ 127void 128as_warn( 129const char *format, 130...) 131{ 132 va_list ap; 133 134 if(!flagseen['W']){ 135 print_architecture_banner(); 136 as_where(); 137 va_start(ap, format); 138 vfprintf(stderr, format, ap); 139 fprintf(stderr, "\n"); 140 va_end(ap); 141 } 142} 143 144/* Like as_bad but the file name and line number are passed in. */ 145void 146as_warn_where (char *file, unsigned int line, const char *format, ...) 147{ 148 va_list args; 149 150 if (!flagseen['W']) 151 { 152 print_architecture_banner(); 153 fprintf(stderr,"%s:%u:", file, line); 154 va_start (args, format); 155 vfprintf(stderr, format, args); 156 va_end (args); 157 } 158} 159 160/* 161 * Like as_warn_where but the file name and optional line number and column 162 * are passed in. 163 */ 164void 165as_warn_where_with_column (char *file, unsigned int line, unsigned int column, const char *format, ...) 166{ 167 va_list args; 168 169 if (!flagseen['W']) 170 { 171 print_architecture_banner(); 172 fprintf(stderr, "%s:", file); 173 if (line) 174 { 175 fprintf(stderr, "%u:", line); 176 if (column) 177 fprintf(stderr, "%u:", column); 178 } 179 va_start (args, format); 180 vfprintf(stderr, format, args); 181 fprintf(stderr, "\n"); 182 va_end (args); 183 } 184} 185 186/* 187 * a s _ b a d ( ) 188 * 189 * Send to stderr a string as a warning, * and locate warning in input file(s). 190 * Please us when there is no recovery, but we want to continue processing 191 * but not produce an object file. 192 * Please explain in string (which may have '\n's) what recovery was done. 193 */ 194void 195as_bad( 196const char *format, 197...) 198{ 199 va_list ap; 200 201 print_architecture_banner(); 202 bad_error = 1; 203 as_where(); 204 va_start(ap, format); 205 vfprintf(stderr, format, ap); 206 fprintf(stderr, "\n"); 207 va_end(ap); 208} 209 210/* 211 * a s _ f a t a l ( ) 212 * 213 * Send to stderr a string (with bell) (JF: Bell is obnoxious!) as a fatal 214 * message, and locate stdsource in input file(s). 215 * Please only use this for when we DON'T have some recovery action. 216 * It exit()s with a warning status. 217 */ 218void 219as_fatal( 220const char *format, 221...) 222{ 223 va_list ap; 224 225 print_architecture_banner(); 226 bad_error = 1; 227 as_where(); 228 va_start(ap, format); 229 fprintf (stderr, "FATAL:"); 230 vfprintf(stderr, format, ap); 231 fprintf(stderr, "\n"); 232 va_end(ap); 233 exit(1); 234} 235 236void 237sprint_value (char *buf, signed_expr_t val) 238{ 239 sprintf (buf, "%qd", val); 240} 241