SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_vcd_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_vcd_trace.h - Implementation of VCD tracing.
21 
22  Original 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, and significantly enhanced, the basics
41  are identical to what was originally contributed by Infineon. The
42  contribution of Infineon in the development of this tracing
43  technology is hereby acknowledged.
44 
45  *****************************************************************************/
46 
47 #ifndef SC_VCD_TRACE_H
48 #define SC_VCD_TRACE_H
49 
51 
52 namespace sc_core {
53 
54 class vcd_trace; // defined in vcd_trace.cpp
55 template<class T> class vcd_T_trace;
56 
57 
58 // ----------------------------------------------------------------------------
59 // CLASS : vcd_trace_file
60 //
61 // ...
62 // ----------------------------------------------------------------------------
63 
65  : public sc_trace_file_base
66 {
67 public:
68 
70 
71  // sc_set_vcd_time_unit is deprecated.
72 #if 0 // deprecated
73  inline void sc_set_vcd_time_unit(int exponent10_seconds)
74  { set_time_unit(exponent10_seconds); }
75 #endif
76 
77  // Create a Vcd trace file.
78  // `Name' forms the base of the name to which `.vcd' is added.
79  vcd_trace_file(const char *name);
80 
81  // Flush results and close file.
83 
84 protected:
85 
86  // These are all virtual functions in sc_trace_file and
87  // they need to be defined here.
88 
89  // Trace a boolean object (single bit)
90  void trace(const bool& object, const std::string& name);
91 
92  // Trace a sc_bit object (single bit)
93  virtual void trace( const sc_dt::sc_bit& object,
94  const std::string& name);
95 
96  // Trace a sc_logic object (single bit)
97  void trace(const sc_dt::sc_logic& object, const std::string& name);
98 
99  // Trace an unsigned char with the given width
100  void trace(const unsigned char& object, const std::string& name,
101  int width);
102 
103  // Trace an unsigned short with the given width
104  void trace(const unsigned short& object, const std::string& name,
105  int width);
106 
107  // Trace an unsigned int with the given width
108  void trace(const unsigned int& object, const std::string& name,
109  int width);
110 
111  // Trace an unsigned long with the given width
112  void trace(const unsigned long& object, const std::string& name,
113  int width);
114 
115  // Trace a signed char with the given width
116  void trace(const char& object, const std::string& name, int width);
117 
118  // Trace a signed short with the given width
119  void trace(const short& object, const std::string& name, int width);
120 
121  // Trace a signed int with the given width
122  void trace(const int& object, const std::string& name, int width);
123 
124  // Trace a signed long with the given width
125  void trace(const long& object, const std::string& name, int width);
126 
127  // Trace an int64 with a given width
128  void trace(const sc_dt::int64& object, const std::string& name,
129  int width);
130 
131  // Trace a uint64 with a given width
132  void trace(const sc_dt::uint64& object, const std::string& name,
133  int width);
134 
135  // Trace a float
136  void trace(const float& object, const std::string& name);
137 
138  // Trace a double
139  void trace(const double& object, const std::string& name);
140 
141  // Trace sc_dt::sc_uint_base
142  void trace (const sc_dt::sc_uint_base& object,
143  const std::string& name);
144 
145  // Trace sc_dt::sc_int_base
146  void trace (const sc_dt::sc_int_base& object,
147  const std::string& name);
148 
149  // Trace sc_dt::sc_unsigned
150  void trace (const sc_dt::sc_unsigned& object,
151  const std::string& name);
152 
153  // Trace sc_dt::sc_signed
154  void trace (const sc_dt::sc_signed& object, const std::string& name);
155 
156  // Trace sc_dt::sc_fxval
157  void trace( const sc_dt::sc_fxval& object, const std::string& name );
158 
159  // Trace sc_dt::sc_fxval_fast
160  void trace( const sc_dt::sc_fxval_fast& object,
161  const std::string& name );
162 
163  // Trace sc_dt::sc_fxnum
164  void trace( const sc_dt::sc_fxnum& object, const std::string& name );
165 
166  // Trace sc_dt::sc_fxnum_fast
167  void trace( const sc_dt::sc_fxnum_fast& object,
168  const std::string& name );
169 
170  template<class T>
171  void traceT(const T& object, const std::string& name,
172  vcd_enum type=VCD_WIRE)
173  {
174  if( add_trace_check(name) )
175  traces.push_back(new vcd_T_trace<T>( object, name
176  , obtain_name(),type) );
177  }
178 
179  // Trace sc_dt::sc_bv_base (sc_dt::sc_bv)
180  virtual void trace(const sc_dt::sc_bv_base& object,
181  const std::string& name);
182 
183  // Trace sc_dt::sc_lv_base (sc_dt::sc_lv)
184  virtual void trace(const sc_dt::sc_lv_base& object,
185  const std::string& name);
186  // Trace an enumerated object - where possible output the enumeration literals
187  // in the trace file. Enum literals is a null terminated array of null
188  // terminated char* literal strings.
189  void trace(const unsigned& object, const std::string& name,
190  const char** enum_literals);
191 
192  // Output a comment to the trace file
193  void write_comment(const std::string& comment);
194 
195  // Write trace info for cycle.
196  void cycle(bool delta_cycle);
197 
198 private:
199 
200 #if SC_TRACING_PHASE_CALLBACKS_
201  // avoid hidden overload warnings
202  virtual void trace( sc_trace_file* ) const { sc_assert(false); }
203 #endif // SC_TRACING_PHASE_CALLBACKS_
204 
205  // Initialize the VCD tracing
206  virtual void do_initialize();
207 
208  unsigned vcd_name_index; // Number of variables traced
209 
210  unsigned previous_time_units_low; // Previous time unit as 64-bit integer
211  unsigned previous_time_units_high;
212 
213 public:
214 
215  // Array to store the variables traced
216  std::vector<vcd_trace*> traces;
217 
218  // Create VCD names for each variable
219  std::string obtain_name();
220 
221 };
222 
223 } // namespace sc_core
224 
225 #endif // SC_VCD_TRACE_H
226 // Taf!
#define sc_assert(expr)
Definition: sc_report.h:235
uint64_t uint64
Definition: sc_nbdefs.h:183
vcd_trace_file(const char *name)
void traceT(const T &object, const std::string &name, vcd_enum type=VCD_WIRE)
Definition: sc_vcd_trace.h:171
void trace(const bool &object, const std::string &name)
virtual void set_time_unit(double v, sc_time_unit tu)
int64_t int64
Definition: sc_nbdefs.h:182
std::string obtain_name()
void write_comment(const std::string &comment)
std::vector< vcd_trace * > traces
Definition: sc_vcd_trace.h:216
bool add_trace_check(const std::string &name) const
void cycle(bool delta_cycle)