src/sysc/utils/sc_report.h

Go to the documentation of this file.
00001 #ifndef SC_REPORT_H
00002 #define SC_REPORT_H 1
00003 
00004 /*****************************************************************************
00005 
00006   The following code is derived, directly or indirectly, from the SystemC
00007   source code Copyright (c) 1996-2005 by all Contributors.
00008   All Rights reserved.
00009 
00010   The contents of this file are subject to the restrictions and limitations
00011   set forth in the SystemC Open Source License Version 2.4 (the "License");
00012   You may not use this file except in compliance with such restrictions and
00013   limitations. You may obtain instructions on how to receive a copy of the
00014   License at http://www.systemc.org/. Software distributed by Contributors
00015   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00016   ANY KIND, either express or implied. See the License for the specific
00017   language governing rights and limitations under the License.
00018 
00019  *****************************************************************************/
00020 
00021 /*****************************************************************************
00022 
00023   sc_report.h -- Run-time logging and reporting facilities
00024 
00025   Interface design by SystemC Verification Working Group.
00026   Implementation by Alex Riesen, Synopsys Inc.
00027   Original implementation by Martin Janssen, Synopsys Inc.
00028   Reference implementation by Cadence Design Systems, Inc., 2002-09-23:
00029   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00030   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey.
00031 
00032  *****************************************************************************/
00033 
00034 /*****************************************************************************
00035 
00036   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00037   changes you are making here.
00038 
00039       Name, Affiliation, Date: Alex Riesen, Synopsys Inc., Jan 28, 2003
00040   Description of Modification: Implementation for SytemC 2.1
00041 
00042  *****************************************************************************/
00043 
00044 #include <exception>
00045 #include <string>
00046 
00047 namespace sc_core {
00048 
00049 // ----------------------------------------------------------------------------
00050 //  ENUM : sc_severity
00051 //
00052 //  Enumeration of possible exception severity levels
00053 // ----------------------------------------------------------------------------
00054 
00055 enum sc_severity {
00056     SC_INFO = 0,        // informative only
00057     SC_WARNING, // indicates potentially incorrect condition
00058     SC_ERROR,   // indicates a definite problem
00059     SC_FATAL,   // indicates a problem from which we cannot recover
00060     SC_MAX_SEVERITY
00061 };
00062 
00063 typedef unsigned sc_actions;
00064 
00065 // ----------------------------------------------------------------------------
00066 //  ENUM : 
00067 //
00068 //  Enumeration of actions on an exception (implementation specific)
00069 // ----------------------------------------------------------------------------
00070 
00071 enum {
00072     SC_UNSPECIFIED  = 0x0000, // look for lower-priority rule
00073     SC_DO_NOTHING   = 0x0001, // take no action (ignore if other bits set)
00074     SC_THROW        = 0x0002, // throw an exception
00075     SC_LOG          = 0x0004, // add report to report log
00076     SC_DISPLAY      = 0x0008, // display report to screen
00077     SC_CACHE_REPORT = 0x0010, // save report to cache
00078     SC_INTERRUPT    = 0x0020, // call sc_interrupt_here(...)
00079     SC_STOP         = 0x0040, // call sc_stop()
00080     SC_ABORT        = 0x0080  // call abort()
00081 };
00082 
00083 class sc_object;
00084 class sc_time;
00085 struct sc_msg_def;
00086 class sc_report;
00087 const std::string sc_report_compose_message( const sc_report& );
00088 
00089 // ----------------------------------------------------------------------------
00090 //  CLASS : sc_report
00091 //
00092 //  Exception reporting
00093 // ----------------------------------------------------------------------------
00094 
00095 class sc_report : public std::exception
00096 {
00097 public:
00098 
00099     sc_report();
00100 
00101     sc_report(const sc_report&);
00102 
00103     sc_report & operator=(const sc_report&);
00104 
00105     virtual ~sc_report() throw();
00106 
00107     const char * get_msg_type() const;
00108 
00109     const char * get_msg() const
00110         { return msg; }
00111 
00112     sc_severity get_severity() const
00113         { return severity; }
00114 
00115     const char * get_file_name() const
00116         { return file; }
00117 
00118     int get_line_number() const
00119         { return line; }
00120 
00121     const sc_time & get_time() const
00122         { return *timestamp; }
00123 
00124     const char* get_process_name() const;
00125 
00126     bool valid () const
00127         {
00128             return process != 0;
00129         }
00130 
00131     virtual const char* what() const throw()
00132         { 
00133             return m_what;
00134         }
00135 
00136 protected:
00137 
00138     friend class sc_report_handler;
00139 
00140 
00141     sc_report(sc_severity,
00142               const sc_msg_def*,
00143               const char* msg,
00144               const char* file,
00145               int line);
00146 
00147 
00148 
00149     sc_severity        severity;
00150     const sc_msg_def*  md;
00151     char*              msg;
00152     char*              file;
00153     int                line;
00154     sc_time*           timestamp;
00155     sc_object*         process;
00156     char*              m_what;
00157 
00158 public:  // backward compatibility with 2.0+
00159 
00160     static const char* get_message(int id);
00161     static bool is_suppressed(int id);
00162     static void make_warnings_errors(bool);
00163     static void register_id(int id, const char* msg);
00164     static void suppress_id(int id, bool); // only for info or warning
00165     static void suppress_infos(bool);
00166     static void suppress_warnings(bool);
00167 
00168     int get_id() const;
00169 };
00170 typedef std::exception sc_exception;
00171 
00172 #define SC_DEFAULT_INFO_ACTIONS (SC_LOG | SC_DISPLAY)
00173 #define SC_DEFAULT_WARNING_ACTIONS (SC_LOG | SC_DISPLAY)
00174 #define SC_DEFAULT_ERROR_ACTIONS (SC_LOG | SC_CACHE_REPORT | SC_THROW)
00175 #define SC_DEFAULT_FATAL_ACTIONS \
00176 (SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT)
00177 
00178 
00179 // ----------------------------------------------------------------------------
00180 //  Report macros.
00181 //
00182 //  Use these macros to report an info, warning, error, or fatal.
00183 // ----------------------------------------------------------------------------
00184 
00185 #define SC_REPORT_INFO(id,msg) \
00186     sc_core::sc_report_handler::report( \
00187             sc_core::SC_INFO, id, msg, __FILE__, __LINE__ )
00188 
00189 #define SC_REPORT_WARNING(id,msg) \
00190     sc_core::sc_report_handler::report(\
00191             sc_core::SC_WARNING, id, msg, __FILE__, __LINE__)
00192 
00193 #define SC_REPORT_ERROR(id,msg) \
00194     sc_core::sc_report_handler::report( \
00195             sc_core::SC_ERROR, id, msg, __FILE__, __LINE__ )
00196 
00197 #define SC_REPORT_FATAL(id,msg) \
00198     sc_core::sc_report_handler::report( \
00199             sc_core::SC_FATAL, id, msg, __FILE__, __LINE__ )
00200 
00201 // ----------------------------------------------------------------------------
00202 //  MACRO : sc_assert(expr)
00203 //
00204 //  Like assert(), but additionally prints the current process name
00205 //  and simulation time, if the simulation is running.
00206 // ----------------------------------------------------------------------------
00207 
00208 #ifdef NDEBUG
00209 
00210 #define sc_assert(expr)                                                       \
00211  ((void) 0)
00212 
00213 #else
00214 
00215 #define sc_assert(expr)                                                       \
00216  ((void) ((expr) ? 0 : (SC_REPORT_FATAL( SC_ID_ASSERTION_FAILED_ , #expr ), 0)))
00217 
00218 #endif
00219 
00220 extern const char SC_ID_UNKNOWN_ERROR_[];
00221 extern const char SC_ID_WITHOUT_MESSAGE_[];
00222 extern const char SC_ID_NOT_IMPLEMENTED_[];
00223 extern const char SC_ID_INTERNAL_ERROR_[];
00224 extern const char SC_ID_ASSERTION_FAILED_[];
00225 extern const char SC_ID_OUT_OF_BOUNDS_[];
00226 
00227 // backward compatibility with 2.0+
00228 extern const char SC_ID_REGISTER_ID_FAILED_[];
00229 
00230 } // namespace sc_core
00231 
00232 #include "sysc/utils/sc_report_handler.h"
00233 
00234 #endif // SC_REPORT_H

Generated on Wed Apr 25 13:53:28 2007 for SystemC by  doxygen 1.5.1