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