sc_report.h revision 12027
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 sc_report.h -- Run-time logging and reporting facilities 23 24 Interface design by SystemC Verification Working Group. 25 Implementation by Alex Riesen, Synopsys Inc. 26 Original implementation by Martin Janssen, Synopsys Inc. 27 Reference implementation by Cadence Design Systems, Inc., 2002-09-23: 28 Norris Ip, Dean Shea, John Rose, Jasvinder Singh, William Paulsen, 29 John Pierce, Rachida Kebichi, Ted Elkind, David Bailey. 30 31 CHANGE LOG AT END OF FILE 32 *****************************************************************************/ 33 34#ifndef SC_REPORT_H 35#define SC_REPORT_H 1 36 37#include <exception> 38#include <string> 39 40namespace sc_core { 41 42// ---------------------------------------------------------------------------- 43// ENUM : sc_severity 44// 45// Enumeration of possible exception severity levels 46// ---------------------------------------------------------------------------- 47 48enum sc_severity { 49 SC_INFO = 0, // informative only 50 SC_WARNING, // indicates potentially incorrect condition 51 SC_ERROR, // indicates a definite problem 52 SC_FATAL, // indicates a problem from which we cannot recover 53 SC_MAX_SEVERITY 54}; 55 56typedef unsigned sc_actions; 57 58// ---------------------------------------------------------------------------- 59// ENUM : sc_verbosity 60// 61// Enumeration of message verbosity. 62// ---------------------------------------------------------------------------- 63 64 enum sc_verbosity { 65 SC_NONE = 0, 66 SC_LOW = 100, 67 SC_MEDIUM = 200, 68 SC_HIGH = 300, 69 SC_FULL = 400, 70 SC_DEBUG = 500 71 }; 72 73// ---------------------------------------------------------------------------- 74// ENUM : 75// 76// Enumeration of actions on an exception (implementation specific) 77// ---------------------------------------------------------------------------- 78 79enum { 80 SC_UNSPECIFIED = 0x0000, // look for lower-priority rule 81 SC_DO_NOTHING = 0x0001, // take no action (ignore if other bits set) 82 SC_THROW = 0x0002, // throw an exception 83 SC_LOG = 0x0004, // add report to report log 84 SC_DISPLAY = 0x0008, // display report to screen 85 SC_CACHE_REPORT = 0x0010, // save report to cache 86 SC_INTERRUPT = 0x0020, // call sc_interrupt_here(...) 87 SC_STOP = 0x0040, // call sc_stop() 88 SC_ABORT = 0x0080 // call abort() 89}; 90 91class sc_object; 92class sc_time; 93struct sc_msg_def; 94class sc_report; 95class sc_report_handler; 96const std::string sc_report_compose_message( const sc_report& ); 97 98// ---------------------------------------------------------------------------- 99// CLASS : sc_report 100// 101// Exception reporting 102// ---------------------------------------------------------------------------- 103 104class sc_report : public std::exception 105{ 106 friend class sc_report_handler; 107 friend sc_report* sc_handle_exception(); 108 109 sc_report(); // used internally by sc_handle_exception 110 111public: 112 113 sc_report(const sc_report&); 114 115 sc_report & operator=(const sc_report&); 116 117 virtual ~sc_report() throw(); 118 119 const char * get_msg_type() const; 120 121 const char * get_msg() const 122 { return msg; } 123 124 sc_severity get_severity() const 125 { return severity; } 126 127 const char * get_file_name() const 128 { return file; } 129 130 int get_line_number() const 131 { return line; } 132 133 const sc_time & get_time() const 134 { return *timestamp; } 135 136 const char* get_process_name() const; 137 138 int get_verbosity() const { return m_verbosity_level; } 139 140 bool valid () const 141 { 142 return process != 0; 143 } 144 145 virtual const char* what() const throw() 146 { 147 return m_what; 148 } 149 150 void swap( sc_report& ); 151 152protected: 153 154 sc_report(sc_severity, 155 const sc_msg_def*, 156 const char* msg, 157 const char* file, 158 int line, 159 int verbosity_level=SC_MEDIUM); 160 161 sc_severity severity; 162 const sc_msg_def* md; 163 char* msg; 164 char* file; 165 int line; 166 sc_time* timestamp; 167 sc_object* process; 168 int m_verbosity_level; 169 char* m_what; 170 171public: // backward compatibility with 2.0+ 172 173 static const char* get_message(int id); 174 static bool is_suppressed(int id); 175 static void make_warnings_errors(bool); 176 static void register_id(int id, const char* msg); 177 static void suppress_id(int id, bool); // only for info or warning 178 static void suppress_infos(bool); 179 static void suppress_warnings(bool); 180 181 int get_id() const; 182}; 183typedef std::exception sc_exception; 184 185#define SC_DEFAULT_INFO_ACTIONS \ 186 (::sc_core::SC_LOG | ::sc_core::SC_DISPLAY) 187#define SC_DEFAULT_WARNING_ACTIONS \ 188 (::sc_core::SC_LOG | ::sc_core::SC_DISPLAY) 189#define SC_DEFAULT_ERROR_ACTIONS \ 190 (::sc_core::SC_LOG | ::sc_core::SC_CACHE_REPORT | ::sc_core::SC_THROW) 191#define SC_DEFAULT_FATAL_ACTIONS \ 192 (::sc_core::SC_LOG | ::sc_core::SC_DISPLAY | \ 193 ::sc_core::SC_CACHE_REPORT | ::sc_core::SC_ABORT) 194 195 196// ---------------------------------------------------------------------------- 197// Report macros. 198// 199// Use these macros to report an info, warning, error, or fatal. 200// ---------------------------------------------------------------------------- 201 202#define SC_REPORT_INFO( msg_type, msg ) \ 203 ::sc_core::sc_report_handler::report( \ 204 ::sc_core::SC_INFO, msg_type, msg, __FILE__, __LINE__ ) 205 206#define SC_REPORT_INFO_VERB( msg_type, msg, verbosity ) \ 207 ::sc_core::sc_report_handler::report( \ 208 ::sc_core::SC_INFO, msg_type, msg, verbosity, \ 209 __FILE__ , __LINE__ ) 210 211#define SC_REPORT_WARNING( msg_type, msg ) \ 212 ::sc_core::sc_report_handler::report( \ 213 ::sc_core::SC_WARNING, msg_type, msg, __FILE__, __LINE__ ) 214 215#define SC_REPORT_ERROR( msg_type, msg ) \ 216 ::sc_core::sc_report_handler::report( \ 217 ::sc_core::SC_ERROR, msg_type, msg, __FILE__, __LINE__ ) 218 219#define SC_REPORT_FATAL( msg_type, msg ) \ 220 ::sc_core::sc_report_handler::report( \ 221 ::sc_core::SC_FATAL, msg_type, msg, __FILE__, __LINE__ ) 222 223// ---------------------------------------------------------------------------- 224// MACRO : sc_assert(expr) 225// 226// Like assert(), but additionally prints the current process name 227// and simulation time, if the simulation is running. 228// ---------------------------------------------------------------------------- 229 230#ifdef NDEBUG 231 232#define sc_assert(expr) \ 233 ((void) 0) 234 235#else 236 237#define sc_assert(expr) \ 238 ((void)((expr) ? 0 : \ 239 (SC_REPORT_FATAL( ::sc_core::SC_ID_ASSERTION_FAILED_, #expr ), 0))) 240 241#endif // NDEBUG 242 243extern const char SC_ID_UNKNOWN_ERROR_[]; 244extern const char SC_ID_WITHOUT_MESSAGE_[]; 245extern const char SC_ID_NOT_IMPLEMENTED_[]; 246extern const char SC_ID_INTERNAL_ERROR_[]; 247extern const char SC_ID_ASSERTION_FAILED_[]; 248extern const char SC_ID_OUT_OF_BOUNDS_[]; 249 250// backward compatibility with 2.0+ 251extern const char SC_ID_REGISTER_ID_FAILED_[]; 252 253} // namespace sc_core 254 255#include "sysc/utils/sc_report_handler.h" 256 257/***************************************************************************** 258 259 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 260 changes you are making here. 261 262 Name, Affiliation, Date: Alex Riesen, Synopsys Inc., Jan 28, 2003 263 Description of Modification: Implementation for SytemC 2.1 264 265 *****************************************************************************/ 266 267// $Log: sc_report.h,v $ 268// Revision 1.8 2011/08/26 20:46:19 acg 269// Andy Goodrich: moved the modification log to the end of the file to 270// eliminate source line number skew when check-ins are done. 271// 272// Revision 1.7 2011/05/05 17:46:04 acg 273// Philip A. Hartmann: changes in "swap" support. 274// 275// Revision 1.6 2011/04/19 02:39:44 acg 276// Andy Goodrich: set proper name for get_verbosity(). 277// 278// Revision 1.5 2011/03/23 16:16:48 acg 279// Andy Goodrich: finish message verbosity support. 280// 281// Revision 1.4 2011/02/18 20:38:44 acg 282// Andy Goodrich: Updated Copyright notice. 283// 284// Revision 1.3 2011/02/01 23:02:05 acg 285// Andy Goodrich: IEEE 1666 2011 changes. 286// 287// Revision 1.2 2008/05/20 20:42:50 acg 288// Andy Goodrich: added sc_core namespace prefix for ID value in sc_assert() 289// macro. 290// 291// Revision 1.1.1.1 2006/12/15 20:20:06 acg 292// SystemC 2.3 293// 294// Revision 1.3 2006/01/13 18:53:11 acg 295// Andy Goodrich: Added $Log command so that CVS comments are reproduced in 296// the source. 297// 298 299#endif // SC_REPORT_H 300