Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

scv_report.h

Go to the documentation of this file.
00001 //  -*- C++ -*- <this line is for emacs to recognize it as C++ code>
00002 /*****************************************************************************
00003 
00004   The following code is derived, directly or indirectly, from the SystemC
00005   source code Copyright (c) 1996-2002 by all Contributors.
00006   All Rights reserved.
00007 
00008   The contents of this file are subject to the restrictions and limitations
00009   set forth in the SystemC Open Source License Version 2.3 (the "License");
00010   You may not use this file except in compliance with such restrictions and
00011   limitations. You may obtain instructions on how to receive a copy of the
00012   License at http://www.systemc.org/. Software distributed by Contributors
00013   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00014   ANY KIND, either express or implied. See the License for the specific
00015   language governing rights and limitations under the License.
00016 
00017  *****************************************************************************/
00018 
00019 /*****************************************************************************
00020 
00021   scv_report.h --  The public interface for error messages.
00022 
00023   Original Authors (Cadence Design Systems, Inc):
00024   Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen,
00025   John Pierce, Rachida Kebichi, Ted Elkind, David Bailey
00026   2002-09-23
00027 
00028  *****************************************************************************/
00029 
00030 /*****************************************************************************
00031 
00032   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00033   changes you are making here.
00034 
00035       Name, Affiliation, Date:
00036   Description of Modification:
00037 
00038  *****************************************************************************/
00039 
00040 #ifndef _SCV_REPORT_H
00041 #define _SCV_REPORT_H
00042 
00043 #include "scv/scv_config.h"
00044 
00045 
00046 #ifdef _SCV_USE_SC_REPORT
00047 
00048 typedef sc_actions scv_actions;
00049 typedef sc_report scv_report;
00050 typedef sc_report_handler scv_report_handler;
00051 typedef sc_severity scv_severity;
00052 typedef const char *scv_msg_type;
00053 
00054 #define SCV_INFO SC_INFO
00055 #define SCV_WARNING SC_WARNING
00056 #define SCV_ERROR SC_ERROR
00057 #define SCV_FATAL SC_FATAL
00058 
00059 #define SCV_UNSPECIFIED SC_UNSPECIFIED
00060 #define SCV_DO_NOTHING SC_DO_NOTHING
00061 #define SCV_THROW SC_THROW
00062 #define SCV_LOG SC_LOG
00063 #define SCV_DISPLAY SC_DISPLAY
00064 #define SCV_CACHE_REPORT SC_CACHE_REPORT
00065 #define SCV_INTERRUPT SC_INTERRUPT
00066 #define SCV_STOP SC_STOP
00067 #define SCV_ABORT SC_ABORT
00068 
00069 #define SCV_DEFAULT_INFO_ACTIONS SC_DEFAULT_INFO_ACTIONS
00070 #define SCV_DEFAULT_WARNING_ACTIONS SC_DEFAULT_WARNING_ACTIONS
00071 #define SCV_DEFAULT_ERROR_ACTIONS SC_DEFAULT_ERROR_ACTIONS
00072 #define SCV_DEFAULT_FATAL_ACTIONS SC_DEFAULT_FATAL_ACTIONS
00073 
00074 #define SCV_REPORT_INFO SC_REPORT_INFO
00075 #define SCV_REPORT_WARNING SC_REPORT_WARNING
00076 #define SCV_REPORT_ERROR SC_REPORT_ERROR
00077 #define SCV_REPORT_FATAL SC_REPORT_FATAL
00078 
00079 #else
00080 
00081 
00082 #include <string>
00083 
00084 #include "scv/scv_object_if.h"
00085 #include "scv/scv_util.h"
00086 #include "scv/scv_debug.h"
00087 
00088 #ifdef set_handler
00089 # undef set_handler
00090 #endif
00091 
00092 #ifdef _MSC_VER
00093 #ifdef DELETE
00094 #undef DELETE
00095 #endif
00096 #ifdef ERROR
00097 #undef ERROR
00098 #endif
00099 #endif
00100 
00101 
00102 //
00103 // scv_report
00104 //
00105 
00106 
00107 #define SCV_REPORT_INFO(msg_type,msg) \
00108    scv_report_handler::report(SCV_INFO,(msg_type),(msg),__FILE__,__LINE__)
00109 
00110 #define SCV_REPORT_WARNING(msg_type,msg) \
00111    scv_report_handler::report(SCV_WARNING,(msg_type),(msg),__FILE__,__LINE__)
00112 
00113 #define SCV_REPORT_ERROR(msg_type,msg) \
00114    scv_report_handler::report(SCV_ERROR,(msg_type),(msg),__FILE__,__LINE__)
00115 
00116 #define SCV_REPORT_FATAL(msg_type,msg) \
00117    scv_report_handler::report(SCV_FATAL,(msg_type),(msg),__FILE__,__LINE__)
00118 
00119 
00120 enum scv_severity {
00121    SCV_INFO = 0,        // informative only
00122    SCV_WARNING, // indicates potentially incorrect condition
00123    SCV_ERROR,   // indicates a definite problem
00124    SCV_FATAL    // indicates a problem from which we cannot recover
00125 };
00126 
00127 
00128 typedef unsigned scv_actions;
00129 
00130 const scv_actions SCV_UNSPECIFIED  = 0x0000; // look for lower-priority rule
00131 const scv_actions SCV_DO_NOTHING   = 0x0001; // take no action (ignore if other bits set)
00132 const scv_actions SCV_THROW        = 0x0002; // throw an exception
00133 const scv_actions SCV_LOG          = 0x0004; // add report to report log
00134 const scv_actions SCV_DISPLAY      = 0x0008; // display report to screen
00135 const scv_actions SCV_CACHE_REPORT = 0x0010; // save report to cache
00136 const scv_actions SCV_INTERRUPT    = 0x0020; // interrupt simulation
00137 const scv_actions SCV_STOP         = 0x0040; // call sc_stop()
00138 const scv_actions SCV_ABORT        = 0x0080; // call abort(0)
00139 
00140 
00141 typedef const char *scv_msg_type;
00142 
00143 
00144 class scv_report : public scv_object_if {
00145 public:
00146 
00147    scv_report(
00148      scv_severity severity, scv_msg_type msg_type,
00149      const char *msg,
00150      const char *file_name, int line_number,
00151      sc_time time, const char *_process_name
00152    );
00153 
00154    scv_report(const scv_report&);
00155 
00156    virtual ~scv_report() {}
00157 
00158    scv_report& operator=(const scv_report&);
00159 
00160    // for use with sc_exception
00161    operator const char *() const;
00162 
00163    scv_severity get_severity() const
00164      { return _severity; }
00165    scv_msg_type get_msg_type() const
00166      { return _msg_type.c_str(); }
00167    const char *get_msg() const
00168      { return _msg.c_str(); }
00169    const char *get_file_name() const
00170      { return _file_name.c_str(); }
00171    int get_line_number() const
00172      { return _line_number; }
00173 
00174    sc_time get_time() const
00175      { return _time; }
00176    const char *get_process_name() const
00177      { return _process_name.c_str(); }
00178 
00179    const char *get_name() const
00180      { return _msg_type.c_str(); }
00181    const char *kind() const
00182      { return _kind; }
00183    void print(ostream& o=cout, int details=0, int indent=0) const;
00184 
00185 private:
00186 
00187    scv_severity _severity;
00188    string _msg_type;
00189    string _msg;
00190    string _file_name;
00191    int _line_number;
00192    sc_time _time;
00193    string _process_name;
00194 
00195    static const char *_kind;
00196 };
00197 
00198 
00199 class scv_report_handler {
00200 public:
00201 
00202    scv_report_handler() {}
00203    virtual ~scv_report_handler() {}
00204 
00205    //
00206    // configure reporting facility
00207    //
00208 
00209    // specify handler for reports
00210    // 0 restores default 
00211    static void set_handler(
00212      void (*handler)(const scv_report&, const scv_actions&) = 0
00213    );
00214 
00215    // specify actions to take for messages
00216    // SCV_UNSPECIFIED restores default
00217    static scv_actions set_actions(
00218      scv_severity severity,
00219      scv_actions actions = SCV_UNSPECIFIED
00220    );
00221    static scv_actions set_actions(
00222      scv_msg_type msg_type,
00223      scv_actions actions = SCV_UNSPECIFIED
00224    );
00225    static scv_actions set_actions(
00226      scv_msg_type msg_type, scv_severity severity,
00227      scv_actions actions = SCV_UNSPECIFIED
00228    );
00229 
00230    // specify how many occurrences to tolerate
00231    // -1 restores default
00232    static int stop_after(
00233      scv_severity severity,
00234      int limit = -1
00235    );
00236    static int stop_after(
00237      scv_msg_type msg_type,
00238      int limit = -1
00239    );
00240    static int stop_after(
00241      scv_msg_type msg_type, scv_severity severity,
00242      int limit = -1
00243    );
00244 
00245    // override configured actions
00246    static scv_actions suppress(scv_actions actions = 0U);
00247    static scv_actions force(scv_actions actions = 0U);
00248 
00249    // add callback
00250    static void register_cb(void (*f)(const scv_report *));
00251 
00252    // get unused action (returns SCV_UNSPECIFIED if none available)
00253    static scv_actions get_new_action_id();
00254 
00255    // control log file name
00256    static const char *get_log_file_name();
00257    static void set_log_file_name(const char *name);
00258 
00259    // control debug output for scv_report
00260    static int get_debug() { return _debug; }
00261    static void set_debug(int debug) { _debug = debug; }
00262 
00263    //
00264    // use reporting facility
00265    //
00266 
00267    // user can intercept with set_handler
00268    static void report(
00269      scv_severity severity, scv_msg_type msg_type,
00270      const char *msg,
00271      const char *file_name, int line_number
00272    );
00273 
00274    // always calls default handler
00275    static void default_handler(const scv_report&, const scv_actions&);
00276 
00277    static const scv_report *get_cached_report();
00278    static void clear_cached_report();
00279 
00280 private:
00281 
00282    // set default configuration
00283    static void initialize();
00284 
00285    static int _debug;
00286 };
00287 
00288 
00289 const scv_actions SCV_DEFAULT_INFO_ACTIONS
00290        = SCV_LOG | SCV_DISPLAY;
00291 const scv_actions SCV_DEFAULT_WARNING_ACTIONS
00292        = SCV_LOG | SCV_DISPLAY;
00293 const scv_actions SCV_DEFAULT_ERROR_ACTIONS
00294        = SCV_LOG | SCV_DISPLAY | SCV_CACHE_REPORT | SCV_THROW;
00295 const scv_actions SCV_DEFAULT_FATAL_ACTIONS
00296        = SCV_LOG | SCV_DISPLAY | SCV_CACHE_REPORT | SCV_THROW;
00297 
00298 
00299 #endif // ! _SCV_USE_SC_REPORT
00300 
00301 
00302 //
00303 // Translation layer for _scv_message messages
00304 //
00305 
00306 
00307 class _scv_message_desc {
00308 public:
00309   _scv_message_desc(
00310     string tag, string format, scv_severity severity, scv_actions actions
00311   ) : _tag(tag), _format(format), _severity(severity), _actions(actions) {}
00312   const char *get_tag() const { return _tag.c_str(); }
00313   const char *get_format() const { return _format.c_str(); }
00314   scv_severity get_severity() const { return _severity; }
00315   unsigned get_actions() const { return _actions; }
00316 private:
00317   string _tag;
00318   string _format;
00319   scv_severity _severity;
00320   scv_actions _actions;
00321 };
00322 
00323 
00324 class _scv_message {
00325 friend class scv_report_core;
00326 public:
00327 
00328   enum severity_level { INFO, WARNING, ERROR, FATAL };
00329 
00330   enum response_level {
00331     NONE_SPECIFIED, ENABLE_MESSAGE, SUPPRESS_MESSAGE
00332   };
00333 
00334 // Message types are actually pointers to descriptors
00335 #define _SCV_DEFERR(code, number, string, severity, actions) \
00336   static _scv_message_desc *code##_base; \
00337   static _scv_message_desc **code;
00338 #include "scv/scv_messages.h"
00339 #undef _SCV_DEFERR
00340 
00341   // Used internally by the SystemC Verification Standard to report exceptions
00342   static void message(_scv_message_desc **desc_pp, ... );
00343   static scv_severity xlat_severity(severity_level severity);
00344 
00345 private:
00346   static void setup();
00347 };
00348 
00349 
00350 #endif // ! _SCV_REPORT_H 

Generated on Fri Jan 14 08:29:11 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18