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
52#include "sysc/tracing/sc_trace_file_base.h"
53
54namespace sc_core {
55
56class vcd_trace;  // defined in vcd_trace.cpp
57template<class T> class vcd_T_trace;
58
59
60// ----------------------------------------------------------------------------
61//  CLASS : vcd_trace_file
62//
63//  ...
64// ----------------------------------------------------------------------------
65
66class vcd_trace_file
67  : public sc_trace_file_base
68{
69public:
70
71    enum vcd_enum {VCD_WIRE=0, VCD_REAL=1, VCD_LAST};
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.
84    ~vcd_trace_file();
85
86protected:
87
88    // These are all virtual functions in sc_trace_file and
89    // they need to be defined here.
90
91    // Trace a boolean object (single bit)
92     void trace(const bool& object, const std::string& name);
93
94    // Trace a sc_bit object (single bit)
95    virtual void trace( const sc_dt::sc_bit& object,
96	    const std::string& name);
97
98    // Trace a sc_logic object (single bit)
99     void trace(const sc_dt::sc_logic& object, const std::string& name);
100
101    // Trace an unsigned char with the given width
102     void trace(const unsigned char& object, const std::string& name,
103     	int width);
104
105    // Trace an unsigned short with the given width
106     void trace(const unsigned short& object, const std::string& name,
107     	int width);
108
109    // Trace an unsigned int with the given width
110     void trace(const unsigned int& object, const std::string& name,
111     	int width);
112
113    // Trace an unsigned long with the given width
114     void trace(const unsigned long& object, const std::string& name,
115     	int width);
116
117    // Trace a signed char with the given width
118     void trace(const char& object, const std::string& name, int width);
119
120    // Trace a signed short with the given width
121     void trace(const short& object, const std::string& name, int width);
122
123    // Trace a signed int with the given width
124     void trace(const int& object, const std::string& name, int width);
125
126    // Trace a signed long with the given width
127     void trace(const long& object, const std::string& name, int width);
128
129    // Trace an int64 with a given width
130     void trace(const sc_dt::int64& object, const std::string& name,
131         int width);
132
133    // Trace a uint64 with a given width
134     void trace(const sc_dt::uint64& object, const std::string& name,
135         int width);
136
137    // Trace a float
138     void trace(const float& object, const std::string& name);
139
140    // Trace a double
141     void trace(const double& object, const std::string& name);
142
143    // Trace sc_dt::sc_uint_base
144     void trace (const sc_dt::sc_uint_base& object,
145	 	const std::string& name);
146
147    // Trace sc_dt::sc_int_base
148     void trace (const sc_dt::sc_int_base& object,
149	 	const std::string& name);
150
151    // Trace sc_dt::sc_unsigned
152     void trace (const sc_dt::sc_unsigned& object,
153	 	const std::string& name);
154
155    // Trace sc_dt::sc_signed
156     void trace (const sc_dt::sc_signed& object, const std::string& name);
157
158    // Trace sc_dt::sc_fxval
159    void trace( const sc_dt::sc_fxval& object, const std::string& name );
160
161    // Trace sc_dt::sc_fxval_fast
162    void trace( const sc_dt::sc_fxval_fast& object,
163		const std::string& name );
164
165    // Trace sc_dt::sc_fxnum
166    void trace( const sc_dt::sc_fxnum& object, const std::string& name );
167
168    // Trace sc_dt::sc_fxnum_fast
169    void trace( const sc_dt::sc_fxnum_fast& object,
170		const std::string& name );
171
172    template<class T>
173    void traceT(const T& object, const std::string& name,
174    	vcd_enum type=VCD_WIRE)
175    {
176        if( add_trace_check(name) )
177            traces.push_back(new vcd_T_trace<T>( object, name
178                                               , obtain_name(),type) );
179    }
180
181   // Trace sc_dt::sc_bv_base (sc_dt::sc_bv)
182    virtual void trace(const sc_dt::sc_bv_base& object,
183		const std::string& name);
184
185    // Trace sc_dt::sc_lv_base (sc_dt::sc_lv)
186    virtual void trace(const sc_dt::sc_lv_base& object,
187	    const std::string& name);
188    // Trace an enumerated object - where possible output the enumeration literals
189    // in the trace file. Enum literals is a null terminated array of null
190    // terminated char* literal strings.
191     void trace(const unsigned& object, const std::string& name,
192     	const char** enum_literals);
193
194    // Output a comment to the trace file
195     void write_comment(const std::string& comment);
196
197    // Write trace info for cycle.
198     void cycle(bool delta_cycle);
199
200private:
201
202#if SC_TRACING_PHASE_CALLBACKS_
203    // avoid hidden overload warnings
204    virtual void trace( sc_trace_file* ) const { sc_assert(false); }
205#endif // SC_TRACING_PHASE_CALLBACKS_
206
207    // Initialize the VCD tracing
208    virtual void do_initialize();
209
210    unsigned vcd_name_index;           // Number of variables traced
211
212    unsigned previous_time_units_low;  // Previous time unit as 64-bit integer
213    unsigned previous_time_units_high;
214
215public:
216
217    // Array to store the variables traced
218    std::vector<vcd_trace*> traces;
219
220    // Create VCD names for each variable
221    std::string obtain_name();
222
223};
224
225} // namespace sc_core
226
227#endif // SC_VCD_TRACE_H
228// Taf!
229