SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_trace.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_trace.h - Functions for tracing signals and variables.
23 
24  Author: Abhijit Ghosh, Synopsys, Inc.
25 
26  *****************************************************************************/
27 
28 /*****************************************************************************
29 
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32 
33  Name, Affiliation, Date:
34  Description of Modification:
35 
36  *****************************************************************************/
37 
38 /*****************************************************************************
39 
40  Acknowledgement: The tracing mechanism is based on the tracing
41  mechanism developed at Infineon (formerly Siemens HL). Though this
42  code is somewhat different, the basics are identical to what was
43  originally contributed by Infineon. The contribution of Infineon
44  in the development of this tracing technology is hereby
45  acknowledged.
46 
47  *****************************************************************************/
48 
49 #ifndef SC_TRACE_H
50 #define SC_TRACE_H
51 
52 #include <cstdio>
53 
55 #include "sysc/kernel/sc_time.h"
56 
57 // Some forward declarations
58 namespace sc_dt
59 {
60  class sc_bit;
61  class sc_logic;
62  class sc_bv_base;
63  class sc_lv_base;
64  class sc_signed;
65  class sc_unsigned;
66  class sc_int_base;
67  class sc_uint_base;
68  class sc_fxval;
69  class sc_fxval_fast;
70  class sc_fxnum;
71  class sc_fxnum_fast;
72 }
73 
74 namespace sc_core {
75 
76 class sc_event;
77 class sc_time;
78 
79 template <class T> class sc_signal_in_if;
80 
81 // Base class for all kinds of trace files.
82 
84 {
85  friend class sc_simcontext;
86 
87 public:
88 
89  // Constructor
90  sc_trace_file();
91 
92  // All functions are pure virtual because they need to be defined by the
93  // particular tracing mechanism
94 
95 
96 #define DECL_TRACE_METHOD_A(tp) \
97  virtual void trace( const tp& object, \
98  const std::string& name ) = 0;
99 
100 #define DECL_TRACE_METHOD_B(tp) \
101  virtual void trace( const tp& object, \
102  const std::string& name, \
103  int width ) = 0;
104 
105 
107  DECL_TRACE_METHOD_A( sc_time )
108 
109  DECL_TRACE_METHOD_A( bool )
112 
113  DECL_TRACE_METHOD_B( unsigned char )
114  DECL_TRACE_METHOD_B( unsigned short )
115  DECL_TRACE_METHOD_B( unsigned int )
116  DECL_TRACE_METHOD_B( unsigned long )
117  DECL_TRACE_METHOD_B( char )
118  DECL_TRACE_METHOD_B( short )
119  DECL_TRACE_METHOD_B( int )
120  DECL_TRACE_METHOD_B( long )
123 
124  DECL_TRACE_METHOD_A( float )
125  DECL_TRACE_METHOD_A( double )
130 
135 
138 
139 
140 #undef DECL_TRACE_METHOD_A
141 #undef DECL_TRACE_METHOD_B
142 
143  // Trace an enumerated object - where possible output the enumeration
144  // literals in the trace file. Enum literals is a null terminated array
145  // of null terminated char* literal strings.
146  virtual void trace( const unsigned int& object,
147  const std::string& name,
148  const char** enum_literals ) = 0;
149 
150  // Output a comment to the trace file
151  virtual void write_comment( const std::string& comment ) = 0;
152 
153  // Set the amount of space before next column
154  // (For most formats this does nothing)
155  virtual void space( int n );
156 
157  // Also trace transitions between delta cycles if flag is true.
158  virtual void delta_cycles( bool flag );
159 
160  // Set time unit.
161  virtual void set_time_unit( double v, sc_time_unit tu )=0;
162 
163 protected:
164 
165  // Write trace info for cycle
166  virtual void cycle( bool delta_cycle ) = 0;
167 
168  // Helper for event tracing
169  const sc_dt::uint64& event_trigger_stamp( const sc_event& event ) const;
170 
171  // Flush results and close file
172  virtual ~sc_trace_file()
173  { /* Intentionally blank */ }
174 };
175 
176 /*****************************************************************************/
177 
178 // Now comes all the SystemC defined tracing functions.
179 // We define two sc_trace() versions for scalar types; one where the object to
180 // be traced is passed as a reference and the other where a pointer to the
181 // tracing object is passed.
182 
183 #define DECL_TRACE_FUNC_REF_A(tp) \
184 SC_API void \
185 sc_trace( sc_trace_file* tf, \
186  const tp& object, \
187  const std::string& name );
188 
189 #define DECL_TRACE_FUNC_PTR_A(tp) \
190 SC_API void \
191 sc_trace( sc_trace_file* tf, \
192  const tp* object, \
193  const std::string& name ); \
194 
195 #define DECL_TRACE_FUNC_A(tp) \
196 DECL_TRACE_FUNC_REF_A(tp) \
197 DECL_TRACE_FUNC_PTR_A(tp)
198 
199 #define DECL_TRACE_FUNC_REF_B(tp) \
200 SC_API void \
201 sc_trace( sc_trace_file* tf, const tp& object, const std::string& name, \
202  int width = 8 * sizeof( tp ) );
203 
204 
205 #define DECL_TRACE_FUNC_PTR_B(tp) \
206 SC_API void \
207 sc_trace( sc_trace_file* tf, const tp* object, const std::string& name, \
208  int width = 8 * sizeof( tp ) );
209 
210 
211 #define DECL_TRACE_FUNC_B(tp) \
212 DECL_TRACE_FUNC_REF_B(tp) \
213 DECL_TRACE_FUNC_PTR_B(tp)
214 
215 
217 DECL_TRACE_FUNC_A( sc_time )
218 
219 DECL_TRACE_FUNC_A( bool )
220 DECL_TRACE_FUNC_A( float )
221 DECL_TRACE_FUNC_A( double )
222 
223 DECL_TRACE_FUNC_B( unsigned char )
224 DECL_TRACE_FUNC_B( unsigned short )
225 DECL_TRACE_FUNC_B( unsigned int )
226 DECL_TRACE_FUNC_B( unsigned long )
227 DECL_TRACE_FUNC_B( char )
228 DECL_TRACE_FUNC_B( short )
229 DECL_TRACE_FUNC_B( int )
230 DECL_TRACE_FUNC_B( long )
233 
234 
237 
242 
245 
250 
251 
252 #undef DECL_TRACE_FUNC_REF_A
253 #undef DECL_TRACE_FUNC_PTR_A
254 #undef DECL_TRACE_FUNC_A
255 
256 
257 #undef DECL_TRACE_FUNC_REF_B
258 #undef DECL_TRACE_FUNC_PTR_B
259 #undef DECL_TRACE_FUNC_B
260 
261 
262 template <class T>
263 inline
264 void
266  const sc_signal_in_if<T>& object,
267  const std::string& name )
268 {
269  sc_trace( tf, object.read(), name );
270 }
271 
272 template< class T >
273 inline
274 void
276  const sc_signal_in_if<T>& object,
277  const char* name )
278 {
279  sc_trace( tf, object.read(), name );
280 }
281 
282 
283 // specializations for signals of type char, short, int, long
284 
285 SC_API void sc_trace( sc_trace_file* tf,
286  const sc_signal_in_if<char>& object,
287  const std::string& name,
288  int width );
289 
290 SC_API void sc_trace( sc_trace_file* tf,
291  const sc_signal_in_if<short>& object,
292  const std::string& name,
293  int width );
294 
295 SC_API void sc_trace( sc_trace_file* tf,
296  const sc_signal_in_if<int>& object,
297  const std::string& name,
298  int width );
299 
300 SC_API void sc_trace( sc_trace_file* tf,
301  const sc_signal_in_if<long>& object,
302  const std::string& name,
303  int width );
304 
305 
306 // 1. non-template function is better than template
307 // 2. more-specialized template is better than less-specialized
308 // 3. no partial specialization for template functions
309 
310 
311 // Trace an enumerated object - where possible output the enumeration literals
312 // in the trace file. Enum literals is a null terminated array of null
313 // terminated char* literal strings.
314 
315 SC_API void
317  const unsigned int& object,
318  const std::string& name,
319  const char** enum_literals );
320 
321 
322 // Dummy function for arbitrary types of value, does nothing
323 
324 extern SC_API void sc_trace( sc_trace_file* tf,
325  const void* object,
326  const std::string& name );
327 
328 
329 // Turn on/off delta cycle tracing on trace file `tf'.
330 // Default is to turn on delta cycle tracing.
331 
332 inline
333 SC_API void
334 sc_trace_delta_cycles( sc_trace_file* tf, bool on = true )
335 {
336  if( tf ) tf->delta_cycles( on );
337 }
338 
339 
340 // Output a comment to the trace file
341 
342 inline
343 SC_API void
344 sc_write_comment( sc_trace_file* tf, const std::string& comment )
345 {
346  if( tf ) tf->write_comment( comment );
347 }
348 
349 
350 // Equivalent of std::fprintf for trace files!
351 
352 SC_API void tprintf( sc_trace_file* tf, const char* format, ... );
353 
354 // ----------------------------------------------------------------------------
355 // Create VCD file
356 extern SC_API sc_trace_file *sc_create_vcd_trace_file(const char* name);
357 extern SC_API void sc_close_vcd_trace_file( sc_trace_file* tf );
358 
359 
360 // ----------------------------------------------------------------------------
361 // Create WIF file
362 extern SC_API sc_trace_file *sc_create_wif_trace_file(const char *name);
363 extern SC_API void sc_close_wif_trace_file( sc_trace_file* tf );
364 
365 } // namespace sc_core
366 
367 #endif // SC_TRACE_H
368 // Taf
Base class for the fixed-point types; limited precision.
Definition: sc_fxnum.h:991
The sc_signal<T> input interface class.
Definition: sc_signal_ifs.h:49
Fixed-point value types; limited precision.
Definition: sc_fxval.h:439
SC_API void sc_trace(sc_trace_file *tf, const void *object, const std::string &name)
int64_t int64
Definition: sc_nbdefs.h:188
Bit class.
Definition: sc_bit.h:92
Base class for sc_uint.
Definition: sc_uint_base.h:534
Arbitrary precision signed number.
Definition: sc_signed.h:1099
#define DECL_TRACE_FUNC_A(tp)
Definition: sc_trace.h:195
uint64_t uint64
Definition: sc_nbdefs.h:189
Arbitrary precision unsigned number.
Definition: sc_unsigned.h:1001
SC_API void sc_trace_delta_cycles(sc_trace_file *tf, bool on=true)
Definition: sc_trace.h:334
Base class for the fixed-point types; arbitrary precision.
Definition: sc_fxnum.h:564
Four-valued logic type.
Definition: sc_logic.h:104
Base class for sc_int.
Definition: sc_int_base.h:548
#define DECL_TRACE_METHOD_B(tp)
Definition: sc_trace.h:100
Fixed-point value type; arbitrary precision.
Definition: sc_fxval.h:95
Arbitrary size logic vector base class.
Definition: sc_lv_base.h:91
class SC_API sc_event
Definition: sc_interface.h:40
The time class.
SC_API sc_trace_file * sc_create_wif_trace_file(const char *name)
The simulation context.
virtual ~sc_trace_file()
Definition: sc_trace.h:172
class SC_API sc_trace_file
Definition: sc_object.h:52
SC_API void tprintf(sc_trace_file *tf, const char *format,...)
SC_API void sc_write_comment(sc_trace_file *tf, const std::string &comment)
Definition: sc_trace.h:344
#define DECL_TRACE_FUNC_B(tp)
Definition: sc_trace.h:211
virtual void write_comment(const std::string &comment)=0
SC_API void sc_close_wif_trace_file(sc_trace_file *tf)
virtual void delta_cycles(bool flag)
Top level header file for arbitrary precision signed/unsigned.
class SC_API sc_logic
Definition: sc_signal_ifs.h:43
Arbitrary size bit vector base class.
Definition: sc_bv_base.h:80
SC_API sc_trace_file * sc_create_vcd_trace_file(const char *name)
#define SC_API
Definition: sc_cmnhdr.h:168
#define DECL_TRACE_METHOD_A(tp)
Definition: sc_trace.h:96
sc_time_unit
Enumeration of time units.
Definition: sc_time.h:64
SC_API void sc_close_vcd_trace_file(sc_trace_file *tf)