SystemC 3.0.0
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
58namespace 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
74namespace sc_core {
75
76class sc_event;
77class sc_time;
78
79template <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
87public:
88
89 // Constructor
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 )
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
163protected:
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
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) \
184SC_API void \
185sc_trace( sc_trace_file* tf, \
186 const tp& object, \
187 const std::string& name );
188
189#define DECL_TRACE_FUNC_PTR_A(tp) \
190SC_API void \
191sc_trace( sc_trace_file* tf, \
192 const tp* object, \
193 const std::string& name ); \
194
195#define DECL_TRACE_FUNC_A(tp) \
196DECL_TRACE_FUNC_REF_A(tp) \
197DECL_TRACE_FUNC_PTR_A(tp)
198
199#define DECL_TRACE_FUNC_REF_B(tp) \
200SC_API void \
201sc_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) \
206SC_API void \
207sc_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) \
212DECL_TRACE_FUNC_REF_B(tp) \
213DECL_TRACE_FUNC_PTR_B(tp)
214
215
217DECL_TRACE_FUNC_A( sc_time )
218
219DECL_TRACE_FUNC_A( bool )
220DECL_TRACE_FUNC_A( float )
221DECL_TRACE_FUNC_A( double )
222
223DECL_TRACE_FUNC_B( unsigned char )
224DECL_TRACE_FUNC_B( unsigned short )
225DECL_TRACE_FUNC_B( unsigned int )
226DECL_TRACE_FUNC_B( unsigned long )
227DECL_TRACE_FUNC_B( char )
228DECL_TRACE_FUNC_B( short )
230DECL_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
262template <class T>
263inline
264void
266 const sc_signal_in_if<T>& object,
267 const std::string& name )
268{
269 sc_trace( tf, object.read(), name );
270}
271
272template< class T >
273inline
274void
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
286 const sc_signal_in_if<char>& object,
287 const std::string& name,
288 int width );
289
291 const sc_signal_in_if<short>& object,
292 const std::string& name,
293 int width );
294
296 const sc_signal_in_if<int>& object,
297 const std::string& name,
298 int width );
299
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
315SC_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
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
332inline
333SC_API void
335{
336 if( tf ) tf->delta_cycles( on );
337}
338
339
340// Output a comment to the trace file
341
342inline
343SC_API void
344sc_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
352SC_API void tprintf( sc_trace_file* tf, const char* format, ... );
353
354// ----------------------------------------------------------------------------
355// Create VCD file
358
359
360// ----------------------------------------------------------------------------
361// Create WIF file
364
365} // namespace sc_core
366
367#endif // SC_TRACE_H
368// Taf
#define DECL_TRACE_FUNC_B(tp)
Definition: sc_trace.h:211
#define DECL_TRACE_FUNC_A(tp)
Definition: sc_trace.h:195
#define DECL_TRACE_METHOD_B(tp)
Definition: sc_trace.h:100
#define DECL_TRACE_METHOD_A(tp)
Definition: sc_trace.h:96
#define SC_API
Definition: sc_cmnhdr.h:148
SC_API void sc_close_vcd_trace_file(sc_trace_file *tf)
class SC_API sc_event
Definition: sc_interface.h:36
SC_API void sc_write_comment(sc_trace_file *tf, const std::string &comment)
Definition: sc_trace.h:344
SC_API sc_trace_file * sc_create_vcd_trace_file(const char *name)
void sc_trace(sc_trace_file *tf, const sc_in< T > &port, const std::string &name)
SC_API void tprintf(sc_trace_file *tf, const char *format,...)
SC_API void sc_close_wif_trace_file(sc_trace_file *tf)
SC_API sc_trace_file * sc_create_wif_trace_file(const char *name)
sc_time_unit
Definition: sc_time.h:82
SC_API void sc_trace_delta_cycles(sc_trace_file *tf, bool on=true)
Definition: sc_trace.h:334
unsigned long long uint64
Definition: sc_nbdefs.h:216
class SC_API sc_logic
Definition: sc_signal_ifs.h:39
long long int64
Definition: sc_nbdefs.h:215
const sc_dt::uint64 & event_trigger_stamp(const sc_event &event) const
virtual ~sc_trace_file()
Definition: sc_trace.h:172
virtual void trace(const unsigned int &object, const std::string &name, const char **enum_literals)=0
virtual void write_comment(const std::string &comment)=0
virtual void delta_cycles(bool flag)
virtual void cycle(bool delta_cycle)=0
virtual void set_time_unit(double v, sc_time_unit tu)=0
virtual void space(int n)