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