gem5  v20.1.0.0
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 "systemc/core/event.hh"
40 
41 class OutputStream;
42 
43 namespace sc_gem5
44 {
45 
47 {
48  protected:
49  int _width;
50 
51  public:
53  virtual ~TraceValBase() {}
54 
55  int width() { return _width; }
56 
57  virtual void finalize() {};
58  virtual bool check() = 0;
59 };
60 
61 template <typename T, typename Base=TraceValBase>
62 class TraceVal : public Base
63 {
64  private:
65  const T *t;
66  T oldVal;
67 
68  public:
69  TraceVal(const T *_t, int _width) : Base(_width), t(_t), oldVal(*t)
70  {}
71  ~TraceVal() {}
72 
73  void finalize() override { oldVal = *t; }
74  const T &value() { return oldVal; }
75 
76  bool
77  check() override
78  {
79  bool changed = (*t != oldVal);
80  oldVal = *t;
81  return changed;
82  }
83 };
84 
85 template <typename T, typename Base>
86 class TraceVal<::sc_core::sc_signal_in_if<T>, Base> : public Base
87 {
88  private:
89  const ::sc_core::sc_signal_in_if<T> *iface;
90  T oldVal;
91 
92  public:
93  TraceVal(const ::sc_core::sc_signal_in_if<T> *_iface, int _width) :
94  Base(_width), iface(_iface), oldVal(iface->read())
95  {}
96  ~TraceVal() {}
97 
98  void finalize() override { oldVal = iface->read(); }
99  const T &value() { return oldVal; }
100 
101  bool
102  check() override
103  {
104  T newVal = iface->read();
105  bool changed = (newVal != oldVal);
106  oldVal = newVal;
107  return changed;
108  }
109 };
110 
111 template <typename Base>
112 class TraceVal<::sc_core::sc_event, Base> : public Base
113 {
114  private:
115  bool triggered;
116  uint64_t oldStamp;
117  const Event *event;
118 
119  public:
120  TraceVal(const ::sc_core::sc_event *_event, int _width) :
121  Base(_width), triggered(false), oldStamp(0),
122  event(Event::getFromScEvent(_event))
123  {}
125 
126  bool value() { return triggered; }
127  void finalize() override { oldStamp = event->triggeredStamp(); }
128 
129  bool
130  check() override
131  {
132  uint64_t newStamp = event->triggeredStamp();
133  triggered = (oldStamp != newStamp);
134  oldStamp = newStamp;
135  return triggered;
136  }
137 };
138 
139 template <typename T, typename Base>
140 class TraceValFxnumBase : public Base
141 {
142  private:
143  const T *t;
145 
146  public:
147  TraceValFxnumBase(const T *_t, int _width) :
148  Base(_width), t(_t),
149  oldVal(_t->m_params.type_params(), _t->m_params.enc(),
150  _t->m_params.cast_switch(), 0)
151  {}
153 
154  void
155  finalize() override
156  {
157  oldVal = *t;
158  this->_width = t->wl();
159  }
160 
161  const T &value() { return oldVal; }
162 
163  bool
164  check() override
165  {
166  bool changed = (*t != oldVal);
167  oldVal = *t;
168  return changed;
169  }
170 };
171 
172 template <typename Base>
173 class TraceVal<::sc_dt::sc_fxnum, Base> :
174  public TraceValFxnumBase<::sc_dt::sc_fxnum, Base>
175 {
176  public:
179 };
180 
181 template <typename Base>
183  public TraceValFxnumBase<::sc_dt::sc_fxnum_fast, Base>
184 {
185  public:
188 };
189 
191 {
192  protected:
194  uint64_t timeUnitTicks;
197 
199 
200  TraceFile(const std::string &name);
201 
202  std::ostream &stream();
203 
204  public:
205  ~TraceFile();
206 
207  void traceDeltas(bool on) { _traceDeltas = on; }
208 
209  void set_time_unit(double, ::sc_core::sc_time_unit) override;
210  void finalizeTime();
211 
212  virtual void trace(bool delta) = 0;
213 
214  virtual void addTraceVal(const bool *v, const std::string &name) = 0;
215  virtual void addTraceVal(const float *v, const std::string &name) = 0;
216  virtual void addTraceVal(const double *v, const std::string &name) = 0;
217 
218  virtual void addTraceVal(const sc_dt::sc_logic *v,
219  const std::string &name) = 0;
220  virtual void addTraceVal(const sc_dt::sc_int_base *v,
221  const std::string &name) = 0;
222  virtual void addTraceVal(const sc_dt::sc_uint_base *v,
223  const std::string &name) = 0;
224  virtual void addTraceVal(const sc_dt::sc_signed *v,
225  const std::string &name) = 0;
226  virtual void addTraceVal(const sc_dt::sc_unsigned *v,
227  const std::string &name) = 0;
228  virtual void addTraceVal(const sc_dt::sc_bv_base *v,
229  const std::string &name) = 0;
230  virtual void addTraceVal(const sc_dt::sc_lv_base *v,
231  const std::string &name) = 0;
232  virtual void addTraceVal(const sc_dt::sc_fxval *v,
233  const std::string &name) = 0;
234  virtual void addTraceVal(const sc_dt::sc_fxval_fast *v,
235  const std::string &name) = 0;
236  virtual void addTraceVal(const sc_dt::sc_fxnum *v,
237  const std::string &name) = 0;
238  virtual void addTraceVal(const sc_dt::sc_fxnum_fast *v,
239  const std::string &name) = 0;
240 
241  virtual void addTraceVal(const sc_core::sc_event *v,
242  const std::string &name) = 0;
243  virtual void addTraceVal(const sc_core::sc_time *v,
244  const std::string &name) = 0;
245 
246  virtual void addTraceVal(const unsigned char *v,
247  const std::string &name, int width) = 0;
248  virtual void addTraceVal(const char *v, const std::string &name,
249  int width) = 0;
250  virtual void addTraceVal(const unsigned short *v,
251  const std::string &name, int width) = 0;
252  virtual void addTraceVal(const short *v, const std::string &name,
253  int width) = 0;
254  virtual void addTraceVal(const unsigned int *v,
255  const std::string &name, int width) = 0;
256  virtual void addTraceVal(const int *v, const std::string &name,
257  int width) = 0;
258  virtual void addTraceVal(const unsigned long *v,
259  const std::string &name, int width) = 0;
260  virtual void addTraceVal(const long *v, const std::string &name,
261  int width) = 0;
262 
263  virtual void addTraceVal(const sc_dt::int64 *v,
264  const std::string &name, int width) = 0;
265  virtual void addTraceVal(const sc_dt::uint64 *v,
266  const std::string &name, int width) = 0;
267 
268  virtual void addTraceVal(const unsigned int *,
269  const std::string &name,
270  const char **literals) = 0;
271 
272  virtual void writeComment(const std::string &comment) = 0;
273 };
274 
275 } // namespace sc_gem5
276 
277 #endif // __SYSTEMC_UTILS_TRACEFILE_HH__
sc_gem5::TraceValBase
Definition: tracefile.hh:46
sc_fxnum.hh
sc_gem5::TraceFile::addTraceVal
virtual void addTraceVal(const bool *v, const std::string &name)=0
sc_gem5::TraceValFxnumBase
Definition: sc_fxnum.hh:105
sc_gem5::TraceFile::finalizeTime
void finalizeTime()
Definition: tracefile.cc:75
sc_gem5::TraceVal::value
const T & value()
Definition: tracefile.hh:74
sc_core::sc_time_unit
sc_time_unit
Definition: sc_time.hh:40
sc_gem5::TraceFile::traceDeltas
void traceDeltas(bool on)
Definition: tracefile.hh:207
ArmISA::width
Bitfield< 4 > width
Definition: miscregs_types.hh:68
sc_dt::sc_fxnum_fast
Definition: sc_fxnum.hh:844
sc_dt::sc_fxval
Definition: sc_fxval.hh:86
sc_gem5::Event
Definition: event.hh:58
sc_dt::sc_bv_base
Definition: sc_bv_base.hh:105
sc_gem5::TraceVal<::sc_core::sc_event, Base >::finalize
void finalize() override
Definition: tracefile.hh:127
sc_gem5::TraceVal<::sc_core::sc_event, Base >::triggered
bool triggered
Definition: tracefile.hh:115
sc_dt::sc_int_base
Definition: sc_int_base.hh:494
sc_core::sc_trace_file
Definition: sc_trace_file.hh:61
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::value
const T & value()
Definition: tracefile.hh:99
sc_gem5::TraceValBase::~TraceValBase
virtual ~TraceValBase()
Definition: tracefile.hh:53
sc_gem5::TraceValBase::finalize
virtual void finalize()
Definition: tracefile.hh:57
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::iface
const ::sc_core::sc_signal_in_if< T > * iface
Definition: tracefile.hh:89
sc_dt::sc_signed
Definition: sc_signed.hh:984
sc_dt::sc_logic
Definition: sc_logic.hh:130
sc_gem5::TraceValBase::check
virtual bool check()=0
sc_gem5::TraceFile::~TraceFile
~TraceFile()
Definition: tracefile.cc:48
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::TraceVal
TraceVal(const ::sc_core::sc_signal_in_if< T > *_iface, int _width)
Definition: tracefile.hh:93
sc_gem5::TraceFile::timeUnitTicks
uint64_t timeUnitTicks
Definition: tracefile.hh:194
sc_event.hh
sc_gem5::TraceValBase::width
int width()
Definition: tracefile.hh:55
sc_gem5::TraceFile::trace
virtual void trace(bool delta)=0
sc_gem5::TraceVal::TraceVal
TraceVal(const T *_t, int _width)
Definition: tracefile.hh:69
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
sc_core::sc_event
Definition: sc_event.hh:169
sc_gem5::TraceFile::_traceDeltas
bool _traceDeltas
Definition: tracefile.hh:198
MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:297
sc_gem5::TraceFile::TraceFile
TraceFile(const std::string &name)
Definition: tracefile.cc:43
sc_core::sc_time
Definition: sc_time.hh:49
sc_dt::sc_fxnum
Definition: sc_fxnum.hh:483
sc_signal_in_if.hh
sc_gem5::TraceValFxnumBase::value
const T & value()
Definition: tracefile.hh:161
sc_gem5::TraceFile
Definition: tracefile.hh:190
sc_core::sc_signal_in_if
Definition: sc_signal_in_if.hh:53
sc_gem5::TraceVal::finalize
void finalize() override
Definition: tracefile.hh:73
sc_gem5::TraceFile::_os
OutputStream * _os
Definition: tracefile.hh:193
sc_gem5::TraceVal<::sc_core::sc_event, Base >::oldStamp
uint64_t oldStamp
Definition: tracefile.hh:116
sc_gem5::TraceValBase::TraceValBase
TraceValBase(int _width)
Definition: tracefile.hh:52
sc_dt::int64
int64_t int64
Definition: sc_nbdefs.hh:205
sc_gem5::TraceValFxnumBase::~TraceValFxnumBase
~TraceValFxnumBase()
Definition: tracefile.hh:152
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::~TraceVal
~TraceVal()
Definition: tracefile.hh:96
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::oldVal
T oldVal
Definition: tracefile.hh:90
sc_gem5::TraceVal<::sc_core::sc_event, Base >::check
bool check() override
Definition: tracefile.hh:130
sc_gem5::TraceValFxnumBase::check
bool check() override
Definition: tracefile.hh:164
name
const std::string & name()
Definition: trace.cc:50
sc_dt::sc_uint_base
Definition: sc_uint_base.hh:465
sc_gem5::TraceVal<::sc_core::sc_event, Base >::value
bool value()
Definition: tracefile.hh:126
sc_gem5::TraceFile::writeComment
virtual void writeComment(const std::string &comment)=0
sc_gem5::TraceValFxnumBase::TraceValFxnumBase
TraceValFxnumBase(const T *_t, int _width)
Definition: tracefile.hh:147
sc_gem5::TraceVal<::sc_dt::sc_fxnum_fast, Base >::~TraceVal
~TraceVal()
Definition: tracefile.hh:187
sc_gem5::TraceVal<::sc_dt::sc_fxnum, Base >::~TraceVal
~TraceVal()
Definition: tracefile.hh:178
sc_dt::sc_lv_base
Definition: sc_lv_base.hh:118
sc_gem5::TraceValFxnumBase::finalize
void finalize() override
Definition: tracefile.hh:155
sc_gem5::TraceFile::stream
std::ostream & stream()
Definition: tracefile.cc:53
sc_dt::sc_fxval_fast
Definition: sc_fxval.hh:376
sc_gem5::TraceVal<::sc_core::sc_event, Base >::event
const Event * event
Definition: tracefile.hh:117
sc_gem5::TraceVal::check
bool check() override
Definition: tracefile.hh:77
OutputStream
Definition: output.hh:53
sc_gem5::TraceValFxnumBase::t
const T * t
Definition: tracefile.hh:143
sc_dt::sc_unsigned
Definition: sc_unsigned.hh:890
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::finalize
void finalize() override
Definition: tracefile.hh:98
sc_gem5::TraceFile::set_time_unit
void set_time_unit(double, ::sc_core::sc_time_unit) override
Definition: tracefile.cc:56
sc_gem5::TraceVal<::sc_core::sc_event, Base >::~TraceVal
~TraceVal()
Definition: tracefile.hh:124
sc_gem5::TraceVal::t
const T * t
Definition: tracefile.hh:65
sc_gem5
Definition: sc_clock.cc:42
sc_gem5::TraceVal::oldVal
T oldVal
Definition: tracefile.hh:66
event.hh
sc_gem5::TraceVal::~TraceVal
~TraceVal()
Definition: tracefile.hh:71
sc_gem5::TraceVal
Definition: tracefile.hh:62
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::check
bool check() override
Definition: tracefile.hh:102
sc_trace_file.hh
sc_gem5::TraceValFxnumBase::oldVal
T oldVal
Definition: tracefile.hh:144
MipsISA::on
Bitfield< 0 > on
Definition: dt_constants.hh:87
sc_gem5::TraceValBase::_width
int _width
Definition: tracefile.hh:49
sc_gem5::TraceFile::timeUnitValue
double timeUnitValue
Definition: tracefile.hh:195
ArmISA::v
Bitfield< 28 > v
Definition: miscregs_types.hh:51
sc_gem5::TraceVal<::sc_core::sc_event, Base >::TraceVal
TraceVal(const ::sc_core::sc_event *_event, int _width)
Definition: tracefile.hh:120
sc_gem5::TraceFile::timeUnitUnit
::sc_core::sc_time_unit timeUnitUnit
Definition: tracefile.hh:196

Generated on Wed Sep 30 2020 14:02:18 for gem5 by doxygen 1.8.17