SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_report.h
Go to the documentation of this file.
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>
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
46namespace sc_core {
47
48// ----------------------------------------------------------------------------
49// ENUM : sc_severity
50//
51// Enumeration of possible exception severity levels
52// ----------------------------------------------------------------------------
53
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
60};
61
62// ----------------------------------------------------------------------------
63// ENUM : sc_verbosity
64//
65// Enumeration of message verbosity.
66// ----------------------------------------------------------------------------
67
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
83typedef unsigned sc_actions;
84
85enum {
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
103
104class sc_object;
105class sc_time;
106struct sc_msg_def;
107class sc_report;
108class sc_report_handler;
109SC_API const std::string sc_report_compose_message( const sc_report& );
110
111// ----------------------------------------------------------------------------
112// CLASS : sc_report
113//
114// Exception reporting
115// ----------------------------------------------------------------------------
116
117class SC_API sc_report : public std::exception
118{
119 friend class sc_report_handler;
121
122 sc_report(); // used internally by sc_handle_exception
123
124public:
125
127
129
130 virtual ~sc_report() noexcept;
131
132 const char * get_msg_type() const;
133
134 const char * get_msg() const
135 { return msg; }
136
138 { return severity; }
139
140 const char * get_file_name() const
141 { return file; }
142
143 int get_line_number() const
144 { return line; }
145
146 const sc_time & get_time() const
147 { return *timestamp; }
148
149 const char* get_process_name() const;
150
151 int get_verbosity() const { return m_verbosity_level; }
152
153 bool valid () const;
154
155 virtual const char* what() const noexcept
156 {
157 return m_what;
158 }
159
160 void swap( sc_report& );
161
162protected:
163
165 const sc_msg_def*,
166 const char* msg,
167 const char* file,
168 int line,
169 int verbosity_level=SC_MEDIUM);
170
173 char* msg;
174 char* file;
175 int line;
179 char* m_what;
180
181public: // 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
194typedef 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_REPORT_INFO_VERB( msg_type, msg, ::sc_core::SC_MEDIUM )
204
205#define SC_REPORT_INFO_VERB( msg_type, msg, verbosity ) \
206 do { \
207 if( verbosity <= ::sc_core::sc_report_handler::get_verbosity_level() ) \
208 ::sc_core::sc_report_handler::report( \
209 ::sc_core::SC_INFO, msg_type, msg, verbosity, __FILE__ , __LINE__ \
210 ); \
211 } while(false)
212
213#define SC_REPORT_WARNING( msg_type, msg ) \
214 ::sc_core::sc_report_handler::report( \
215 ::sc_core::SC_WARNING, msg_type, msg, __FILE__, __LINE__ )
216
217#define SC_REPORT_ERROR( msg_type, msg ) \
218 ::sc_core::sc_report_handler::report( \
219 ::sc_core::SC_ERROR, msg_type, msg, __FILE__, __LINE__ )
220
221#define SC_REPORT_FATAL( msg_type, msg ) \
222 ::sc_core::sc_report_handler::report( \
223 ::sc_core::SC_FATAL, msg_type, msg, __FILE__, __LINE__ )
224
225// ----------------------------------------------------------------------------
226// FUNCTION : sc_abort()
227//
228// Like abort(), never returns and aborts the current program immediately,
229// but may print additional information.
230// ----------------------------------------------------------------------------
231
232[[noreturn]] SC_API void sc_abort();
233
234// ----------------------------------------------------------------------------
235// MACRO : sc_assert(expr)
236//
237// Like assert(), but additionally prints the current process name
238// and simulation time, if the simulation is running.
239// ----------------------------------------------------------------------------
240
241#if defined(NDEBUG) && !defined(SC_ENABLE_ASSERTIONS) // disable assertions
242
243#define sc_assert(expr) \
244 ((void) 0)
245
246#else // enable assertions
247
248#define sc_assert(expr) \
249 ((void)((expr) ? 0 : \
250 (::sc_core::sc_assertion_failed(#expr,__FILE__,__LINE__),0)))
251
252#endif // defined(NDEBUG) && !defined(SC_ENABLE_ASSERTIONS)
253
254[[noreturn]] SC_API void
255sc_assertion_failed(const char* msg, const char* file, int line);
256
257extern SC_API const char SC_ID_UNKNOWN_ERROR_[];
258extern SC_API const char SC_ID_WITHOUT_MESSAGE_[];
259extern SC_API const char SC_ID_NOT_IMPLEMENTED_[];
260extern SC_API const char SC_ID_INTERNAL_ERROR_[];
261extern SC_API const char SC_ID_ASSERTION_FAILED_[];
262extern SC_API const char SC_ID_OUT_OF_BOUNDS_[];
263extern SC_API const char SC_ID_ABORT_[];
264
265// backward compatibility with 2.0+
266extern SC_API const char SC_ID_REGISTER_ID_FAILED_[];
267
268} // namespace sc_core
269
270#if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
271# pragma warning(pop)
272#endif
273
275
276/*****************************************************************************
277
278 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
279 changes you are making here.
280
281 Name, Affiliation, Date: Alex Riesen, Synopsys Inc., Jan 28, 2003
282 Description of Modification: Implementation for SytemC 2.1
283
284 *****************************************************************************/
285
286// $Log: sc_report.h,v $
287// Revision 1.8 2011/08/26 20:46:19 acg
288// Andy Goodrich: moved the modification log to the end of the file to
289// eliminate source line number skew when check-ins are done.
290//
291// Revision 1.7 2011/05/05 17:46:04 acg
292// Philip A. Hartmann: changes in "swap" support.
293//
294// Revision 1.6 2011/04/19 02:39:44 acg
295// Andy Goodrich: set proper name for get_verbosity().
296//
297// Revision 1.5 2011/03/23 16:16:48 acg
298// Andy Goodrich: finish message verbosity support.
299//
300// Revision 1.4 2011/02/18 20:38:44 acg
301// Andy Goodrich: Updated Copyright notice.
302//
303// Revision 1.3 2011/02/01 23:02:05 acg
304// Andy Goodrich: IEEE 1666 2011 changes.
305//
306// Revision 1.2 2008/05/20 20:42:50 acg
307// Andy Goodrich: added sc_core namespace prefix for ID value in sc_assert()
308// macro.
309//
310// Revision 1.1.1.1 2006/12/15 20:20:06 acg
311// SystemC 2.3
312//
313// Revision 1.3 2006/01/13 18:53:11 acg
314// Andy Goodrich: Added $Log command so that CVS comments are reproduced in
315// the source.
316//
317
318#endif // SC_REPORT_H
#define SC_API
Definition: sc_cmnhdr.h:148
SC_API const char SC_ID_ABORT_[]
SC_API const char SC_ID_OUT_OF_BOUNDS_[]
SC_API const std::string sc_report_compose_message(const sc_report &)
SC_API const char SC_ID_INTERNAL_ERROR_[]
SC_API void sc_abort()
sc_verbosity
Definition: sc_report.h:68
@ SC_MEDIUM
Definition: sc_report.h:71
@ SC_NONE
Definition: sc_report.h:69
@ SC_HIGH
Definition: sc_report.h:72
@ SC_LOW
Definition: sc_report.h:70
@ SC_DEBUG
Definition: sc_report.h:74
@ SC_FULL
Definition: sc_report.h:73
@ SC_UNSPECIFIED
Definition: sc_report.h:86
@ SC_LOG
Definition: sc_report.h:89
@ SC_DEFAULT_CATCH_ACTIONS
Definition: sc_report.h:101
@ SC_ABORT
Definition: sc_report.h:94
@ SC_STOP
Definition: sc_report.h:93
@ SC_THROW
Definition: sc_report.h:88
@ SC_DO_NOTHING
Definition: sc_report.h:87
@ SC_CACHE_REPORT
Definition: sc_report.h:91
@ SC_INTERRUPT
Definition: sc_report.h:92
@ SC_DEFAULT_ERROR_ACTIONS
Definition: sc_report.h:99
@ SC_DEFAULT_INFO_ACTIONS
Definition: sc_report.h:97
@ SC_DEFAULT_WARNING_ACTIONS
Definition: sc_report.h:98
@ SC_DEFAULT_FATAL_ACTIONS
Definition: sc_report.h:100
@ SC_DISPLAY
Definition: sc_report.h:90
unsigned sc_actions
Definition: sc_report.h:83
std::exception sc_exception
Definition: sc_report.h:194
class SC_API sc_object
Definition: sc_object.h:46
sc_severity
Definition: sc_report.h:54
@ SC_MAX_SEVERITY
Definition: sc_report.h:59
@ SC_ERROR
Definition: sc_report.h:57
@ SC_FATAL
Definition: sc_report.h:58
@ SC_INFO
Definition: sc_report.h:55
@ SC_WARNING
Definition: sc_report.h:56
SC_API const char SC_ID_REGISTER_ID_FAILED_[]
Definition: sc_bit_ids.h:72
SC_API const char SC_ID_ASSERTION_FAILED_[]
SC_API const char SC_ID_WITHOUT_MESSAGE_[]
SC_API void sc_assertion_failed(const char *msg, const char *file, int line)
SC_API const char SC_ID_NOT_IMPLEMENTED_[]
SC_API const char SC_ID_UNKNOWN_ERROR_[]
static void suppress_warnings(bool)
static void suppress_id(int id, bool)
static void make_warnings_errors(bool)
static void register_id(int id, const char *msg)
sc_severity severity
Definition: sc_report.h:171
const sc_msg_def * md
Definition: sc_report.h:172
sc_report(sc_severity, const sc_msg_def *, const char *msg, const char *file, int line, int verbosity_level=SC_MEDIUM)
sc_report(const sc_report &)
void swap(sc_report &)
int get_line_number() const
Definition: sc_report.h:143
sc_time * timestamp
Definition: sc_report.h:176
static void suppress_infos(bool)
const char * get_process_name() const
int get_id() const
sc_report & operator=(const sc_report &)
static bool is_suppressed(int id)
const sc_time & get_time() const
Definition: sc_report.h:146
bool valid() const
virtual const char * what() const noexcept
Definition: sc_report.h:155
virtual ~sc_report() noexcept
sc_severity get_severity() const
Definition: sc_report.h:137
const char * get_file_name() const
Definition: sc_report.h:140
friend SC_API sc_report * sc_handle_exception()
static const char * get_message(int id)
int get_verbosity() const
Definition: sc_report.h:151