gem5  v21.1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
42 class OutputStream;
43 
44 namespace 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 
62 template <typename T, typename Base=TraceValBase>
63 class TraceVal : public Base
64 {
65  private:
66  const T *t;
67  T oldVal;
68 
69  public:
70  TraceVal(const T *_t, int _width) : Base(_width), t(_t), oldVal(*t)
71  {}
72  ~TraceVal() {}
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 
86 template <typename T, typename Base>
88 {
89  private:
90  const ::sc_core::sc_signal_in_if<T> *iface;
91  T oldVal;
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  {}
97  ~TraceVal() {}
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 
112 template <typename Base>
114 {
115  private:
116  bool triggered;
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 
140 template <typename T, typename Base>
141 class 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 
173 template <typename Base>
175  public TraceValFxnumBase<::sc_dt::sc_fxnum, Base>
176 {
177  public:
180 };
181 
182 template <typename Base>
184  public TraceValFxnumBase<::sc_dt::sc_fxnum_fast, Base>
185 {
186  public:
189 };
190 
192 {
193  protected:
195  uint64_t timeUnitTicks;
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__
sc_gem5::TraceValBase
Definition: tracefile.hh:47
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:73
sc_gem5::TraceVal::value
const T & value()
Definition: tracefile.hh:75
sc_core::sc_time_unit
sc_time_unit
Definition: sc_time.hh:40
sc_gem5::TraceFile::traceDeltas
void traceDeltas(bool on)
Definition: tracefile.hh:208
sc_dt::sc_fxnum_fast
Definition: sc_fxnum.hh:844
gem5::MipsISA::event
Bitfield< 10, 5 > event
Definition: pra_constants.hh:300
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:128
sc_gem5::TraceVal<::sc_core::sc_event, Base >::triggered
bool triggered
Definition: tracefile.hh:116
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:100
sc_gem5::TraceValBase::~TraceValBase
virtual ~TraceValBase()
Definition: tracefile.hh:54
sc_gem5::TraceValBase::finalize
virtual void finalize()
Definition: tracefile.hh:58
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::iface
const ::sc_core::sc_signal_in_if< T > * iface
Definition: tracefile.hh:90
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
output.hh
sc_gem5::TraceFile::~TraceFile
~TraceFile()
Definition: tracefile.cc:46
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:94
sc_gem5::TraceFile::timeUnitTicks
uint64_t timeUnitTicks
Definition: tracefile.hh:195
sc_event.hh
gem5::auxv::Base
@ Base
Definition: aux_vector.hh:76
sc_gem5::TraceValBase::width
int width()
Definition: tracefile.hh:56
sc_gem5::TraceFile::trace
virtual void trace(bool delta)=0
sc_gem5::TraceVal::TraceVal
TraceVal(const T *_t, int _width)
Definition: tracefile.hh:70
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
gem5::ArmISA::width
Bitfield< 4 > width
Definition: misc_types.hh:71
sc_core::sc_event
Definition: sc_event.hh:169
sc_gem5::TraceFile::_traceDeltas
bool _traceDeltas
Definition: tracefile.hh:199
sc_gem5::TraceFile::TraceFile
TraceFile(const std::string &name)
Definition: tracefile.cc:41
gem5::ArmISA::v
Bitfield< 28 > v
Definition: misc_types.hh:54
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:162
sc_gem5::TraceFile
Definition: tracefile.hh:191
sc_core::sc_signal_in_if
Definition: sc_signal_in_if.hh:53
sc_gem5::TraceVal::finalize
void finalize() override
Definition: tracefile.hh:74
sc_gem5::TraceVal<::sc_core::sc_event, Base >::oldStamp
uint64_t oldStamp
Definition: tracefile.hh:117
sc_gem5::TraceValBase::TraceValBase
TraceValBase(int _width)
Definition: tracefile.hh:53
gem5::MipsISA::on
Bitfield< 0 > on
Definition: dt_constants.hh:90
sc_dt::int64
int64_t int64
Definition: sc_nbdefs.hh:205
sc_gem5::TraceValFxnumBase::~TraceValFxnumBase
~TraceValFxnumBase()
Definition: tracefile.hh:153
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::~TraceVal
~TraceVal()
Definition: tracefile.hh:97
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::oldVal
T oldVal
Definition: tracefile.hh:91
sc_gem5::TraceVal<::sc_core::sc_event, Base >::check
bool check() override
Definition: tracefile.hh:131
sc_gem5::TraceValFxnumBase::check
bool check() override
Definition: tracefile.hh:165
name
const std::string & name()
Definition: trace.cc:49
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:127
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:148
sc_gem5::TraceVal<::sc_dt::sc_fxnum_fast, Base >::~TraceVal
~TraceVal()
Definition: tracefile.hh:188
sc_gem5::TraceVal<::sc_dt::sc_fxnum, Base >::~TraceVal
~TraceVal()
Definition: tracefile.hh:179
sc_dt::sc_lv_base
Definition: sc_lv_base.hh:118
sc_gem5::TraceValFxnumBase::finalize
void finalize() override
Definition: tracefile.hh:156
sc_gem5::TraceFile::stream
std::ostream & stream()
Definition: tracefile.cc:51
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:118
sc_gem5::TraceVal::check
bool check() override
Definition: tracefile.hh:78
sc_gem5::TraceValFxnumBase::t
const T * t
Definition: tracefile.hh:144
sc_gem5::TraceFile::_os
gem5::OutputStream * _os
Definition: tracefile.hh:194
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:99
sc_gem5::TraceFile::set_time_unit
void set_time_unit(double, ::sc_core::sc_time_unit) override
Definition: tracefile.cc:54
sc_gem5::TraceVal<::sc_core::sc_event, Base >::~TraceVal
~TraceVal()
Definition: tracefile.hh:125
sc_gem5::TraceVal::t
const T * t
Definition: tracefile.hh:66
sc_gem5
Definition: sc_clock.cc:41
sc_gem5::TraceVal::oldVal
T oldVal
Definition: tracefile.hh:67
event.hh
sc_gem5::TraceVal::~TraceVal
~TraceVal()
Definition: tracefile.hh:72
sc_gem5::TraceVal
Definition: tracefile.hh:63
sc_gem5::TraceVal<::sc_core::sc_signal_in_if< T >, Base >::check
bool check() override
Definition: tracefile.hh:103
sc_trace_file.hh
sc_gem5::TraceValFxnumBase::oldVal
T oldVal
Definition: tracefile.hh:145
sc_gem5::TraceValBase::_width
int _width
Definition: tracefile.hh:50
sc_gem5::TraceFile::timeUnitValue
double timeUnitValue
Definition: tracefile.hh:196
gem5::OutputStream
Definition: output.hh:56
sc_gem5::TraceVal<::sc_core::sc_event, Base >::TraceVal
TraceVal(const ::sc_core::sc_event *_event, int _width)
Definition: tracefile.hh:121
sc_gem5::TraceFile::timeUnitUnit
::sc_core::sc_time_unit timeUnitUnit
Definition: tracefile.hh:197

Generated on Wed Jul 28 2021 12:10:32 for gem5 by doxygen 1.8.17