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