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 #include "sysc/kernel/sc_cmnhdr.h" 40 41 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN) 42 # pragma warning(push) 43 # pragma warning(disable:4275) // ignore missing std::exception DLL export 44 #endif 45 46 namespace sc_core { 47 48 // ---------------------------------------------------------------------------- 49 // ENUM : sc_severity 50 // 51 // Enumeration of possible exception severity levels 52 // ---------------------------------------------------------------------------- 53 54 enum sc_severity { 55 SC_INFO = 0, // informative only 56 SC_WARNING, // indicates potentially incorrect condition 57 SC_ERROR, // indicates a definite problem 58 SC_FATAL, // indicates a problem from which we cannot recover 59 SC_MAX_SEVERITY 60 }; 61 62 // ---------------------------------------------------------------------------- 63 // ENUM : sc_verbosity 64 // 65 // Enumeration of message verbosity. 66 // ---------------------------------------------------------------------------- 67 68 enum sc_verbosity { 69 SC_NONE = 0, 70 SC_LOW = 100, 71 SC_MEDIUM = 200, 72 SC_HIGH = 300, 73 SC_FULL = 400, 74 SC_DEBUG = 500 75 }; 76 77 // ---------------------------------------------------------------------------- 78 // ENUM : 79 // 80 // Enumeration of actions on an exception (implementation specific) 81 // ---------------------------------------------------------------------------- 82 83 typedef unsigned sc_actions; 84 85 enum { 86 SC_UNSPECIFIED = 0x0000, // look for lower-priority rule 87 SC_DO_NOTHING = 0x0001, // take no action (ignore if other bits set) 88 SC_THROW = 0x0002, // throw an exception 89 SC_LOG = 0x0004, // add report to report log 90 SC_DISPLAY = 0x0008, // display report to screen 91 SC_CACHE_REPORT = 0x0010, // save report to cache 92 SC_INTERRUPT = 0x0020, // call sc_interrupt_here(...) 93 SC_STOP = 0x0040, // call sc_stop() 94 SC_ABORT = 0x0080, // call abort() 95 96 // default action constants 97 SC_DEFAULT_INFO_ACTIONS = SC_LOG | SC_DISPLAY, 98 SC_DEFAULT_WARNING_ACTIONS = SC_LOG | SC_DISPLAY, 99 SC_DEFAULT_ERROR_ACTIONS = SC_LOG | SC_CACHE_REPORT | SC_THROW, 100 SC_DEFAULT_FATAL_ACTIONS = SC_LOG | SC_DISPLAY | SC_CACHE_REPORT | SC_ABORT, 101 SC_DEFAULT_CATCH_ACTIONS = SC_DISPLAY 102 }; 103 104 class sc_object; 105 class sc_time; 106 struct sc_msg_def; 107 class sc_report; 108 class sc_report_handler; 109 SC_API const std::string sc_report_compose_message( const sc_report& ); 110 111 // ---------------------------------------------------------------------------- 112 // CLASS : sc_report 113 // 114 // Exception reporting 115 // ---------------------------------------------------------------------------- 116 117 class SC_API sc_report : public std::exception 118 { 119 friend class sc_report_handler; 120 friend SC_API sc_report* sc_handle_exception(); 121 122 sc_report(); // used internally by sc_handle_exception 123 124 public: 125 126 sc_report(const sc_report&); 127 128 sc_report & operator=(const sc_report&); 129 130 virtual ~sc_report() SC_NOEXCEPT_; 131 132 const char * get_msg_type() const; 133 get_msg()134 const char * get_msg() const 135 { return msg; } 136 get_severity()137 sc_severity get_severity() const 138 { return severity; } 139 get_file_name()140 const char * get_file_name() const 141 { return file; } 142 get_line_number()143 int get_line_number() const 144 { return line; } 145 get_time()146 const sc_time & get_time() const 147 { return *timestamp; } 148 149 const char* get_process_name() const; 150 get_verbosity()151 int get_verbosity() const { return m_verbosity_level; } 152 153 bool valid () const; 154 what()155 virtual const char* what() const SC_NOEXCEPT_ 156 { 157 return m_what; 158 } 159 160 void swap( sc_report& ); 161 162 protected: 163 164 sc_report(sc_severity, 165 const sc_msg_def*, 166 const char* msg, 167 const char* file, 168 int line, 169 int verbosity_level=SC_MEDIUM); 170 171 sc_severity severity; 172 const sc_msg_def* md; 173 char* msg; 174 char* file; 175 int line; 176 sc_time* timestamp; 177 char* process_name; 178 int m_verbosity_level; 179 char* m_what; 180 181 public: // backward compatibility with 2.0+ 182 183 static const char* get_message(int id); 184 static bool is_suppressed(int id); 185 static void make_warnings_errors(bool); 186 static void register_id(int id, const char* msg); 187 static void suppress_id(int id, bool); // only for info or warning 188 static void suppress_infos(bool); 189 static void suppress_warnings(bool); 190 191 int get_id() const; 192 }; 193 194 typedef std::exception sc_exception; 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 // SC_NORETURN_ macro, indicating that a function does not return 225 #if SC_CPLUSPLUS >= 201103L && (!defined(_MSC_VER) || _MSC_VER >= 1900) 226 // C++11: use standard C++ attribute 227 # define SC_NORETURN_ [[noreturn]] 228 #else 229 # if defined(_MSC_VER) 230 # define SC_NORETURN_ __declspec(noreturn) 231 # elif defined(__GNUC__) || defined(__MINGW32__) || defined(__clang__) 232 # define SC_NORETURN_ __attribute__((noreturn)) 233 # else 234 # define SC_NORETURN_ /* nothing */ 235 # endif 236 #endif // SC_NORETURN_ 237 238 // ---------------------------------------------------------------------------- 239 // FUNCTION : sc_abort() 240 // 241 // Like abort(), never returns and aborts the current program immediately, 242 // but may print additional information. 243 // ---------------------------------------------------------------------------- 244 245 SC_NORETURN_ SC_API void sc_abort(); 246 247 // ---------------------------------------------------------------------------- 248 // MACRO : sc_assert(expr) 249 // 250 // Like assert(), but additionally prints the current process name 251 // and simulation time, if the simulation is running. 252 // ---------------------------------------------------------------------------- 253 254 #if defined(NDEBUG) && !defined(SC_ENABLE_ASSERTIONS) // disable assertions 255 256 #define sc_assert(expr) \ 257 ((void) 0) 258 259 #else // enable assertions 260 261 #define sc_assert(expr) \ 262 ((void)((expr) ? 0 : \ 263 (::sc_core::sc_assertion_failed(#expr,__FILE__,__LINE__),0))) 264 265 #endif // defined(NDEBUG) && !defined(SC_ENABLE_ASSERTIONS) 266 267 SC_NORETURN_ SC_API void 268 sc_assertion_failed(const char* msg, const char* file, int line); 269 270 extern SC_API const char SC_ID_UNKNOWN_ERROR_[]; 271 extern SC_API const char SC_ID_WITHOUT_MESSAGE_[]; 272 extern SC_API const char SC_ID_NOT_IMPLEMENTED_[]; 273 extern SC_API const char SC_ID_INTERNAL_ERROR_[]; 274 extern SC_API const char SC_ID_ASSERTION_FAILED_[]; 275 extern SC_API const char SC_ID_OUT_OF_BOUNDS_[]; 276 extern SC_API const char SC_ID_ABORT_[]; 277 278 // backward compatibility with 2.0+ 279 extern SC_API const char SC_ID_REGISTER_ID_FAILED_[]; 280 281 } // namespace sc_core 282 283 #undef SC_NORETURN_ 284 285 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN) 286 # pragma warning(pop) 287 #endif 288 289 #include "sysc/utils/sc_report_handler.h" 290 291 /***************************************************************************** 292 293 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 294 changes you are making here. 295 296 Name, Affiliation, Date: Alex Riesen, Synopsys Inc., Jan 28, 2003 297 Description of Modification: Implementation for SytemC 2.1 298 299 *****************************************************************************/ 300 301 // $Log: sc_report.h,v $ 302 // Revision 1.8 2011/08/26 20:46:19 acg 303 // Andy Goodrich: moved the modification log to the end of the file to 304 // eliminate source line number skew when check-ins are done. 305 // 306 // Revision 1.7 2011/05/05 17:46:04 acg 307 // Philip A. Hartmann: changes in "swap" support. 308 // 309 // Revision 1.6 2011/04/19 02:39:44 acg 310 // Andy Goodrich: set proper name for get_verbosity(). 311 // 312 // Revision 1.5 2011/03/23 16:16:48 acg 313 // Andy Goodrich: finish message verbosity support. 314 // 315 // Revision 1.4 2011/02/18 20:38:44 acg 316 // Andy Goodrich: Updated Copyright notice. 317 // 318 // Revision 1.3 2011/02/01 23:02:05 acg 319 // Andy Goodrich: IEEE 1666 2011 changes. 320 // 321 // Revision 1.2 2008/05/20 20:42:50 acg 322 // Andy Goodrich: added sc_core namespace prefix for ID value in sc_assert() 323 // macro. 324 // 325 // Revision 1.1.1.1 2006/12/15 20:20:06 acg 326 // SystemC 2.3 327 // 328 // Revision 1.3 2006/01/13 18:53:11 acg 329 // Andy Goodrich: Added $Log command so that CVS comments are reproduced in 330 // the source. 331 // 332 333 #endif // SC_REPORT_H 334