OpenADFortTk (basic)
src/lib/support/Open64IRInterface/IFDiagnostics.h
Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 #ifndef IFDiagnostics_INCLUDED
00003 #define IFDiagnostics_INCLUDED
00004 /* ====================================================================
00005  * ====================================================================
00006  *
00007  * Description:
00008  *    A generic module for diagnostics reporting, where an enumeration
00009  *    of error codes will support options to turn warnings on or off.
00010  *    It possible to initialize and exit this module several times, but
00011  *    typically it is initiated only once (when the executable is started
00012  *    up) and excited only once (when the executable is exited).
00013  *
00014  *    Initialization
00015  *    --------------
00016  *
00017  *       Diag_Init:
00018  *          This module should be initialized as early as possible, and
00019  *          certainly before any of the other facilities provided through
00020  *          this interface are referenced.
00021  *
00022  *       Diag_Exit:
00023  *          This module should be terminated as late as possible, and
00024  *          certainly after all potential references to any of the other
00025  *          facilities provided through this interface (with possible
00026  *          exception of Diag_Get_Warn_Count).
00027  *
00028  *       Diag_Set_Phase:
00029  *          A string identifying the executable and possibly the stage
00030  *          of computation within this executable.  The phase name is 
00031  *          kept in a hidden character buffer, and it must not exceed
00032  *          80 characters in size (including the terminating '\0' char).
00033  *          By default the phase is set to be an empty string.
00034  *
00035  *       Diag_Set_File:
00036  *          All diagnostics messages are emitted to stderr (see <stdio.h>),
00037  *          and this routine will open an output file (as named) and also
00038  *          cause diagnostics to be streamed through to that file.
00039  *
00040  *       Diag_Set_Max_Diags:
00041  *          The maximum number of diagnostics messages that will be emitted
00042  *          before the execution is terminated (zero (0) means unlimited.
00043  *          Initially, unlimited.
00044  *          
00045  *       Diag_Get_Warn_Count:
00046  *          A counter of the number of warnings that have been emitted.
00047  *          Initially, zero (0).  Note that this counter will not be reset
00048  *          by a call to Diag_Exit().
00049  *          
00050  *
00051  *    Diagnostics Reporting
00052  *    ---------------------
00053  *       The arguments (diag_args) must have the format:
00054  *
00055  *          (DIAG_CODE, args)
00056  *
00057  *       where DIAG_CODE is one of the enumerated values and args is
00058  *       a comma separated list of values corresponding to the format
00059  *       directives in the diagnostic message (see IFDiagnostics.cpp).
00060  *       When "Is_True_On" is defined, the location of the ASSERT in
00061  *       the compiler sources is emitted as part of the diagnostics.
00062  *
00063  *       ASSERT_WARN:
00064  *          Given a boolean truth expression, emit a warning diagnostics
00065  *          based on the diag_args when the truth-value is FALSE.
00066  *
00067  *       ASSERT_FATAL:
00068  *          Given a boolean truth expression, emit a fatal error 
00069  *          diagnostics based on the diag_args when the truth-value 
00070  *          is FALSE and exit with error code (1).
00071  *
00072  *       ASSERT_DBG_WARN:
00073  *          Same as ASSERT_WARN, but only to be emitted during the
00074  *          development of the tool.  I.e. customer's should never
00075  *          see this fatal error, and code to work around the problem
00076  *          must follow the assertion.
00077  *
00078  *       ASSERT_DBG_FATAL:
00079  *          Same as ASSERT_FATAL, but only to be emitted during the
00080  *          development of the tool.  I.e. customer's should never
00081  *          see this fatal error.
00082  *
00083  * ====================================================================
00084  * ====================================================================
00085  */
00086 
00087 //************************* System Include Files ****************************
00088 
00089 #include <stdio.h>                  /* for stderr */
00090 
00091 // Private debugging level: messages for in-house debugging [0-9]
00092 #define DBG_LVL 0
00093 
00094 // Public debugging level: stuff that a few users may find interesting [0-9]
00095 extern int DBG_LVL_PUB; // default: 0
00096 
00097 #define DBGMSG(level, ...)                                            \
00098   if (level <= DBG_LVL) {                                             \
00099     fprintf(stderr, "Open64IRInterface:[debuglevel=%d]: ", level);                            \
00100     fprintf(stderr, __VA_ARGS__); fputs("\n", stderr); }
00101 
00102 #define DBGMSG_PUB(level, ...)                                        \
00103   if (level <= DBG_LVL_PUB) {                                         \
00104     fprintf(stderr, "Open64IRInterface:[debuglevel=%d]: ", level);                             \
00105     fprintf(stderr, __VA_ARGS__); fputs("\n", stderr); }
00106 
00107 #define ERRMSG(...)                                                   \
00108   { fputs("error", stderr);                                           \
00109     if (DBG_LVL) {                                                    \
00110       fprintf(stderr, "Open64IRInterface: [%s:%d]", __FILE__, __LINE__); }              \
00111     fputs(": ", stderr); fprintf(stderr, __VA_ARGS__); fputs("\n", stderr); }
00112 
00113 #define DIE(...) ERRMSG(__VA_ARGS__); { exit(1); }
00114 
00115 
00116 #define IFDBG(level) if (level <= DBG_LVL)
00117 
00118 #define IFDBG_PUB(level) if (level <= DBG_LVL_PUB)
00119 
00120 //***************************************************************************
00121 
00122 
00123       /* ------------ Initialization and finalization -------------*/
00124       /* ----------------------------------------------------------*/
00125 
00126 extern void Diag_Init(void);
00127 extern void Diag_Exit(void);
00128 extern void Diag_Set_Phase(const char *phase_name);
00129 extern void Diag_Set_File(const char *filename);
00130 extern void Diag_Set_Max_Diags(int max_allowed_diags);
00131 extern int  Diag_Get_Warn_Count(void);
00132 
00133 
00134       /* -------------- Diagnostic code enumeration ---------------*/
00135       /* ----------------------------------------------------------*/
00136 
00137 typedef enum Diag_Code
00138 {
00139    DIAG_FIRST = 0,
00140    DIAG_A_STRING = 0,
00141    DIAG_UNKNOWN_CMD_LINE_OPTION = 1,
00142    DIAG_UNIMPLEMENTED = 2,
00143    DIAG_CANNOT_OPEN_FILE = 3,
00144    DIAG_CANNOT_CLOSE_FILE = 4,
00145 
00146    /* whirl2f statement and expression diagnostics */
00147    DIAG_W2F_FIRST = 100,
00148    DIAG_W2F_CANNOT_HANDLE_OPC = 101,            /* WN related diagnostics */
00149    DIAG_W2F_UNEXPECTED_OPC = 110,
00150    DIAG_W2F_UNEXPECTED_IOS = 111,
00151    DIAG_W2F_UNEXPECTED_IOU = 112,
00152    DIAG_W2F_UNEXPECTED_IOF = 113,
00153    DIAG_W2F_UNEXPECTED_IOC = 114,
00154    DIAG_W2F_UNEXPECTED_IOL = 115,
00155    DIAG_W2F_UNEXPECTED_INITV = 116,
00156    DIAG_W2F_UNEXPECTED_DOLOOP_BOUNDOP = 117,
00157    DIAG_W2F_UNEXPECTED_IMPLIED_DOLOOP = 118,
00158    DIAG_W2F_UNEXPECTED_RETURNSITE = 119,
00159    DIAG_W2F_UNEXPECTED_CALLSITE = 120,
00160    DIAG_W2F_UNEXPECTED_SUBSTRING_REF = 121,
00161    DIAG_W2F_UNEXPEXTED_RETURNREG_USE = 122,
00162    DIAG_W2F_UNEXPEXTED_OFFSET = 123,
00163    DIAG_W2F_UNEXPEXTED_NULL_PTR = 124,
00164    DIAG_W2F_NONEXISTENT_FLD_PATH = 125,
00165    DIAG_W2F_CANNOT_LDA_PREG = 126,
00166    DIAG_W2F_CANNOT_DEREF = 127,
00167    DIAG_W2F_UNEXPECTED_NUM_KIDS = 128,
00168    DIAG_W2F_UNEXPECTED_CVT = 129,
00169    DIAG_W2F_UNEXPECTED_CONTEXT = 130,
00170 
00171    /* whirl2f symbol-table diagnostics */
00172    DIAG_W2F_UNEXPECTED_TYPE_KIND = 203,          /* symtab diagnostics */
00173    DIAG_W2F_UNEXPECTED_TYPE_SIZE = 204,
00174    DIAG_W2F_UNEXPECTED_BTYPE = 205,
00175    DIAG_W2F_EXPECTED_PTR_TO_CHARACTER = 206,
00176    DIAG_W2F_EXPECTED_PTR = 207,
00177    DIAG_W2F_UNEXPECTED_SYMBOL = 208,
00178    DIAG_W2F_UNEXPECTED_SYMCLASS = 209,
00179    DIAG_W2F_UNEXPECTED_STORECLASS = 210,
00180    DIAG_W2F_UNEXPECTED_SYM_CONST = 211,
00181    DIAG_W2F_UNEXPECTED_PRAGMA = 212,
00182    DIAG_W2F_MISPLACED_PRAGMA = 213,
00183    DIAG_W2F_EXPECTED_IDNAME = 214,
00184    DIAG_W2F_INCOMPATIBLE_TYS = 215,
00185    DIAG_W2F_DECLARE_RETURN_PARAM = 216,
00186    DIAG_W2F_BUFFER_ERROR = 217,
00187    DIAG_W2F_LAST = 217,
00188 
00189    DIAG_LAST = 542
00190 } DIAG_CODE;
00191 
00192 
00193       /* ------------------- Diagnostics macros -------------------*/
00194       /* ----------------------------------------------------------*/
00195 
00196 #ifdef Is_True_On
00197 
00198 #define ASSERT_WARN(a_truth, diag_args) \
00199    DIAG_ASSERT_LOC(a_truth, Diag_Warning, diag_args)
00200 #define ASSERT_FATAL(a_truth, diag_args) \
00201    DIAG_ASSERT_LOC(a_truth, Diag_Fatal, diag_args)
00202 #define ASSERT_DBG_WARN ASSERT_WARN
00203 #define ASSERT_DBG_FATAL ASSERT_FATAL
00204 
00205 #else /* !defined(Is_True_On) */
00206 
00207 #define ASSERT_WARN(a_truth, diag_args) \
00208    DIAG_ASSERT_NOLOC(a_truth, Diag_Warning, diag_args)
00209 #define ASSERT_FATAL(a_truth, diag_args) \
00210    DIAG_ASSERT_NOLOC(a_truth, Diag_Fatal, diag_args)
00211 # define ASSERT_DBG_WARN(a_truth, diag_args) ((void) 1)
00212 # define ASSERT_DBG_FATAL(a_truth, diag_args) ((void) 1)
00213 
00214 #endif /*Is_True_On*/
00215 
00216 
00217    /* ------- Hidden functions/macros (NEVER CALL THESE) -------*/
00218    /* ----------------------------------------------------------*/
00219 
00220 #define DIAG_ASSERT_LOC(a_truth, diag_handler, diag_args) \
00221    ((a_truth) ? \
00222     (void) 1 :  \
00223     (Diag_Set_Location(__FILE__, __LINE__), diag_handler  diag_args))
00224 
00225 #define DIAG_ASSERT_NOLOC(a_truth, diag_handler, diag_args) \
00226    ((a_truth) ? (void) 1 : diag_handler  diag_args)
00227 
00228 extern void Diag_Set_Location(const char *file_name, int line_number);
00229 extern void Diag_Warning(DIAG_CODE code, ...);
00230 extern void Diag_Fatal(DIAG_CODE code, ...);
00231 
00232 #endif
00233 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines