|
OpenADFortTk (basic)
|
00001 // ########################################################## 00002 // # This file is part of OpenADFortTk. # 00003 // # The full COPYRIGHT notice can be found in the top # 00004 // # level directory of the OpenADFortTk source tree. # 00005 // # For more information visit # 00006 // # http://www.mcs.anl.gov/openad # 00007 // ########################################################## 00008 00009 /* ==================================================================== 00010 * ==================================================================== 00011 * 00012 * Description: 00013 * 00014 * This hides the error diagnostics machinery, such that we 00015 * can define our own or rely on some existing facilities. 00016 * 00017 * For now, we just implement a simple error diagnostics scheme 00018 * which does not rely on any other existing scheme. 00019 * 00020 * ==================================================================== 00021 * ==================================================================== 00022 */ 00023 00024 #include <stdarg.h> 00025 #include <errno.h> /* for sys_errlist */ 00026 #include <stdio.h> /* for stderr */ 00027 00028 #include "Open64BasicTypes.h" 00029 #include "file_util.h" 00030 00031 #include "IFDiagnostics.h" 00032 00033 00034 int DBG_LVL_PUB = 0; 00035 00036 static char Diag_Phase_Name[80] = ""; 00037 static FILE *Diag_File = NULL; 00038 static int Diag_Max_Diags = 10; /* Default */ 00039 static int Diag_Warn_Count = 0; 00040 static const char *Diag_File_Location = NULL; 00041 static int Diag_Line_Location = 0; 00042 00043 static const char *Diag_Msg[DIAG_LAST+1]; 00044 00045 00046 void 00047 Diag_Init(void) 00048 { 00049 int diag; 00050 00051 /* Initiate the Diag_Msg[] table to a standard error message. 00052 */ 00053 for (diag = DIAG_FIRST; diag <= DIAG_LAST; diag++) 00054 Diag_Msg[diag] = "*** Unknown diagnostics code ***"; 00055 00056 /* Initiate the Diag_Msg[] table for well-defined error codes. 00057 */ 00058 Diag_Msg[DIAG_A_STRING] = "%s"; 00059 Diag_Msg[DIAG_UNIMPLEMENTED] = "TODO: Unimplemented feature: %s"; 00060 Diag_Msg[DIAG_UNKNOWN_CMD_LINE_OPTION] = "Unknown command-line option: %s"; 00061 Diag_Msg[DIAG_CANNOT_OPEN_FILE] = "Cannot open file (%s), errno=%d"; 00062 Diag_Msg[DIAG_CANNOT_CLOSE_FILE] = "Cannot close file (%s), errno=%d"; 00063 00064 Diag_Msg[DIAG_W2F_CANNOT_HANDLE_OPC] = 00065 "cannot handle opcode %s (%d)"; 00066 Diag_Msg[DIAG_W2F_UNEXPECTED_OPC] = 00067 "unexpected opcode in %s()"; 00068 Diag_Msg[DIAG_W2F_UNEXPECTED_IOS] = 00069 "unexpected IO statement kind %s in %s()"; 00070 Diag_Msg[DIAG_W2F_UNEXPECTED_IOU] = 00071 "unexpected IO unit kind %s in %s()"; 00072 Diag_Msg[DIAG_W2F_UNEXPECTED_IOF] = 00073 "unexpected IO format kind %s in %s()"; 00074 Diag_Msg[DIAG_W2F_UNEXPECTED_IOC] = 00075 "unexpected IO control kind %s in %s()"; 00076 Diag_Msg[DIAG_W2F_UNEXPECTED_IOL] = 00077 "unexpected IO list kind %s in %s()"; 00078 Diag_Msg[DIAG_W2F_UNEXPECTED_INITV] = 00079 "unexpected INITV kind %d in %s()"; 00080 Diag_Msg[DIAG_W2F_UNEXPECTED_DOLOOP_BOUNDOP] = 00081 "unexpected opcode (%s) for DO loop bound in %s()"; 00082 Diag_Msg[DIAG_W2F_UNEXPECTED_IMPLIED_DOLOOP] = 00083 "unexpected form of implied do-loop in %s(); Cannot calculate bounds"; 00084 Diag_Msg[DIAG_W2F_UNEXPECTED_RETURNSITE] = 00085 "RETURNSITE out of sequence in %s()"; 00086 Diag_Msg[DIAG_W2F_UNEXPECTED_CALLSITE] = 00087 "CALLSITE out of sequence in %s()"; 00088 Diag_Msg[DIAG_W2F_UNEXPECTED_SUBSTRING_REF] = 00089 "Unexpected (sub)string reference in %s()"; 00090 Diag_Msg[DIAG_W2F_UNEXPEXTED_RETURNREG_USE] = 00091 "Unexpected usage of return-registers detected in %s()"; 00092 Diag_Msg[DIAG_W2F_UNEXPEXTED_OFFSET] = 00093 "Unexpected offset (%d) for memory location in %s()"; 00094 Diag_Msg[DIAG_W2F_UNEXPEXTED_NULL_PTR] = 00095 "Unexpected NULL value for %s in %s()"; 00096 Diag_Msg[DIAG_W2F_NONEXISTENT_FLD_PATH] = 00097 "Non-existent path to an FLD of the given object type in %s()"; 00098 Diag_Msg[DIAG_W2F_CANNOT_LDA_PREG] = 00099 "Cannot take the address of a pseudo-register"; 00100 Diag_Msg[DIAG_W2F_CANNOT_DEREF] = 00101 "Cannot dereference pointer variable in %s(); No pointee specification"; 00102 Diag_Msg[DIAG_W2F_UNEXPECTED_NUM_KIDS] = 00103 "Unexpected number of kids (%d), expected %d kids for %s()"; 00104 Diag_Msg[DIAG_W2F_UNEXPECTED_CVT] = 00105 "unexpected conversion from %s to %s in %s()"; /* Use MTYPE_name() */ 00106 Diag_Msg[DIAG_W2F_UNEXPECTED_CONTEXT] = 00107 "unexpected context of translation for %s()"; 00108 00109 Diag_Msg[DIAG_W2F_UNEXPECTED_TYPE_KIND] = 00110 "unexpected TY_kind (%d) in %s()"; 00111 Diag_Msg[DIAG_W2F_UNEXPECTED_TYPE_SIZE] = 00112 "unexpected TY_size (%d) in %s()"; 00113 Diag_Msg[DIAG_W2F_UNEXPECTED_BTYPE] = 00114 "unexpected TY_btype (%s) in %s()"; /* Use MTYPE_name() */ 00115 Diag_Msg[DIAG_W2F_EXPECTED_PTR_TO_CHARACTER] = 00116 "expected pointer to character operands in %s()"; 00117 Diag_Msg[DIAG_W2F_EXPECTED_PTR] = 00118 "expected pointer TY in %s()"; 00119 Diag_Msg[DIAG_W2F_UNEXPECTED_SYMBOL] = 00120 "unexpected form of symbol in %s()"; 00121 Diag_Msg[DIAG_W2F_UNEXPECTED_SYMCLASS] = 00122 "unexpected ST_symclass (%d) in %s()"; 00123 Diag_Msg[DIAG_W2F_UNEXPECTED_STORECLASS] = 00124 "unexpected ST_sclass (%d) in %s()"; 00125 Diag_Msg[DIAG_W2F_UNEXPECTED_SYM_CONST] = 00126 "unexpected symbolic constant in %s()"; 00127 Diag_Msg[DIAG_W2F_UNEXPECTED_PRAGMA] = 00128 "unexpected pragma kind in %s()"; 00129 Diag_Msg[DIAG_W2F_MISPLACED_PRAGMA] = 00130 "pragma %s will be misplaced in output, and will be emitted as comment"; 00131 Diag_Msg[DIAG_W2F_EXPECTED_IDNAME] = 00132 "expected OPC_IDNAME in %s()"; 00133 Diag_Msg[DIAG_W2F_INCOMPATIBLE_TYS] = 00134 "incompatible types in %s()"; 00135 Diag_Msg[DIAG_W2F_DECLARE_RETURN_PARAM] = 00136 "should not declare return parameter: %s()"; 00137 Diag_Msg[DIAG_W2F_BUFFER_ERROR] = 00138 "Error in buffer access: %s"; 00139 00140 Diag_Warn_Count = 0; 00141 } /* Diag_Init */ 00142 00143 00144 void 00145 Diag_Exit(void) 00146 { 00147 /* Close the diagnostics file if one is open */ 00148 if (Diag_File != NULL) { 00149 fclose (Diag_File); 00150 Diag_File = NULL; 00151 } 00152 } 00153 00154 00155 void 00156 Diag_Set_Phase(const char *phase_name) 00157 { 00158 Set_Error_Phase(phase_name); /* Initiate the common error handler */ 00159 (void)strcpy(Diag_Phase_Name, phase_name); 00160 } 00161 00162 00163 void 00164 Diag_Set_File(const char *filename) 00165 { 00166 /* Initiate the common error handler */ 00167 Set_Error_File(filename); 00168 00169 /* Close the diagnostics file if one already is open */ 00170 if (Diag_File != NULL) 00171 { 00172 fclose(Diag_File); 00173 Diag_File = NULL; 00174 } 00175 00176 if (filename != NULL) 00177 { 00178 /* Delete the named file if it exists: */ 00179 if (Is_File(filename)) 00180 unlink(filename); 00181 00182 Diag_File = fopen(filename, "a"); 00183 if (Diag_File == NULL) 00184 fprintf(stderr, "Cannot open error-file: \"%s\"\n", filename); 00185 else if (Same_File(Diag_File, stderr)) 00186 { 00187 fclose(Diag_File); 00188 Diag_File = NULL; 00189 fprintf(stderr, "Cannot open stderr as alternate error file\n"); 00190 } 00191 } 00192 else 00193 fprintf(stderr, 00194 "Attempt to open name-less file as error file is ignored\n"); 00195 } 00196 00197 00198 void 00199 Diag_Set_Max_Diags(int max_allowed_diags) 00200 { 00201 Diag_Max_Diags = max_allowed_diags; 00202 } 00203 00204 00205 int 00206 Diag_Get_Warn_Count(void) 00207 { 00208 return Diag_Warn_Count; 00209 } 00210 00211 00212 //*************************************************************************** 00213 00214 void 00215 Diag_Set_Location(const char *file_name, int line_number) 00216 { 00217 Diag_File_Location = file_name; 00218 Diag_Line_Location = line_number; 00219 } 00220 00221 00222 void 00223 Diag_Warning(DIAG_CODE code, ...) 00224 { 00225 char diag_char[512]; 00226 va_list arg_ptr; 00227 00228 if (Diag_Max_Diags > Diag_Warn_Count) 00229 { 00230 if (Diag_File_Location != NULL) 00231 (void)sprintf(&diag_char[0], 00232 "%s(%s:%d): WARNING %d: %s\n", 00233 Diag_Phase_Name, 00234 Diag_File_Location, Diag_Line_Location, 00235 code, 00236 Diag_Msg[code]); 00237 else 00238 (void)sprintf(&diag_char[0], 00239 "%s: WARNING %d: %s\n", 00240 Diag_Phase_Name, code, Diag_Msg[code]); 00241 00242 va_start(arg_ptr, code); 00243 vfprintf(stderr, &diag_char[0], arg_ptr); 00244 va_end(arg_ptr); 00245 00246 Diag_Warn_Count++; 00247 } 00248 } /* Diag_Warning */ 00249 00250 00251 void 00252 Diag_Fatal(DIAG_CODE code, ...) 00253 { 00254 char diag_char[512]; 00255 va_list arg_ptr; 00256 00257 if (Diag_File_Location != NULL) { 00258 sprintf(&diag_char[0], "%s(%s:%d): FATAL ERROR: %s\n", 00259 Diag_Phase_Name, 00260 Diag_File_Location, Diag_Line_Location, 00261 Diag_Msg[code]); 00262 } else { 00263 sprintf(&diag_char[0], "%s: FATAL ERROR: %s\n", 00264 Diag_Phase_Name, Diag_Msg[code]); 00265 } 00266 00267 va_start(arg_ptr, code); 00268 vfprintf(stderr, &diag_char[0], arg_ptr); 00269 va_end(arg_ptr); 00270 00271 exit(1); 00272 } /* Diag_Fatal */ 00273