Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 /* ==================================================================== 00037 * ==================================================================== 00038 * 00039 * 00040 * Revision history: 00041 * 12-Apr-95 - Original Version 00042 * 00043 * Description: 00044 * 00045 * This hides the error diagnostics machinery, such that we 00046 * can define our own or rely on some existing facilities. 00047 * 00048 * For now, we just implement a simple error diagnostics scheme 00049 * which does not rely on any other existing scheme. 00050 * 00051 * ==================================================================== 00052 * ==================================================================== 00053 */ 00054 00055 #include <stdarg.h> 00056 #include <errno.h> /* for sys_errlist */ 00057 #include <stdio.h> /* for stderr */ 00058 #include "common_include.h" 00059 #include "file_util.h" 00060 00061 static const UINT Diag_Phase_Name_Len = 80; 00062 static char Diag_Phase_Name[Diag_Phase_Name_Len+1] = ""; 00063 static FILE *Diag_File = NULL; 00064 static INT Diag_Max_Diags = 10; /* Default */ 00065 static INT Diag_Warn_Count = 0; 00066 static const char *Diag_File_Location = NULL; 00067 static INT Diag_Line_Location = 0; 00068 static INT Diag_SrcLine_Location = 0; 00069 static INT Diag_SrcCol_Location = 0; 00070 00071 static const char *Diag_Msg[DIAG_LAST+1]; 00072 00073 00074 void Diag_Init(void) 00075 { 00076 INT diag; 00077 00078 /* Initiate the Diag_Msg[] table to a standard error message. 00079 */ 00080 for (diag = DIAG_FIRST; diag <= DIAG_LAST; diag++) 00081 Diag_Msg[diag] = "*** Unknown diagnostics code ***"; 00082 00083 /* Initiate the Diag_Msg[] table for well-defined error codes. 00084 */ 00085 Diag_Msg[DIAG_A_STRING] = "%s"; 00086 Diag_Msg[DIAG_UNIMPLEMENTED] = "TODO: Unimplemented feature: %s"; 00087 Diag_Msg[DIAG_UNKNOWN_CMD_LINE_OPTION] = "Unknown command-line option: %s"; 00088 Diag_Msg[DIAG_CANNOT_OPEN_FILE] = "Cannot open file (%s), errno=%d"; 00089 Diag_Msg[DIAG_CANNOT_CLOSE_FILE] = "Cannot close file (%s), errno=%d"; 00090 00091 Diag_Msg[DIAG_W2F_CANNOT_HANDLE_OPC] = 00092 "cannot handle opcode %s (%d)"; 00093 Diag_Msg[DIAG_W2F_UNEXPECTED_OPC] = 00094 "unexpected opcode in %s()"; 00095 Diag_Msg[DIAG_W2F_UNEXPECTED_IOS] = 00096 "unexpected IO statement kind %s in %s()"; 00097 Diag_Msg[DIAG_W2F_UNEXPECTED_IOU] = 00098 "unexpected IO unit kind %s in %s()"; 00099 Diag_Msg[DIAG_W2F_UNEXPECTED_IOF] = 00100 "unexpected IO format kind %s in %s()"; 00101 Diag_Msg[DIAG_W2F_UNEXPECTED_IOC] = 00102 "unexpected IO control kind %s in %s()"; 00103 Diag_Msg[DIAG_W2F_UNEXPECTED_IOL] = 00104 "unexpected IO list kind %s in %s()"; 00105 Diag_Msg[DIAG_W2F_UNEXPECTED_INITV] = 00106 "unexpected INITV kind %d in %s()"; 00107 Diag_Msg[DIAG_W2F_UNEXPECTED_DOLOOP_BOUNDOP] = 00108 "unexpected opcode (%s) for DO loop bound in %s()"; 00109 Diag_Msg[DIAG_W2F_UNEXPECTED_IMPLIED_DOLOOP] = 00110 "unexpected form of implied do-loop in %s(); Cannot calculate bounds"; 00111 Diag_Msg[DIAG_W2F_UNEXPECTED_RETURNSITE] = 00112 "RETURNSITE out of sequence in %s()"; 00113 Diag_Msg[DIAG_W2F_UNEXPECTED_CALLSITE] = 00114 "CALLSITE out of sequence in %s()"; 00115 Diag_Msg[DIAG_W2F_UNEXPECTED_SUBSTRING_REF] = 00116 "Unexpected (sub)string reference in %s()"; 00117 Diag_Msg[DIAG_W2F_UNEXPEXTED_RETURNREG_USE] = 00118 "Unexpected usage of return-registers detected in %s()"; 00119 Diag_Msg[DIAG_W2F_UNEXPEXTED_OFFSET] = 00120 "Unexpected offset (%d) for memory location in %s()"; 00121 Diag_Msg[DIAG_W2F_UNEXPEXTED_NULL_PTR] = 00122 "Unexpected NULL value for %s in %s()"; 00123 Diag_Msg[DIAG_W2F_NONEXISTENT_FLD_PATH] = 00124 "Non-existent path to an FLD of the given object type in %s()"; 00125 Diag_Msg[DIAG_W2F_CANNOT_LDA_PREG] = 00126 "Cannot take the address of a pseudo-register"; 00127 Diag_Msg[DIAG_W2F_CANNOT_DEREF] = 00128 "Cannot dereference pointer variable in %s(); No pointee specification"; 00129 Diag_Msg[DIAG_W2F_UNEXPECTED_NUM_KIDS] = 00130 "Unexpected number of kids (%d), expected %d kids for %s()"; 00131 Diag_Msg[DIAG_W2F_UNEXPECTED_CVT] = 00132 "unexpected conversion from %s to %s in %s()"; /* Use MTYPE_name() */ 00133 Diag_Msg[DIAG_W2F_UNEXPECTED_CONTEXT] = 00134 "unexpected context of translation for %s()"; 00135 00136 Diag_Msg[DIAG_W2F_UNEXPECTED_TYPE_KIND] = 00137 "unexpected TY_kind (%d) in %s()"; 00138 Diag_Msg[DIAG_W2F_UNEXPECTED_TYPE_SIZE] = 00139 "unexpected TY_size (%d) in %s()"; 00140 Diag_Msg[DIAG_W2F_UNEXPECTED_BTYPE] = 00141 "unexpected TY_btype (%s) in %s()"; /* Use MTYPE_name() */ 00142 Diag_Msg[DIAG_W2F_EXPECTED_PTR_TO_CHARACTER] = 00143 "expected pointer to character operands in %s()"; 00144 Diag_Msg[DIAG_W2F_EXPECTED_PTR] = 00145 "expected pointer TY in %s()"; 00146 Diag_Msg[DIAG_W2F_UNEXPECTED_SYMBOL] = 00147 "unexpected form of symbol in %s()"; 00148 Diag_Msg[DIAG_W2F_UNEXPECTED_SYMCLASS] = 00149 "unexpected ST_symclass (%d) in %s()"; 00150 Diag_Msg[DIAG_W2F_UNEXPECTED_STORECLASS] = 00151 "unexpected ST_sclass (%d) in %s()"; 00152 Diag_Msg[DIAG_W2F_UNEXPECTED_SYM_CONST] = 00153 "unexpected symbolic constant in %s()"; 00154 Diag_Msg[DIAG_W2F_UNEXPECTED_PRAGMA] = 00155 "unexpected pragma kind in %s()"; 00156 Diag_Msg[DIAG_W2F_MISPLACED_PRAGMA] = 00157 "pragma %s will be misplaced in output, and will be emitted as comment"; 00158 Diag_Msg[DIAG_W2F_EXPECTED_IDNAME] = 00159 "expected OPC_IDNAME in %s()"; 00160 Diag_Msg[DIAG_W2F_INCOMPATIBLE_TYS] = 00161 "incompatible types in %s()"; 00162 Diag_Msg[DIAG_W2F_DECLARE_RETURN_PARAM] = 00163 "should not declare return parameter: %s()"; 00164 Diag_Msg[DIAG_W2F_BUFFER_ERROR] = 00165 "Error in buffer access: %s"; 00166 00167 Diag_Msg[DIAG_W2C_CANNOT_HANDLE_OPC] = Diag_Msg[DIAG_W2F_CANNOT_HANDLE_OPC]; 00168 Diag_Msg[DIAG_W2C_UNEXPECTED_OPC] = Diag_Msg[DIAG_W2F_UNEXPECTED_OPC]; 00169 Diag_Msg[DIAG_W2C_EXPECTED_IDNAME] = Diag_Msg[DIAG_W2F_EXPECTED_IDNAME]; 00170 00171 Diag_Msg[DIAG_PRP_OPTION_ILLEGAL] = 00172 "Illegal %s option: %s\n"; 00173 Diag_Msg[DIAG_PRP_OPTION_MISSING_SRC] = 00174 "Missing source file for PURPLE processing"; 00175 Diag_Msg[DIAG_PRP_NAME_OVERFLOW] = 00176 "The input overflows a name-buffer: %s\n"; 00177 Diag_Msg[DIAG_PRP_FILE_ERROR] = "Error in accessing file: %s\n"; 00178 Diag_Msg[DIAG_PRP_FILE_CANNOT_OPEN] = "Cannot open file: %s\n"; 00179 Diag_Msg[DIAG_PRP_FILE_CANNOT_CLOSE] = "Cannot close file: %s\n"; 00180 Diag_Msg[DIAG_PRP_FILE_OVERWRITTEN] = "Overwrites existing file: %s\n"; 00181 Diag_Msg[DIAG_PRP_FILE_AT_END] = "Attempt to go beyond end of file: %s\n"; 00182 Diag_Msg[DIAG_PRP_FILE_NOT_OPEN] = "Attemp at accessing unopened file\n"; 00183 Diag_Msg[DIAG_PRP_FILE_NOT_CLOSED] = "Forgot to close file: %s\n"; 00184 Diag_Msg[DIAG_PRP_FILE_HEADER_ERROR] = "Error in header of file: %s\n"; 00185 Diag_Msg[DIAG_PRP_ITEM_INPUT_ERROR] = 00186 "Unexpected item found in purple input-file (%s):\n" 00187 "-- ignoring remaining input"; 00188 Diag_Msg[DIAG_PRP_EXPECTED_PURPLE_REGION] = 00189 "Missing PURPLE region definition"; 00190 Diag_Msg[DIAG_PRP_PREREQUISITE_CALL] = 00191 "Need to call %s(), before %s()"; 00192 Diag_Msg[DIAG_PRP_EXPECTED_CONSTRAINT] = 00193 "Missing PURPLE region constraint %s"; 00194 Diag_Msg[DIAG_PRP_UNEXPECTED_OPCODE] = 00195 "unexpected opcode (%d) in PURPLE routine %s()"; 00196 Diag_Msg[DIAG_PRP_UNEXPECTED_TYPE] = 00197 "unexpected type (%s) in PURPLE routine %s()"; 00198 Diag_Msg[DIAG_PRP_INVALID_LEXEME_KIND] = 00199 "invalid lexeme-kind (%d) in PURPLE routine %s()"; 00200 Diag_Msg[DIAG_PRP_INVALID_TRACE_ITEM_KIND] = 00201 "invalid trace item kind (%d) in PURPLE routine %s()"; 00202 Diag_Msg[DIAG_PRP_CANNOT_ASSIGN_OBJECT] = 00203 "illegal use of %s; assignment not supported"; 00204 Diag_Msg[DIAG_PRP_ILLEGAL_SET] = 00205 "illegal set in %s()"; 00206 Diag_Msg[DIAG_PRP_RVALUE_ERROR] = 00207 "illegal access to rvalue attribute"; 00208 Diag_Msg[DIAG_PRP_PLACEHOLDER_ERROR] = 00209 "Encountered unexpected purple placeholder format in %s"; 00210 Diag_Msg[DIAG_PRP_PREG_VALUE] = 00211 "Error in preg value mapping; %s"; 00212 Diag_Msg[DIAG_PRP_MEM_VALUE] = 00213 "Error in memory value mapping; %s"; 00214 Diag_Msg[DIAG_PRP_VALUE_SPACE] = 00215 "Error in memory value space; %s"; 00216 Diag_Msg[DIAG_PRP_VARIABLE_DEF] = 00217 "Error in variable definition; %s"; 00218 Diag_Msg[DIAG_PRP_DEFINED_MEM_SPACE] = 00219 "Error in defined memory space; %s"; 00220 Diag_Msg[DIAG_PRP_PU_MMAP] = 00221 "Error in PU memory mapping; %s"; 00222 Diag_Msg[DIAG_PRP_FILE_MMAP] = 00223 "Error in file memory mapping; %s"; 00224 Diag_Msg[DIAG_PRP_PROGRAM_MMAP] = 00225 "Error in program memory mapping; %s"; 00226 Diag_Msg[DIAG_PRP_ICALL] = 00227 "Cannot handle indirect call; %s"; 00228 Diag_Msg[DIAG_PRP_REF_PARAM] = 00229 "Purple cannot trace reference parameter (%d) value; %s"; 00230 Diag_Msg[DIAG_PRP_CANNOT_HANDLE_CONSTRUCT] = 00231 "Purple cannot handle construct: %s"; 00232 Diag_Msg[DIAG_PRP_EDIT_OUTPUT] = 00233 "You need to edit the output file: %s"; 00234 00235 Diag_Warn_Count = 0; 00236 } /* Diag_Init */ 00237 00238 00239 void Diag_Exit(void) 00240 { 00241 /* Close the diagnostics file if one is open */ 00242 if (Diag_File != NULL) 00243 { 00244 fclose (Diag_File); 00245 Diag_File = NULL; 00246 } 00247 } /* Diag_Exit */ 00248 00249 00250 void Diag_Set_Phase(const char *phase_name) 00251 { 00252 Set_Error_Phase(phase_name); /* Initiate the common error handler */ 00253 (void)strncpy(Diag_Phase_Name, phase_name, Diag_Phase_Name_Len); 00254 Diag_Phase_Name[Diag_Phase_Name_Len] = '\0'; 00255 } /* Diag_Set_Phase */ 00256 00257 00258 void Diag_Set_File(const char *filename) 00259 { 00260 /* Initiate the common error handler */ 00261 Set_Error_File(filename); 00262 00263 /* Close the diagnostics file if one already is open */ 00264 if (Diag_File != NULL) 00265 { 00266 fclose(Diag_File); 00267 Diag_File = NULL; 00268 } 00269 00270 if (filename != NULL) 00271 { 00272 /* Delete the named file if it exists: */ 00273 if (Is_File(filename)) 00274 unlink(filename); 00275 00276 Diag_File = fopen(filename, "a"); 00277 if (Diag_File == NULL) 00278 fprintf(stderr, "Cannot open error-file: \"%s\"\n", filename); 00279 else if (Same_File(Diag_File, stderr)) 00280 { 00281 fclose(Diag_File); 00282 Diag_File = NULL; 00283 fprintf(stderr, "Cannot open stderr as alternate error file\n"); 00284 } 00285 } 00286 else 00287 fprintf(stderr, 00288 "Attempt to open name-less file as error file is ignored\n"); 00289 } /* Diag_Set_File */ 00290 00291 00292 void Diag_Set_Max_Diags(INT max_allowed_diags) 00293 { 00294 Diag_Max_Diags = max_allowed_diags; 00295 } /* Diag_Set_Max_Diags */ 00296 00297 00298 INT Diag_Get_Warn_Count(void) 00299 { 00300 return Diag_Warn_Count; 00301 } /* Diag_Get_Warn_Count */ 00302 00303 00304 void Diag_Set_Location(const char *file_name, INT line_number) 00305 { 00306 Diag_File_Location = file_name; 00307 Diag_Line_Location = line_number; 00308 } /* Diag_Set_Location */ 00309 00310 00311 void Diag_Set_Srcpos(SRCPOS srcpos) 00312 { 00313 USRCPOS usrcpos; 00314 USRCPOS_srcpos(usrcpos) = srcpos; 00315 00316 Diag_SrcLine_Location = USRCPOS_linenum(usrcpos); 00317 Diag_SrcCol_Location = USRCPOS_column(usrcpos); 00318 } /* Diag_Set_Srcpos */ 00319 00320 00321 void Diag_Warning(DIAG_CODE code, ...) 00322 { 00323 char diag_char[512]; 00324 va_list arg_ptr; 00325 00326 if (Diag_Max_Diags > Diag_Warn_Count) 00327 { 00328 if (Diag_File_Location != NULL) 00329 (void)sprintf(&diag_char[0], 00330 "%s(%s:%d): WARNING %d: %s\n", 00331 Diag_Phase_Name, 00332 Diag_File_Location, Diag_Line_Location, 00333 code, 00334 Diag_Msg[code]); 00335 else 00336 (void)sprintf(&diag_char[0], 00337 "%s: WARNING %d: %s\n", 00338 Diag_Phase_Name, code, Diag_Msg[code]); 00339 00340 va_start(arg_ptr, code); 00341 vfprintf(stderr, &diag_char[0], arg_ptr); 00342 va_end(arg_ptr); 00343 00344 Diag_Warn_Count++; 00345 } 00346 } /* Diag_Warning */ 00347 00348 00349 void Diag_Fatal(DIAG_CODE code, ...) 00350 { 00351 char diag_char[512]; 00352 va_list arg_ptr; 00353 00354 if (Diag_File_Location != NULL) 00355 (void)sprintf(&diag_char[0], 00356 "%s(%s:%d): FATAL ERROR: %s\n", 00357 Diag_Phase_Name, 00358 Diag_File_Location, Diag_Line_Location, 00359 Diag_Msg[code]); 00360 else 00361 (void)sprintf(&diag_char[0], 00362 "%s: FATAL ERROR: %s\n", 00363 Diag_Phase_Name, Diag_Msg[code]); 00364 00365 va_start(arg_ptr, code); 00366 vfprintf(stderr, &diag_char[0], arg_ptr); 00367 va_end(arg_ptr); 00368 00369 exit(1); 00370 } /* Diag_Fatal */ 00371 00372 00373 void Diag_User_Warning(DIAG_CODE code, ...) 00374 { 00375 char diag_char[512]; 00376 va_list arg_ptr; 00377 00378 (void)sprintf(&diag_char[0], 00379 "WARNING %d: line %d, column %d: %s\n", 00380 code, 00381 Diag_SrcLine_Location, 00382 Diag_SrcCol_Location, 00383 Diag_Msg[code]); 00384 00385 va_start(arg_ptr, code); 00386 vfprintf(stderr, &diag_char[0], arg_ptr); 00387 va_end(arg_ptr); 00388 } /* Diag_User_Warning */ 00389 00390 00391 void Diag_User_Fatal(DIAG_CODE code, ...) 00392 { 00393 char diag_char[512]; 00394 va_list arg_ptr; 00395 00396 (void)sprintf(&diag_char[0], 00397 "FATAL ERROR: line %d, column %d: %s\n", 00398 Diag_SrcLine_Location, 00399 Diag_SrcCol_Location, 00400 Diag_Msg[code]); 00401 00402 va_start(arg_ptr, code); 00403 vfprintf(stderr, &diag_char[0], arg_ptr); 00404 va_end(arg_ptr); 00405 00406 exit(1); 00407 } /* Diag_User_Fatal */ 00408 00409 00410 void Diag_Warning_Srcpos(DIAG_CODE code, ...) 00411 { 00412 char diag_char[512]; 00413 va_list arg_ptr; 00414 00415 if (Diag_Max_Diags > Diag_Warn_Count) 00416 { 00417 if (Diag_File_Location != NULL) 00418 (void)sprintf(&diag_char[0], 00419 "%s(%s:%d): WARNING %d: line %d: %s\n", 00420 Diag_Phase_Name, 00421 Diag_File_Location, Diag_Line_Location, 00422 code, 00423 Diag_SrcLine_Location, 00424 Diag_Msg[code]); 00425 else 00426 (void)sprintf(&diag_char[0], 00427 "%s: WARNING %d: line %d: %s\n", 00428 Diag_Phase_Name, 00429 code, 00430 Diag_SrcLine_Location, 00431 Diag_Msg[code]); 00432 00433 va_start(arg_ptr, code); 00434 vfprintf(stderr, &diag_char[0], arg_ptr); 00435 va_end(arg_ptr); 00436 00437 Diag_Warn_Count++; 00438 } 00439 } /* Diag_Warning_Srcpos */ 00440 00441 00442 void Diag_Fatal_Srcpos(DIAG_CODE code, ...) 00443 { 00444 char diag_char[512]; 00445 va_list arg_ptr; 00446 00447 if (Diag_File_Location != NULL) 00448 (void)sprintf(&diag_char[0], 00449 "%s(%s:%d): FATAL ERROR: line %d: %s\n", 00450 Diag_Phase_Name, 00451 Diag_File_Location, Diag_Line_Location, 00452 Diag_SrcLine_Location, 00453 Diag_Msg[code]); 00454 else 00455 (void)sprintf(&diag_char[0], 00456 "%s: FATAL ERROR: line %d: %s\n", 00457 Diag_Phase_Name, Diag_SrcLine_Location, Diag_Msg[code]); 00458 00459 va_start(arg_ptr, code); 00460 vfprintf(stderr, &diag_char[0], arg_ptr); 00461 va_end(arg_ptr); 00462 00463 exit(1); 00464 } /* Diag_Fatal_Srcpos */