SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_trace.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_trace.h - Functions for tracing signals and variables.
21 
22  Author: Abhijit Ghosh, Synopsys, Inc.
23 
24  *****************************************************************************/
25 
26 /*****************************************************************************
27 
28  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
29  changes you are making here.
30 
31  Name, Affiliation, Date:
32  Description of Modification:
33 
34  *****************************************************************************/
35 
36 /*****************************************************************************
37 
38  Acknowledgement: The tracing mechanism is based on the tracing
39  mechanism developed at Infineon (formerly Siemens HL). Though this
40  code is somewhat different, the basics are identical to what was
41  originally contributed by Infineon. The contribution of Infineon
42  in the development of this tracing technology is hereby
43  acknowledged.
44 
45  *****************************************************************************/
46 
47 #ifndef SC_TRACE_H
48 #define SC_TRACE_H
49 
50 #include <cstdio>
51 
53 #include "sysc/kernel/sc_time.h"
54 
55 // Some forward declarations
56 namespace sc_dt
57 {
58  class sc_bit;
59  class sc_logic;
60  class sc_bv_base;
61  class sc_lv_base;
62  class sc_signed;
63  class sc_unsigned;
64  class sc_int_base;
65  class sc_uint_base;
66  class sc_fxval;
67  class sc_fxval_fast;
68  class sc_fxnum;
69  class sc_fxnum_fast;
70 }
71 
72 namespace sc_core {
73 
74 class sc_time;
75 
76 template <class T> class sc_signal_in_if;
77 
78 
79 // Base class for all kinds of trace files.
80 
82 {
83  friend class sc_simcontext;
84 
85 public:
86 
87  // Constructor
88  sc_trace_file();
89 
90  // All functions are pure virtual because they need to be defined by the
91  // particular tracing mechanism
92 
93 
94 #define DECL_TRACE_METHOD_A(tp) \
95  virtual void trace( const tp& object, \
96  const std::string& name ) = 0;
97 
98 #define DECL_TRACE_METHOD_B(tp) \
99  virtual void trace( const tp& object, \
100  const std::string& name, \
101  int width ) = 0;
102 
103 
104  DECL_TRACE_METHOD_A( bool )
105  DECL_TRACE_METHOD_A( sc_dt::sc_bit )
106  DECL_TRACE_METHOD_A( sc_dt::sc_logic )
107 
108  DECL_TRACE_METHOD_B( unsigned char )
109  DECL_TRACE_METHOD_B( unsigned short )
110  DECL_TRACE_METHOD_B( unsigned int )
111  DECL_TRACE_METHOD_B( unsigned long )
112  DECL_TRACE_METHOD_B( char )
113  DECL_TRACE_METHOD_B( short )
114  DECL_TRACE_METHOD_B( int )
115  DECL_TRACE_METHOD_B( long )
116  DECL_TRACE_METHOD_B( sc_dt::int64 )
117  DECL_TRACE_METHOD_B( sc_dt::uint64 )
118 
119  DECL_TRACE_METHOD_A( float )
120  DECL_TRACE_METHOD_A( double )
121  DECL_TRACE_METHOD_A( sc_dt::sc_int_base )
122  DECL_TRACE_METHOD_A( sc_dt::sc_uint_base )
123  DECL_TRACE_METHOD_A( sc_dt::sc_signed )
124  DECL_TRACE_METHOD_A( sc_dt::sc_unsigned )
125 
126  DECL_TRACE_METHOD_A( sc_dt::sc_fxval )
127  DECL_TRACE_METHOD_A( sc_dt::sc_fxval_fast )
128  DECL_TRACE_METHOD_A( sc_dt::sc_fxnum )
129  DECL_TRACE_METHOD_A( sc_dt::sc_fxnum_fast )
130 
131  DECL_TRACE_METHOD_A( sc_dt::sc_bv_base )
132  DECL_TRACE_METHOD_A( sc_dt::sc_lv_base )
133 
134 
135 #undef DECL_TRACE_METHOD_A
136 #undef DECL_TRACE_METHOD_B
137 
138  // Trace an enumerated object - where possible output the enumeration
139  // literals in the trace file. Enum literals is a null terminated array
140  // of null terminated char* literal strings.
141  virtual void trace( const unsigned int& object,
142  const std::string& name,
143  const char** enum_literals ) = 0;
144 
145  // Output a comment to the trace file
146  virtual void write_comment( const std::string& comment ) = 0;
147 
148  // Set the amount of space before next column
149  // (For most formats this does nothing)
150  virtual void space( int n );
151 
152  // Also trace transitions between delta cycles if flag is true.
153  virtual void delta_cycles( bool flag );
154 
155  // Set time unit.
156  virtual void set_time_unit( double v, sc_time_unit tu )=0;
157 
158 protected:
159 
160  // Write trace info for cycle
161  virtual void cycle( bool delta_cycle ) = 0;
162 
163  // Flush results and close file
164  virtual ~sc_trace_file()
165  { /* Intentionally blank */ }
166 };
167 
168 /*****************************************************************************/
169 
170 // Now comes all the SystemC defined tracing functions.
171 // We define two sc_trace() versions for scalar types; one where the object to
172 // be traced is passed as a reference and the other where a pointer to the
173 // tracing object is passed.
174 
175 #define DECL_TRACE_FUNC_REF_A(tp) \
176 void \
177 sc_trace( sc_trace_file* tf, \
178  const tp& object, \
179  const std::string& name );
180 
181 #define DECL_TRACE_FUNC_PTR_A(tp) \
182 void \
183 sc_trace( sc_trace_file* tf, \
184  const tp* object, \
185  const std::string& name ); \
186 
187 #define DECL_TRACE_FUNC_A(tp) \
188 DECL_TRACE_FUNC_REF_A(tp) \
189 DECL_TRACE_FUNC_PTR_A(tp)
190 
191 
193 DECL_TRACE_FUNC_A( sc_dt::sc_logic )
194 
195 DECL_TRACE_FUNC_A( sc_dt::sc_int_base )
196 DECL_TRACE_FUNC_A( sc_dt::sc_uint_base )
197 DECL_TRACE_FUNC_A( sc_dt::sc_signed )
198 DECL_TRACE_FUNC_A( sc_dt::sc_unsigned )
199 
200 DECL_TRACE_FUNC_REF_A( sc_dt::sc_bv_base )
201 DECL_TRACE_FUNC_REF_A( sc_dt::sc_lv_base )
202 
203 
204 #undef DECL_TRACE_FUNC_REF_A
205 #undef DECL_TRACE_FUNC_PTR_A
206 #undef DECL_TRACE_FUNC_A
207 
208 
209 // ----------------------------------------------------------------------------
210 
211 #define DEFN_TRACE_FUNC_REF_A(tp) \
212 inline \
213 void \
214 sc_trace( sc_trace_file* tf, const tp& object, const std::string& name ) \
215 { \
216  if( tf ) { \
217  tf->trace( object, name ); \
218  } \
219 }
220 
221 #define DEFN_TRACE_FUNC_PTR_A(tp) \
222 inline \
223 void \
224 sc_trace( sc_trace_file* tf, const tp* object, const std::string& name ) \
225 { \
226  if( tf ) { \
227  tf->trace( *object, name ); \
228  } \
229 }
230 
231 #define DEFN_TRACE_FUNC_A(tp) \
232 DEFN_TRACE_FUNC_REF_A(tp) \
233 DEFN_TRACE_FUNC_PTR_A(tp)
234 
235 
236 #define DEFN_TRACE_FUNC_REF_B(tp) \
237 inline \
238 void \
239 sc_trace( sc_trace_file* tf, const tp& object, const std::string& name, \
240  int width = 8 * sizeof( tp ) ) \
241 { \
242  if( tf ) { \
243  tf->trace( object, name, width ); \
244  } \
245 }
246 
247 #define DEFN_TRACE_FUNC_PTR_B(tp) \
248 inline \
249 void \
250 sc_trace( sc_trace_file* tf, const tp* object, const std::string& name, \
251  int width = 8 * sizeof( tp ) ) \
252 { \
253  if( tf ) { \
254  tf->trace( *object, name, width ); \
255  } \
256 }
257 
258 
259 #define DEFN_TRACE_FUNC_B(tp) \
260 DEFN_TRACE_FUNC_REF_B(tp) \
261 DEFN_TRACE_FUNC_PTR_B(tp)
262 
263 
264 DEFN_TRACE_FUNC_A( bool )
265 DEFN_TRACE_FUNC_A( float )
266 DEFN_TRACE_FUNC_A( double )
267 
268 DEFN_TRACE_FUNC_B( unsigned char )
269 DEFN_TRACE_FUNC_B( unsigned short )
270 DEFN_TRACE_FUNC_B( unsigned int )
271 DEFN_TRACE_FUNC_B( unsigned long )
272 DEFN_TRACE_FUNC_B( char )
273 DEFN_TRACE_FUNC_B( short )
274 DEFN_TRACE_FUNC_B( int )
275 DEFN_TRACE_FUNC_B( long )
276 DEFN_TRACE_FUNC_B( sc_dt::int64 )
277 DEFN_TRACE_FUNC_B( sc_dt::uint64 )
278 
279 
280 #undef DEFN_TRACE_FUNC_REF_A
281 #undef DEFN_TRACE_FUNC_PTR_A
282 #undef DEFN_TRACE_FUNC_A
283 
284 #undef DEFN_TRACE_FUNC_REF_B
285 #undef DEFN_TRACE_FUNC_PTR_B
286 #undef DEFN_TRACE_FUNC_B
287 
288 
289 template <class T>
290 inline
291 void
293  const sc_signal_in_if<T>& object,
294  const std::string& name )
295 {
296  sc_trace( tf, object.read(), name );
297 }
298 
299 template< class T >
300 inline
301 void
303  const sc_signal_in_if<T>& object,
304  const char* name )
305 {
306  sc_trace( tf, object.read(), name );
307 }
308 
309 
310 // specializations for signals of type char, short, int, long
311 
312 void sc_trace( sc_trace_file* tf,
313  const sc_signal_in_if<char>& object,
314  const std::string& name,
315  int width );
316 
317 void sc_trace( sc_trace_file* tf,
318  const sc_signal_in_if<short>& object,
319  const std::string& name,
320  int width );
321 
322 void sc_trace( sc_trace_file* tf,
323  const sc_signal_in_if<int>& object,
324  const std::string& name,
325  int width );
326 
327 void sc_trace( sc_trace_file* tf,
328  const sc_signal_in_if<long>& object,
329  const std::string& name,
330  int width );
331 
332 
333 // 1. non-template function is better than template
334 // 2. more-specialized template is better than less-specialized
335 // 3. no partial specialization for template functions
336 
337 
338 // Trace an enumerated object - where possible output the enumeration literals
339 // in the trace file. Enum literals is a null terminated array of null
340 // terminated char* literal strings.
341 
342 void
343 sc_trace( sc_trace_file* tf,
344  const unsigned int& object,
345  const std::string& name,
346  const char** enum_literals );
347 
348 
349 // Dummy function for arbitrary types of value, does nothing
350 
351 extern void sc_trace( sc_trace_file* tf,
352  const void* object,
353  const std::string& name );
354 
355 
356 // Turn on/off delta cycle tracing on trace file `tf'.
357 // Default is to turn on delta cycle tracing.
358 
359 inline
360 void
361 sc_trace_delta_cycles( sc_trace_file* tf, bool on = true )
362 {
363  if( tf ) tf->delta_cycles( on );
364 }
365 
366 
367 // Output a comment to the trace file
368 
369 inline
370 void
371 sc_write_comment( sc_trace_file* tf, const std::string& comment )
372 {
373  if( tf ) tf->write_comment( comment );
374 }
375 
376 
377 // Equivalent of std::fprintf for trace files!
378 
379 void tprintf( sc_trace_file* tf, const char* format, ... );
380 
381 // ----------------------------------------------------------------------------
382 // Create VCD file
383 extern sc_trace_file *sc_create_vcd_trace_file(const char* name);
384 extern void sc_close_vcd_trace_file( sc_trace_file* tf );
385 
386 
387 // ----------------------------------------------------------------------------
388 // Create WIF file
389 extern sc_trace_file *sc_create_wif_trace_file(const char *name);
390 extern void sc_close_wif_trace_file( sc_trace_file* tf );
391 
392 } // namespace sc_core
393 
394 #endif // SC_TRACE_H
395 // Taf
void tprintf(sc_trace_file *tf, const char *format,...)
virtual void set_time_unit(double v, sc_time_unit tu)=0
#define DECL_TRACE_METHOD_B(tp)
Definition: sc_trace.h:98
sc_time_unit
Definition: sc_time.h:56
void sc_trace_delta_cycles(sc_trace_file *tf, bool on=true)
Definition: sc_trace.h:361
virtual void space(int n)
#define DECL_TRACE_FUNC_A(tp)
Definition: sc_trace.h:187
uint64_t uint64
Definition: sc_nbdefs.h:183
virtual void trace(const unsigned int &object, const std::string &name, const char **enum_literals)=0
virtual void delta_cycles(bool flag)
void sc_close_wif_trace_file(sc_trace_file *tf)
virtual void cycle(bool delta_cycle)=0
#define DECL_TRACE_FUNC_REF_A(tp)
Definition: sc_trace.h:175
int64_t int64
Definition: sc_nbdefs.h:182
virtual ~sc_trace_file()
Definition: sc_trace.h:164
virtual void write_comment(const std::string &comment)=0
void sc_write_comment(sc_trace_file *tf, const std::string &comment)
Definition: sc_trace.h:371
sc_trace_file * sc_create_vcd_trace_file(const char *name)
sc_trace_file * sc_create_wif_trace_file(const char *name)
void sc_close_vcd_trace_file(sc_trace_file *tf)
#define DECL_TRACE_METHOD_A(tp)
Definition: sc_trace.h:94
void sc_trace(sc_trace_file *tf, const sc_in< T > &port, const std::string &name)
#define DEFN_TRACE_FUNC_A(tp)
Definition: sc_trace.h:231
#define DEFN_TRACE_FUNC_B(tp)
Definition: sc_trace.h:259