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-2006 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 // $Log: sc_report.h,v $
00045 // Revision 1.1.1.1  2006/12/15 20:31:39  acg
00046 // SystemC 2.2
00047 //
00048 // Revision 1.3  2006/01/13 18:53:11  acg
00049 // Andy Goodrich: Added $Log command so that CVS comments are reproduced in
00050 // the source.
00051 //
00052 
00053 #include <exception>
00054 #include <string>
00055 
00056 namespace sc_core {
00057 
00058 // ----------------------------------------------------------------------------
00059 //  ENUM : sc_severity
00060 //
00061 //  Enumeration of possible exception severity levels
00062 // ----------------------------------------------------------------------------
00063 
00064 enum sc_severity {
00065     SC_INFO = 0,        // informative only
00066     SC_WARNING, // indicates potentially incorrect condition
00067     SC_ERROR,   // indicates a definite problem
00068     SC_FATAL,   // indicates a problem from which we cannot recover
00069     SC_MAX_SEVERITY
00070 };
00071 
00072 typedef unsigned sc_actions;
00073 
00074 // ----------------------------------------------------------------------------
00075 //  ENUM : 
00076 //
00077 //  Enumeration of actions on an exception (implementation specific)
00078 // ----------------------------------------------------------------------------
00079 
00080 enum {
00081     SC_UNSPECIFIED  = 0x0000, // look for lower-priority rule
00082     SC_DO_NOTHING   = 0x0001, // take no action (ignore if other bits set)
00083     SC_THROW        = 0x0002, // throw an exception
00084     SC_LOG          = 0x0004, // add report to report log
00085     SC_DISPLAY      = 0x0008, // display report to screen
00086     SC_CACHE_REPORT = 0x0010, // save report to cache
00087     SC_INTERRUPT    = 0x0020, // call sc_interrupt_here(...)
00088     SC_STOP         = 0x0040, // call sc_stop()
00089     SC_ABORT        = 0x0080  // call abort()
00090 };
00091 
00092 class sc_object;
00093 class sc_time;
00094 struct sc_msg_def;
00095 class sc_report;
00096 const std::string sc_report_compose_message( const sc_report& );
00097 
00098 // ----------------------------------------------------------------------------
00099 //  CLASS : sc_report
00100 //
00101 //  Exception reporting
00102 // ----------------------------------------------------------------------------
00103 
00104 class sc_report : public std::exception
00105 {
00106 public:
00107 
00108     sc_report();
00109 
00110     sc_report(const sc_report&);
00111 
00112     sc_report & operator=(const sc_report&);
00113 
00114     virtual ~sc_report() throw();
00115 
00116     const char * get_msg_type() const;
00117 
00118     const char * get_msg() const
00119     { return msg; }
00120 
00121     sc_severity get_severity() const
00122     { return severity; }
00123 
00124     const char * get_file_name() const
00125     { return file; }
00126 
00127     int get_line_number() const
00128     { return line; }
00129 
00130     const sc_time & get_time() const
00131     { return *timestamp; }
00132 
00133     const char* get_process_name() const;
00134 
00135     bool valid () const
00136         {
00137         return process != 0;
00138     }
00139 
00140     virtual const char* what() const throw()
00141         { 
00142         return m_what;
00143     }
00144 
00145 protected:
00146 
00147     friend class sc_report_handler;
00148 
00149 
00150     sc_report(sc_severity,
00151           const sc_msg_def*,
00152           const char* msg,
00153           const char* file,
00154           int line);
00155 
00156 
00157 
00158     sc_severity        severity;
00159     const sc_msg_def*  md;
00160     char*              msg;
00161     char*              file;
00162     int                line;
00163     sc_time*           timestamp;
00164     sc_object*         process;
00165     char*              m_what;
00166 
00167 public:  // backward compatibility with 2.0+
00168 
00169     static const char* get_message(int id);
00170     static bool is_suppressed(int id);
00171     static void make_warnings_errors(bool);
00172     static void register_id(int id, const char* msg);
00173     static void suppress_id(int id, bool); // only for info or warning
00174     static void suppress_infos(bool);
00175     static void suppress_warnings(bool);
00176 
00177     int get_id() const;
00178 };
00179 typedef std::exception sc_exception;
00180 
00181 #define SC_DEFAULT_INFO_ACTIONS (SC_LOG | SC_DISPLAY)
00182 #define SC_DEFAULT_WARNING_ACTIONS (SC_LOG | SC_DISPLAY)
00183 #define SC_DEFAULT_ERROR_ACTIONS (SC_LOG | SC_CACHE_REPORT | SC_THROW)
00184 #define SC_DEFAULT_FATAL_ACTIONS \
00185 (SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT)
00186 
00187 
00188 // ----------------------------------------------------------------------------
00189 //  Report macros.
00190 //
00191 //  Use these macros to report an info, warning, error, or fatal.
00192 // ----------------------------------------------------------------------------
00193 
00194 #define SC_REPORT_INFO(id,msg) \
00195     sc_core::sc_report_handler::report( \
00196         sc_core::SC_INFO, id, msg, __FILE__, __LINE__ )
00197 
00198 #define SC_REPORT_WARNING(id,msg) \
00199     sc_core::sc_report_handler::report(\
00200         sc_core::SC_WARNING, id, msg, __FILE__, __LINE__)
00201 
00202 #define SC_REPORT_ERROR(id,msg) \
00203     sc_core::sc_report_handler::report( \
00204         sc_core::SC_ERROR, id, msg, __FILE__, __LINE__ )
00205 
00206 #define SC_REPORT_FATAL(id,msg) \
00207     sc_core::sc_report_handler::report( \
00208         sc_core::SC_FATAL, id, msg, __FILE__, __LINE__ )
00209 
00210 // ----------------------------------------------------------------------------
00211 //  MACRO : sc_assert(expr)
00212 //
00213 //  Like assert(), but additionally prints the current process name
00214 //  and simulation time, if the simulation is running.
00215 // ----------------------------------------------------------------------------
00216 
00217 #ifdef NDEBUG
00218 
00219 #define sc_assert(expr)                                                       \
00220  ((void) 0)
00221 
00222 #else
00223 
00224 #define sc_assert(expr)                                                       \
00225  ((void) ((expr) ? 0 : (SC_REPORT_FATAL( SC_ID_ASSERTION_FAILED_ , #expr ), 0)))
00226 
00227 #endif
00228 
00229 extern const char SC_ID_UNKNOWN_ERROR_[];
00230 extern const char SC_ID_WITHOUT_MESSAGE_[];
00231 extern const char SC_ID_NOT_IMPLEMENTED_[];
00232 extern const char SC_ID_INTERNAL_ERROR_[];
00233 extern const char SC_ID_ASSERTION_FAILED_[];
00234 extern const char SC_ID_OUT_OF_BOUNDS_[];
00235 
00236 // backward compatibility with 2.0+
00237 extern const char SC_ID_REGISTER_ID_FAILED_[];
00238 
00239 } // namespace sc_core
00240 
00241 #include "sysc/utils/sc_report_handler.h"
00242 
00243 #endif // SC_REPORT_H

Generated on Wed Jan 21 15:32:10 2009 for SystemC by  doxygen 1.5.5