SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_wif_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_wif_trace.h - Implementation of WIF 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.
42  The contribution of Infineon in the development of this tracing
43  technology is hereby acknowledged.
44 
45  *****************************************************************************/
46 
47 /*****************************************************************************
48 
49  Instead of creating the binary WIF format, we create the ASCII
50  WIF format which can be converted to the binary format using
51  a2wif (utility that comes with VSS from Synopsys). This way,
52  a user who does not have Synopsys VSS can still create WIF
53  files, but the files can only be viewed by users who have VSS.
54 
55  *****************************************************************************/
56 
57 #ifndef SC_WIF_TRACE_H
58 #define SC_WIF_TRACE_H
59 
60 #include <cstdio>
63 
64 namespace sc_core {
65 
66 class wif_trace; // defined in wif_trace.cc
67 template<class T> class wif_T_trace;
68 
70  : public sc_trace_file_base
71 {
72 public:
74 
75  // Create a wif trace file.
76  // `Name' forms the base of the name to which `.awif' is added.
77  explicit wif_trace_file(const char *name);
78 
80 
81 protected:
82  // These are all virtual functions in sc_trace_file and
83  // they need to be defined here.
84 
85  // Trace a boolean object (single bit)
86  void trace(const bool& object, const std::string& name);
87 
88  // Trace a sc_bit object (single bit)
89  void trace(const sc_dt::sc_bit& object, const std::string& name);
90 
91  // Trace a sc_logic object (single bit)
92  void trace(const sc_dt::sc_logic& object, const std::string& name);
93 
94  // Trace an unsigned char with the given width
95  void trace(const unsigned char& object, const std::string& name,
96  int width);
97 
98  // Trace an unsigned short with the given width
99  void trace(const unsigned short& object, const std::string& name,
100  int width);
101 
102  // Trace an unsigned int with the given width
103  void trace(const unsigned int& object, const std::string& name,
104  int width);
105 
106  // Trace an unsigned long with the given width
107  void trace(const unsigned long& object, const std::string& name,
108  int width);
109 
110  // Trace a signed char with the given width
111  void trace(const char& object, const std::string& name, int width);
112 
113  // Trace a signed short with the given width
114  void trace(const short& object, const std::string& name, int width);
115 
116  // Trace a signed int with the given width
117  void trace(const int& object, const std::string& name, int width);
118 
119  // Trace a signed long with the given width
120  void trace(const long& object, const std::string& name, int width);
121 
122  // Trace a signed long long with the given width
123  void trace(const sc_dt::int64& object, const std::string& name,
124  int width);
125 
126  // Trace an usigned long long with the given width
127  void trace(const sc_dt::uint64& object, const std::string& name,
128  int width);
129 
130  // Trace a float
131  void trace(const float& object, const std::string& name);
132 
133  // Trace a double
134  void trace(const double& object, const std::string& name);
135 
136  // Trace sc_unsigned
137  void trace (const sc_dt::sc_unsigned& object,
138  const std::string& name);
139 
140  // Trace sc_signed
141  void trace (const sc_dt::sc_signed& object,
142  const std::string& name);
143 
144  // Trace sc_uint_base
145  void trace (const sc_dt::sc_uint_base& object,
146  const std::string& name);
147 
148  // Trace sc_int_base
149  void trace (const sc_dt::sc_int_base& object, const std::string& name);
150 
151  // Trace sc_fxval
152  void trace( const sc_dt::sc_fxval& object, const std::string& name );
153 
154  // Trace sc_fxval_fast
155  void trace( const sc_dt::sc_fxval_fast& object,
156  const std::string& name );
157 
158  // Trace sc_fxnum
159  void trace( const sc_dt::sc_fxnum& object, const std::string& name );
160 
161  // Trace sc_fxnum_fast
162  void trace( const sc_dt::sc_fxnum_fast& object,
163  const std::string& name );
164 
165  template<class T>
166  void traceT(const T& object, const std::string& name, wif_enum type)
167  {
168  if( add_trace_check(name) )
169  traces.push_back( new wif_T_trace<T>( object, name
170  , obtain_name(),type ) );
171  }
172 
173  // Trace sc_bv_base (sc_bv)
174  virtual void trace( const sc_dt::sc_bv_base& object,
175  const std::string& name );
176 
177  // Trace sc_lv_base (sc_lv)
178  virtual void trace( const sc_dt::sc_lv_base& object,
179  const std::string& name );
180 
181  // Trace an enumerated object - where possible output the enumeration literals
182  // in the trace file. Enum literals is a null terminated array of null
183  // terminated char* literal strings.
184  void trace(const unsigned& object, const std::string& name,
185  const char** enum_literals);
186 
187  // Output a comment to the trace file
188  void write_comment(const std::string& comment);
189 
190  // Write trace info for cycle.
191  void cycle(bool delta_cycle);
192 
193 private:
194 
195 #if SC_TRACING_PHASE_CALLBACKS_
196  // avoid hidden overload warnings
197  virtual void trace( sc_trace_file* ) const { sc_assert(false); }
198 #endif // SC_TRACING_PHASE_CALLBACKS_
199 
200  // Initialize the tracing mechanism
201  virtual void do_initialize();
202 
203  unsigned wif_name_index; // Number of variables traced
204 
205  unsigned previous_time_units_low; // Previous time as 64 bit integer
206  unsigned previous_time_units_high;
207  double previous_time; // Previous time as a double
208 
209 public:
210  // Create wif names for each variable
211  std::string obtain_name();
212 
213  // Array to store the variables traced
214  std::vector<wif_trace*> traces;
215 };
216 
217 } // namespace sc_core
218 
219 #endif // SC_WIF_TRACE_H
220 // Taf!
#define sc_assert(expr)
Definition: sc_report.h:235
uint64_t uint64
Definition: sc_nbdefs.h:183
int64_t int64
Definition: sc_nbdefs.h:182
void traceT(const T &object, const std::string &name, wif_enum type)
Definition: sc_wif_trace.h:166
void write_comment(const std::string &comment)
wif_trace_file(const char *name)
std::vector< wif_trace * > traces
Definition: sc_wif_trace.h:214
bool add_trace_check(const std::string &name) const
std::string obtain_name()
void trace(const bool &object, const std::string &name)
void cycle(bool delta_cycle)