Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
diagnostics.h
Go to the documentation of this file.
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 #ifndef diagnostics_INCLUDED
00037 #define diagnostics_INCLUDED
00038 /* ====================================================================
00039  * ====================================================================
00040  *
00041  *
00042  * Revision history:
00043  *    13-Apr-95 - Original Version
00044  *
00045  * Description:
00046  *    A generic module for diagnostics reporting, where an enumeration
00047  *    of error codes will support options to turn warnings on or off.
00048  *    It possible to initialize and exit this module several times, but
00049  *    typically it is initiated only once (when the executable is started
00050  *    up) and excited only once (when the executable is exited).
00051  *
00052  *    Initialization
00053  *    --------------
00054  *
00055  *       Diag_Init:
00056  *          This module should be initialized as early as possible, and
00057  *          certainly before any of the other facilities provided through
00058  *          this interface are referenced.
00059  *
00060  *       Diag_Exit:
00061  *          This module should be terminated as late as possible, and
00062  *          certainly after all potential references to any of the other
00063  *          facilities provided through this interface (with possible
00064  *          exception of Diag_Get_Warn_Count).
00065  *
00066  *       Diag_Set_Phase:
00067  *          A string identifying the executable and possibly the stage
00068  *          of computation within this executable.  The phase name is 
00069  *          kept in a hidden character buffer, and it must not exceed
00070  *          80 characters in size (including the terminating '\0' char).
00071  *          By default the phase is set to be an empty string.
00072  *
00073  *       Diag_Set_File:
00074  *          All diagnostics messages are emitted to stderr (see <stdio.h>),
00075  *          and this routine will open an output file (as named) and also
00076  *          cause diagnostics to be streamed through to that file.
00077  *
00078  *       Diag_Set_Max_Diags:
00079  *          The maximum number of diagnostics messages that will be emitted
00080  *          before the execution is terminated (zero (0) means unlimited.
00081  *          Initially, unlimited.
00082  *          
00083  *       Diag_Get_Warn_Count:
00084  *          A counter of the number of warnings that have been emitted.
00085  *          Initially, zero (0).  Note that this counter will not be reset
00086  *          by a call to Diag_Exit().
00087  *          
00088  *
00089  *    User Errors
00090  *    -----------
00091  *       The arguments (diag_args) must have the format:
00092  *
00093  *          (DIAG_CODE, args)
00094  *
00095  *       where DIAG_CODE is one of the enumerated values and args is
00096  *       a comma separated list of values corresponding to the format
00097  *       directives in the diagnostic message (see diagnostics.c).
00098  *
00099  *       USER_WARNING: 
00100  *          Emits warnings about a condition in the original source
00101  *          program, in terms of line/column numbers from the original
00102  *          source-file.
00103  *       USER_WARNING: 
00104  *          Emits a fatal error and terminates execution without further 
00105  *          processing (EXIT(1)).
00106  *
00107  *
00108  *    Diagnostics Reporting
00109  *    ---------------------
00110  *       The arguments (diag_args) must have the format:
00111  *
00112  *          (DIAG_CODE, args)
00113  *
00114  *       where DIAG_CODE is one of the enumerated values and args is
00115  *       a comma separated list of values corresponding to the format
00116  *       directives in the diagnostic message (see diagnostics.c).
00117  *       When "Is_True_On" is defined, the location of the ASSERT in
00118  *       the compiler sources is emitted as part of the diagnostics.
00119  *
00120  *       ASSERT_WARN:
00121  *          Given a boolean truth expression, emit a warning diagnostics
00122  *          based on the diag_args when the truth-value is FALSE.
00123  *
00124  *       ASSERT_FATAL:
00125  *          Given a boolean truth expression, emit a fatal error 
00126  *          diagnostics based on the diag_args when the truth-value 
00127  *          is FALSE and exit with error code (1).
00128  *
00129  *       ASSERT_WARN_SRCPOS:
00130  *          Same as ASSERT_WARN, but will include the srcpos in the
00131  *          emitted diagnostic message.
00132  *
00133  *       ASSERT_FATAL_SRCPOS:
00134  *          Same as ASSERT_FATAL, but will include the srcpos in the
00135  *          emitted diagnostic message.
00136  *
00137  *       ASSERT_DBG_WARN:
00138  *          Same as ASSERT_WARN, but only to be emitted during the
00139  *          development of the tool.  I.e. customer's should never
00140  *          see this fatal error, and code to work around the problem
00141  *          must follow the assertion.
00142  *
00143  *       ASSERT_DBG_FATAL:
00144  *          Same as ASSERT_FATAL, but only to be emitted during the
00145  *          development of the tool.  I.e. customer's should never
00146  *          see this fatal error.
00147  *
00148  * ====================================================================
00149  * ====================================================================
00150  */
00151       /* ------------ Initialization and finalization -------------*/
00152       /* ----------------------------------------------------------*/
00153 
00154 extern void Diag_Init(void);
00155 extern void Diag_Exit(void);
00156 extern void Diag_Set_Phase(const char *phase_name);
00157 extern void Diag_Set_File(const char *filename);
00158 extern void Diag_Set_Max_Diags(INT max_allowed_diags);
00159 extern INT  Diag_Get_Warn_Count(void);
00160 
00161 
00162       /* -------------- Diagnostic code enumeration ---------------*/
00163       /* ----------------------------------------------------------*/
00164 
00165 typedef enum Diag_Code
00166 {
00167    DIAG_FIRST = 0,
00168    DIAG_A_STRING = 0,
00169    DIAG_UNKNOWN_CMD_LINE_OPTION = 1,
00170    DIAG_UNIMPLEMENTED = 2,
00171    DIAG_CANNOT_OPEN_FILE = 3,
00172    DIAG_CANNOT_CLOSE_FILE = 4,
00173 
00174    /* whirl2f statement and expression diagnostics */
00175    DIAG_W2F_FIRST = 100,
00176    DIAG_W2F_CANNOT_HANDLE_OPC = 101,            /* WN related diagnostics */
00177    DIAG_W2F_UNEXPECTED_OPC = 110,
00178    DIAG_W2F_UNEXPECTED_IOS = 111,
00179    DIAG_W2F_UNEXPECTED_IOU = 112,
00180    DIAG_W2F_UNEXPECTED_IOF = 113,
00181    DIAG_W2F_UNEXPECTED_IOC = 114,
00182    DIAG_W2F_UNEXPECTED_IOL = 115,
00183    DIAG_W2F_UNEXPECTED_INITV = 116,
00184    DIAG_W2F_UNEXPECTED_DOLOOP_BOUNDOP = 117,
00185    DIAG_W2F_UNEXPECTED_IMPLIED_DOLOOP = 118,
00186    DIAG_W2F_UNEXPECTED_RETURNSITE = 119,
00187    DIAG_W2F_UNEXPECTED_CALLSITE = 120,
00188    DIAG_W2F_UNEXPECTED_SUBSTRING_REF = 121,
00189    DIAG_W2F_UNEXPEXTED_RETURNREG_USE = 122,
00190    DIAG_W2F_UNEXPEXTED_OFFSET = 123,
00191    DIAG_W2F_UNEXPEXTED_NULL_PTR = 124,
00192    DIAG_W2F_NONEXISTENT_FLD_PATH = 125,
00193    DIAG_W2F_CANNOT_LDA_PREG = 126,
00194    DIAG_W2F_CANNOT_DEREF = 127,
00195    DIAG_W2F_UNEXPECTED_NUM_KIDS = 128,
00196    DIAG_W2F_UNEXPECTED_CVT = 129,
00197    DIAG_W2F_UNEXPECTED_CONTEXT = 130,
00198 
00199    /* whirl2f symbol-table diagnostics */
00200    DIAG_W2F_UNEXPECTED_TYPE_KIND = 203,          /* symtab diagnostics */
00201    DIAG_W2F_UNEXPECTED_TYPE_SIZE = 204,
00202    DIAG_W2F_UNEXPECTED_BTYPE = 205,
00203    DIAG_W2F_EXPECTED_PTR_TO_CHARACTER = 206,
00204    DIAG_W2F_EXPECTED_PTR = 207,
00205    DIAG_W2F_UNEXPECTED_SYMBOL = 208,
00206    DIAG_W2F_UNEXPECTED_SYMCLASS = 209,
00207    DIAG_W2F_UNEXPECTED_STORECLASS = 210,
00208    DIAG_W2F_UNEXPECTED_SYM_CONST = 211,
00209    DIAG_W2F_UNEXPECTED_PRAGMA = 212,
00210    DIAG_W2F_MISPLACED_PRAGMA = 213,
00211    DIAG_W2F_EXPECTED_IDNAME = 214,
00212    DIAG_W2F_INCOMPATIBLE_TYS = 215,
00213    DIAG_W2F_DECLARE_RETURN_PARAM = 216,
00214    DIAG_W2F_BUFFER_ERROR = 217,
00215    DIAG_W2F_LAST = 217,
00216 
00217    /* whirl2c diagnostics */
00218    DIAG_W2C_FIRST = 300,
00219    DIAG_W2C_CANNOT_HANDLE_OPC = 300,
00220    DIAG_W2C_UNEXPECTED_OPC = 301,
00221    DIAG_W2C_EXPECTED_IDNAME = 302,
00222    DIAG_W2C_LAST = 302, 
00223 
00224 
00225    /* purple diagnostics */
00226    DIAG_PRP_FIRST = 500,
00227    DIAG_PRP_OPTION_ILLEGAL = 501,
00228    DIAG_PRP_OPTION_MISSING_SRC = 502,
00229    DIAG_PRP_NAME_OVERFLOW = 503,
00230    DIAG_PRP_FILE_ERROR = 510,
00231    DIAG_PRP_FILE_CANNOT_OPEN = 511,
00232    DIAG_PRP_FILE_CANNOT_CLOSE = 512,
00233    DIAG_PRP_FILE_OVERWRITTEN = 513,
00234    DIAG_PRP_FILE_AT_END = 514,
00235    DIAG_PRP_FILE_NOT_OPEN = 515,
00236    DIAG_PRP_FILE_NOT_CLOSED = 516,
00237    DIAG_PRP_FILE_HEADER_ERROR = 517,
00238    DIAG_PRP_ITEM_INPUT_ERROR = 519,
00239    DIAG_PRP_EXPECTED_PURPLE_REGION = 520,
00240    DIAG_PRP_PREREQUISITE_CALL = 521,
00241    DIAG_PRP_EXPECTED_CONSTRAINT = 522,
00242    DIAG_PRP_UNEXPECTED_OPCODE = 523,
00243    DIAG_PRP_UNEXPECTED_TYPE= 524,
00244    DIAG_PRP_INVALID_LEXEME_KIND = 525,
00245    DIAG_PRP_INVALID_TRACE_ITEM_KIND = 526,
00246    DIAG_PRP_CANNOT_ASSIGN_OBJECT = 527,
00247    DIAG_PRP_ILLEGAL_SET = 528,
00248    DIAG_PRP_RVALUE_ERROR = 529,
00249    DIAG_PRP_PLACEHOLDER_ERROR = 530,
00250    DIAG_PRP_PREG_VALUE = 531,
00251    DIAG_PRP_MEM_VALUE = 532,
00252    DIAG_PRP_VALUE_SPACE = 533,
00253    DIAG_PRP_VARIABLE_DEF = 534,
00254    DIAG_PRP_DEFINED_MEM_SPACE = 535,
00255    DIAG_PRP_PU_MMAP = 536,
00256    DIAG_PRP_FILE_MMAP = 537,
00257    DIAG_PRP_PROGRAM_MMAP = 538,
00258    DIAG_PRP_ICALL = 539,
00259    DIAG_PRP_REF_PARAM = 540,
00260    DIAG_PRP_CANNOT_HANDLE_CONSTRUCT= 541,
00261    DIAG_PRP_EDIT_OUTPUT= 542,
00262    DIAG_PRP_LAST = 542,
00263 
00264    DIAG_LAST = 542
00265 } DIAG_CODE;
00266 
00267 
00268       /* ------------------- Diagnostics macros -------------------*/
00269       /* ----------------------------------------------------------*/
00270 
00271 #define USER_WARNING(a_truth, diag_args, wn) \
00272    DIAG_USER_SRCPOS(a_truth, Diag_User_Warning, diag_args, wn)
00273 
00274 #define USER_FATAL(a_truth, diag_args, wn) \
00275    DIAG_USER_SRCPOS(a_truth, Diag_User_Fatal, diag_args, wn)
00276 
00277 
00278 #ifdef Is_True_On
00279 
00280 #define ASSERT_WARN_SRCPOS(a_truth, diag_args, wn) \
00281    DIAG_ASSERT_LOC_SRCPOS(a_truth, Diag_Warning, diag_args, wn)
00282 #define ASSERT_FATAL_SRCPOS(a_truth, diag_args, wn) \
00283    DIAG_ASSERT_LOC_SRCPOS(a_truth, Diag_Fatal, diag_args, wn)
00284 #define ASSERT_WARN(a_truth, diag_args) \
00285    DIAG_ASSERT_LOC(a_truth, Diag_Warning, diag_args)
00286 #define ASSERT_FATAL(a_truth, diag_args) \
00287    DIAG_ASSERT_LOC(a_truth, Diag_Fatal, diag_args)
00288 #define ASSERT_DBG_WARN ASSERT_WARN
00289 #define ASSERT_DBG_FATAL ASSERT_FATAL
00290 
00291 #else /* !defined(Is_True_On) */
00292 
00293 #define ASSERT_WARN(a_truth, diag_args) \
00294    DIAG_ASSERT_NOLOC(a_truth, Diag_Warning, diag_args)
00295 #define ASSERT_FATAL(a_truth, diag_args) \
00296    DIAG_ASSERT_NOLOC(a_truth, Diag_Fatal, diag_args)
00297 # define ASSERT_DBG_WARN(a_truth, diag_args) ((void) 1)
00298 # define ASSERT_DBG_FATAL(a_truth, diag_args) ((void) 1)
00299 
00300 #endif /*Is_True_On*/
00301 
00302 
00303    /* ------- Hidden functions/macros (NEVER CALL THESE) -------*/
00304    /* ----------------------------------------------------------*/
00305 
00306 #define DIAG_USER_SRCPOS(a_truth, diag_handler, diag_args, wn) \
00307    ((a_truth) ? \
00308     (void) 1 :  \
00309     (Diag_Set_Srcpos(WN_Get_Linenum(wn)), \
00310      diag_handler  diag_args))
00311   
00312 #define DIAG_ASSERT_LOC(a_truth, diag_handler, diag_args) \
00313    ((a_truth) ? \
00314     (void) 1 :  \
00315     (Diag_Set_Location(__FILE__, __LINE__), diag_handler  diag_args))
00316 
00317 #define DIAG_ASSERT_LOC_SRCPOS(a_truth, diag_handler, diag_args, wn) \
00318    ((a_truth) ? \
00319     (void) 1 :  \
00320     (Diag_Set_Location(__FILE__, __LINE__), \
00321      Diag_Set_Srcpos(WN_Get_Linenum(wn)), \
00322      diag_handler  diag_args))
00323 
00324 #define DIAG_ASSERT_NOLOC(a_truth, diag_handler, diag_args) \
00325    ((a_truth) ? (void) 1 : diag_handler  diag_args)
00326 
00327 #define DIAG_ASSERT_NOLOC_SRCPOS(a_truth, diag_handler, diag_args, wn) \
00328    ((a_truth) ? \
00329     (void) 1 : \
00330     (Diag_Set_Srcpos(WN_Get_Linenum(wn)), \
00331      diag_handler  diag_args))
00332 
00333 extern void Diag_Set_Location(const char *file_name, INT line_number);
00334 extern void Diag_Set_Srcpos(SRCPOS srcpos);
00335 extern void Diag_User_Warning(DIAG_CODE code, ...);
00336 extern void Diag_User_Fatal(DIAG_CODE code, ...);
00337 extern void Diag_Warning(DIAG_CODE code, ...);
00338 extern void Diag_Fatal(DIAG_CODE code, ...);
00339 extern void Diag_Warning_Srcpos(DIAG_CODE code, ...);
00340 extern void Diag_Fatal_Srcpos(DIAG_CODE code, ...);
00341 
00342 
00343 #endif /* diagnostics_INCLUDED */
00344 
00345 
00346 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines