gem5 v24.0.0.0
Loading...
Searching...
No Matches
tracefile.hh
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef __SYSTEMC_UTILS_TRACEFILE_HH__
29#define __SYSTEMC_UTILS_TRACEFILE_HH__
30
31#include <iostream>
32#include <string>
33#include <vector>
34
35#include "base/output.hh"
36#include "systemc/core/event.hh"
41
42class OutputStream;
43
44namespace sc_gem5
45{
46
48{
49 protected:
50 int _width;
51
52 public:
54 virtual ~TraceValBase() {}
55
56 int width() { return _width; }
57
58 virtual void finalize() {};
59 virtual bool check() = 0;
60};
61
62template <typename T, typename Base=TraceValBase>
63class TraceVal : public Base
64{
65 private:
66 const T *t;
68
69 public:
70 TraceVal(const T *_t, int _width) : Base(_width), t(_t), oldVal(*t)
71 {}
73
74 void finalize() override { oldVal = *t; }
75 const T &value() { return oldVal; }
76
77 bool
78 check() override
79 {
80 bool changed = (*t != oldVal);
81 oldVal = *t;
82 return changed;
83 }
84};
85
86template <typename T, typename Base>
87class TraceVal<::sc_core::sc_signal_in_if<T>, Base> : public Base
88{
89 private:
90 const ::sc_core::sc_signal_in_if<T> *iface;
92
93 public:
94 TraceVal(const ::sc_core::sc_signal_in_if<T> *_iface, int _width) :
95 Base(_width), iface(_iface), oldVal(iface->read())
96 {}
98
99 void finalize() override { oldVal = iface->read(); }
100 const T &value() { return oldVal; }
101
102 bool
103 check() override
104 {
105 T newVal = iface->read();
106 bool changed = (newVal != oldVal);
107 oldVal = newVal;
108 return changed;
109 }
110};
111
112template <typename Base>
113class TraceVal<::sc_core::sc_event, Base> : public Base
114{
115 private:
117 uint64_t oldStamp;
118 const Event *event;
119
120 public:
121 TraceVal(const ::sc_core::sc_event *_event, int _width) :
122 Base(_width), triggered(false), oldStamp(0),
123 event(Event::getFromScEvent(_event))
124 {}
126
127 bool value() { return triggered; }
128 void finalize() override { oldStamp = event->triggeredStamp(); }
129
130 bool
131 check() override
132 {
133 uint64_t newStamp = event->triggeredStamp();
134 triggered = (oldStamp != newStamp);
135 oldStamp = newStamp;
136 return triggered;
137 }
138};
139
140template <typename T, typename Base>
141class TraceValFxnumBase : public Base
142{
143 private:
144 const T *t;
146
147 public:
148 TraceValFxnumBase(const T *_t, int _width) :
149 Base(_width), t(_t),
150 oldVal(_t->m_params.type_params(), _t->m_params.enc(),
151 _t->m_params.cast_switch(), 0)
152 {}
154
155 void
156 finalize() override
157 {
158 oldVal = *t;
159 this->_width = t->wl();
160 }
161
162 const T &value() { return oldVal; }
163
164 bool
165 check() override
166 {
167 bool changed = (*t != oldVal);
168 oldVal = *t;
169 return changed;
170 }
171};
172
173template <typename Base>
174class TraceVal<::sc_dt::sc_fxnum, Base> :
175 public TraceValFxnumBase<::sc_dt::sc_fxnum, Base>
176{
177 public:
178 using TraceValFxnumBase<::sc_dt::sc_fxnum, Base>::TraceValFxnumBase;
180};
181
182template <typename Base>
184 public TraceValFxnumBase<::sc_dt::sc_fxnum_fast, Base>
185{
186 public:
187 using TraceValFxnumBase<::sc_dt::sc_fxnum_fast, Base>::TraceValFxnumBase;
189};
190
192{
193 protected:
198
200
201 TraceFile(const std::string &name);
202
203 std::ostream &stream();
204
205 public:
206 ~TraceFile();
207
208 void traceDeltas(bool on) { _traceDeltas = on; }
209
210 void set_time_unit(double, ::sc_core::sc_time_unit) override;
211 void finalizeTime();
212
213 virtual void trace(bool delta) = 0;
214
215 virtual void addTraceVal(const bool *v, const std::string &name) = 0;
216 virtual void addTraceVal(const float *v, const std::string &name) = 0;
217 virtual void addTraceVal(const double *v, const std::string &name) = 0;
218
219 virtual void addTraceVal(const sc_dt::sc_logic *v,
220 const std::string &name) = 0;
221 virtual void addTraceVal(const sc_dt::sc_int_base *v,
222 const std::string &name) = 0;
223 virtual void addTraceVal(const sc_dt::sc_uint_base *v,
224 const std::string &name) = 0;
225 virtual void addTraceVal(const sc_dt::sc_signed *v,
226 const std::string &name) = 0;
227 virtual void addTraceVal(const sc_dt::sc_unsigned *v,
228 const std::string &name) = 0;
229 virtual void addTraceVal(const sc_dt::sc_bv_base *v,
230 const std::string &name) = 0;
231 virtual void addTraceVal(const sc_dt::sc_lv_base *v,
232 const std::string &name) = 0;
233 virtual void addTraceVal(const sc_dt::sc_fxval *v,
234 const std::string &name) = 0;
235 virtual void addTraceVal(const sc_dt::sc_fxval_fast *v,
236 const std::string &name) = 0;
237 virtual void addTraceVal(const sc_dt::sc_fxnum *v,
238 const std::string &name) = 0;
239 virtual void addTraceVal(const sc_dt::sc_fxnum_fast *v,
240 const std::string &name) = 0;
241
242 virtual void addTraceVal(const sc_core::sc_event *v,
243 const std::string &name) = 0;
244 virtual void addTraceVal(const sc_core::sc_time *v,
245 const std::string &name) = 0;
246
247 virtual void addTraceVal(const unsigned char *v,
248 const std::string &name, int width) = 0;
249 virtual void addTraceVal(const char *v, const std::string &name,
250 int width) = 0;
251 virtual void addTraceVal(const unsigned short *v,
252 const std::string &name, int width) = 0;
253 virtual void addTraceVal(const short *v, const std::string &name,
254 int width) = 0;
255 virtual void addTraceVal(const unsigned int *v,
256 const std::string &name, int width) = 0;
257 virtual void addTraceVal(const int *v, const std::string &name,
258 int width) = 0;
259 virtual void addTraceVal(const unsigned long *v,
260 const std::string &name, int width) = 0;
261 virtual void addTraceVal(const long *v, const std::string &name,
262 int width) = 0;
263
264 virtual void addTraceVal(const sc_dt::int64 *v,
265 const std::string &name, int width) = 0;
266 virtual void addTraceVal(const sc_dt::uint64 *v,
267 const std::string &name, int width) = 0;
268
269 virtual void addTraceVal(const unsigned int *,
270 const std::string &name,
271 const char **literals) = 0;
272
273 virtual void writeComment(const std::string &comment) = 0;
274};
275
276} // namespace sc_gem5
277
278#endif // __SYSTEMC_UTILS_TRACEFILE_HH__
virtual void addTraceVal(const unsigned int *, const std::string &name, const char **literals)=0
virtual void addTraceVal(const sc_dt::sc_fxnum *v, const std::string &name)=0
virtual void addTraceVal(const sc_dt::sc_lv_base *v, const std::string &name)=0
virtual void addTraceVal(const sc_dt::sc_int_base *v, const std::string &name)=0
virtual void addTraceVal(const sc_dt::sc_signed *v, const std::string &name)=0
virtual void addTraceVal(const sc_dt::sc_bv_base *v, const std::string &name)=0
virtual void addTraceVal(const bool *v, const std::string &name)=0
virtual void addTraceVal(const char *v, const std::string &name, int width)=0
virtual void addTraceVal(const sc_core::sc_time *v, const std::string &name)=0
virtual void writeComment(const std::string &comment)=0
virtual void addTraceVal(const short *v, const std::string &name, int width)=0
virtual void addTraceVal(const sc_dt::sc_logic *v, const std::string &name)=0
::sc_core::sc_time_unit timeUnitUnit
Definition tracefile.hh:197
virtual void addTraceVal(const sc_dt::uint64 *v, const std::string &name, int width)=0
virtual void addTraceVal(const sc_dt::int64 *v, const std::string &name, int width)=0
gem5::OutputStream * _os
Definition tracefile.hh:194
virtual void addTraceVal(const long *v, const std::string &name, int width)=0
virtual void addTraceVal(const float *v, const std::string &name)=0
virtual void addTraceVal(const double *v, const std::string &name)=0
uint64_t timeUnitTicks
Definition tracefile.hh:195
virtual void addTraceVal(const sc_dt::sc_uint_base *v, const std::string &name)=0
virtual void addTraceVal(const sc_dt::sc_unsigned *v, const std::string &name)=0
virtual void addTraceVal(const unsigned long *v, const std::string &name, int width)=0
virtual void addTraceVal(const unsigned short *v, const std::string &name, int width)=0
virtual void addTraceVal(const sc_core::sc_event *v, const std::string &name)=0
TraceFile(const std::string &name)
Definition tracefile.cc:42
void set_time_unit(double, ::sc_core::sc_time_unit) override
Definition tracefile.cc:58
virtual void trace(bool delta)=0
virtual void addTraceVal(const unsigned int *v, const std::string &name, int width)=0
virtual void addTraceVal(const int *v, const std::string &name, int width)=0
std::ostream & stream()
Definition tracefile.cc:55
virtual void addTraceVal(const unsigned char *v, const std::string &name, int width)=0
virtual void addTraceVal(const sc_dt::sc_fxnum_fast *v, const std::string &name)=0
virtual void addTraceVal(const sc_dt::sc_fxval *v, const std::string &name)=0
virtual void addTraceVal(const sc_dt::sc_fxval_fast *v, const std::string &name)=0
void traceDeltas(bool on)
Definition tracefile.hh:208
TraceValBase(int _width)
Definition tracefile.hh:53
virtual void finalize()
Definition tracefile.hh:58
virtual bool check()=0
virtual ~TraceValBase()
Definition tracefile.hh:54
void finalize() override
Definition tracefile.hh:156
TraceValFxnumBase(const T *_t, int _width)
Definition tracefile.hh:148
TraceVal(const ::sc_core::sc_event *_event, int _width)
Definition tracefile.hh:121
TraceVal(const ::sc_core::sc_signal_in_if< T > *_iface, int _width)
Definition tracefile.hh:94
const ::sc_core::sc_signal_in_if< T > * iface
Definition tracefile.hh:90
bool check() override
Definition tracefile.hh:78
void finalize() override
Definition tracefile.hh:74
const T & value()
Definition tracefile.hh:75
TraceVal(const T *_t, int _width)
Definition tracefile.hh:70
sc_time_unit
Definition sc_time.hh:40
uint64_t uint64
Definition sc_nbdefs.hh:172
int64_t int64
Definition sc_nbdefs.hh:171
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:07 for gem5 by doxygen 1.11.0