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

Generated on Fri Feb 28 2020 16:27:06 for gem5 by doxygen 1.8.13