From 3d29513196e7d59e1b8f9da120089bac17e8771d Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 20 Sep 2018 02:57:54 -0700 Subject: systemc: Implement general and VCD trace support. This doesn't include WIF trace support, but does make allowances for adding it in the future. Change-Id: Ifb62f40a7d8a13e94463930a44ac4b1cf41e3009 Reviewed-on: https://gem5-review.googlesource.com/c/12826 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/systemc/ext/channel/sc_in.hh | 77 +++++++++++++++++++++++++++++----- src/systemc/ext/channel/sc_inout.hh | 64 ++++++++++++++++++++++++---- src/systemc/ext/channel/sc_signal.hh | 16 ------- src/systemc/ext/core/sc_port.hh | 16 +++++++ src/systemc/ext/dt/fx/sc_fxnum.hh | 16 ++++--- src/systemc/ext/utils/sc_trace_file.hh | 5 +++ 6 files changed, 150 insertions(+), 44 deletions(-) (limited to 'src/systemc/ext') diff --git a/src/systemc/ext/channel/sc_in.hh b/src/systemc/ext/channel/sc_in.hh index b7170aed3..a76840161 100644 --- a/src/systemc/ext/channel/sc_in.hh +++ b/src/systemc/ext/channel/sc_in.hh @@ -34,9 +34,9 @@ #include "../core/sc_event.hh" #include "../core/sc_port.hh" +#include "../utils/sc_trace_file.hh" #include "sc_signal_in_if.hh" #include "sc_signal_inout_if.hh" -#include "warn_unimpl.hh" namespace sc_core { @@ -112,7 +112,14 @@ class sc_in : public sc_port, 1> bind(p); } - virtual void end_of_elaboration() { /* Implementation defined. */ } + virtual void + end_of_elaboration() + { + for (auto params: traceParamsVec) + sc_trace(params->tf, (*this)->read(), params->name); + + traceParamsVec.clear(); + } const T &read() const { return (*this)->read(); } operator const T& () const { return (*this)->read(); } @@ -128,9 +135,17 @@ class sc_in : public sc_port, 1> virtual const char *kind() const { return "sc_in"; } + void + add_trace(sc_trace_file *tf, const std::string &name) const + { + traceParamsVec.push_back(new sc_trace_params(tf, name)); + } + private: mutable sc_event_finder_t > _valueChangedFinder; + mutable sc_trace_params_vec traceParamsVec; + // Disabled sc_in(const sc_in &); sc_in &operator = (const sc_in &); @@ -138,9 +153,12 @@ class sc_in : public sc_port, 1> template inline void -sc_trace(sc_trace_file *, const sc_in &, const std::string &) +sc_trace(sc_trace_file *tf, const sc_in &i, const std::string &name) { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + if (i.size()) + sc_trace(tf, i->read(), name); + else + i.add_trace(tf, name); } template <> @@ -236,7 +254,14 @@ class sc_in : public sc_port, 1> bind(p); } - virtual void end_of_elaboration() { /* Implementation defined. */ } + virtual void + end_of_elaboration() + { + for (auto params: traceParamsVec) + sc_trace(params->tf, (*this)->read(), params->name); + + traceParamsVec.clear(); + } const bool &read() const { return (*this)->read(); } operator const bool& () const { return (*this)->read(); } @@ -268,11 +293,19 @@ class sc_in : public sc_port, 1> virtual const char *kind() const { return "sc_in"; } + void + add_trace(sc_trace_file *tf, const std::string &name) const + { + traceParamsVec.push_back(new sc_trace_params(tf, name)); + } + private: mutable sc_event_finder_t > _valueChangedFinder; mutable sc_event_finder_t > _posFinder; mutable sc_event_finder_t > _negFinder; + mutable sc_trace_params_vec traceParamsVec; + // Disabled sc_in(const sc_in &); sc_in &operator = (const sc_in &); @@ -280,9 +313,13 @@ class sc_in : public sc_port, 1> template <> inline void -sc_trace(sc_trace_file *, const sc_in &, const std::string &) +sc_trace(sc_trace_file *tf, const sc_in &i, + const std::string &name) { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + if (i.size()) + sc_trace(tf, i->read(), name); + else + i.add_trace(tf, name); } template <> @@ -383,7 +420,14 @@ class sc_in : bind(p); } - virtual void end_of_elaboration() { /* Implementation defined. */ } + virtual void + end_of_elaboration() + { + for (auto params: traceParamsVec) + sc_trace(params->tf, (*this)->read(), params->name); + + traceParamsVec.clear(); + } const sc_dt::sc_logic &read() const { return (*this)->read(); } operator const sc_dt::sc_logic& () const { return (*this)->read(); } @@ -407,12 +451,20 @@ class sc_in : virtual const char *kind() const { return "sc_in"; } + void + add_trace(sc_trace_file *tf, const std::string &name) const + { + traceParamsVec.push_back(new sc_trace_params(tf, name)); + } + private: mutable sc_event_finder_t > _valueChangedFinder; mutable sc_event_finder_t > _posFinder; mutable sc_event_finder_t > _negFinder; + mutable sc_trace_params_vec traceParamsVec; + // Disabled sc_in(const sc_in &); sc_in &operator = (const sc_in &); @@ -420,10 +472,13 @@ class sc_in : template <> inline void -sc_trace( - sc_trace_file *, const sc_in &, const std::string &) +sc_trace(sc_trace_file *tf, const sc_in &i, + const std::string &name) { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + if (i.size()) + sc_trace(tf, i->read(), name); + else + i.add_trace(tf, name); } } // namespace sc_core diff --git a/src/systemc/ext/channel/sc_inout.hh b/src/systemc/ext/channel/sc_inout.hh index 54b0ae7da..7f19443d5 100644 --- a/src/systemc/ext/channel/sc_inout.hh +++ b/src/systemc/ext/channel/sc_inout.hh @@ -35,8 +35,8 @@ #include "../core/sc_event.hh" #include "../core/sc_port.hh" #include "../dt/bit/sc_logic.hh" +#include "../utils/sc_trace_file.hh" #include "sc_signal_inout_if.hh" -#include "warn_unimpl.hh" namespace sc_dt { @@ -111,6 +111,11 @@ class sc_inout : public sc_port, 1> delete initValue; initValue = nullptr; } + + for (auto params: traceParamsVec) + sc_trace(params->tf, (*this)->read(), params->name); + + traceParamsVec.clear(); } const T &read() const { return (*this)->read(); } @@ -159,19 +164,30 @@ class sc_inout : public sc_port, 1> virtual const char *kind() const { return "sc_inout"; } + void + add_trace(sc_trace_file *tf, const std::string &name) const + { + traceParamsVec.push_back(new sc_trace_params(tf, name)); + } + private: T *initValue; mutable sc_event_finder_t > _valueChangedFinder; + mutable sc_trace_params_vec traceParamsVec; + // Disabled sc_inout(const sc_inout &); }; template inline void -sc_trace(sc_trace_file *, const sc_inout &, const std::string &) +sc_trace(sc_trace_file *tf, const sc_inout &i, const std::string &name) { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + if (i.size()) + sc_trace(tf, i->read(), name); + else + i.add_trace(tf, name); } template <> @@ -259,6 +275,11 @@ class sc_inout : public sc_port, 1> delete initValue; initValue = nullptr; } + + for (auto params: traceParamsVec) + sc_trace(params->tf, (*this)->read(), params->name); + + traceParamsVec.clear(); } const bool &read() const { return (*this)->read(); } @@ -314,21 +335,32 @@ class sc_inout : public sc_port, 1> virtual const char *kind() const { return "sc_inout"; } + void + add_trace(sc_trace_file *tf, const std::string &name) const + { + traceParamsVec.push_back(new sc_trace_params(tf, name)); + } + private: bool *initValue; mutable sc_event_finder_t > _valueChangedFinder; mutable sc_event_finder_t > _posFinder; mutable sc_event_finder_t > _negFinder; + mutable sc_trace_params_vec traceParamsVec; + // Disabled sc_inout(const sc_inout &); }; template <> inline void sc_trace( - sc_trace_file *, const sc_inout &, const std::string &) + sc_trace_file *tf, const sc_inout &i, const std::string &name) { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + if (i.size()) + sc_trace(tf, i->read(), name); + else + i.add_trace(tf, name); } template <> @@ -433,6 +465,11 @@ class sc_inout : delete initValue; initValue = nullptr; } + + for (auto params: traceParamsVec) + sc_trace(params->tf, (*this)->read(), params->name); + + traceParamsVec.clear(); } const sc_dt::sc_logic &read() const { return (*this)->read(); } @@ -488,6 +525,12 @@ class sc_inout : virtual const char *kind() const { return "sc_inout"; } + void + add_trace(sc_trace_file *tf, const std::string &name) const + { + traceParamsVec.push_back(new sc_trace_params(tf, name)); + } + private: sc_dt::sc_logic *initValue; mutable sc_event_finder_t< @@ -495,16 +538,21 @@ class sc_inout : mutable sc_event_finder_t > _posFinder; mutable sc_event_finder_t > _negFinder; + mutable sc_trace_params_vec traceParamsVec; + // Disabled sc_inout(const sc_inout &); }; template <> inline void -sc_trace(sc_trace_file *, const sc_inout &, - const std::string &) +sc_trace(sc_trace_file *tf, + const sc_inout &i, const std::string &name) { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + if (i.size()) + sc_trace(tf, i->read(), name); + else + i.add_trace(tf, name); } } // namespace sc_core diff --git a/src/systemc/ext/channel/sc_signal.hh b/src/systemc/ext/channel/sc_signal.hh index bbe2d0116..7c0183763 100644 --- a/src/systemc/ext/channel/sc_signal.hh +++ b/src/systemc/ext/channel/sc_signal.hh @@ -45,22 +45,6 @@ namespace sc_core { class sc_port_base; -class sc_trace_file; - -// Nonstandard -// Despite having a warning "FOR INTERNAL USE ONLY!" in all caps above this -// class definition in the Accellera implementation, it appears in their -// examples and test programs, and so we need to have it here as well. -struct sc_trace_params -{ - sc_trace_file *tf; - std::string name; - - sc_trace_params(sc_trace_file *tf, const std::string &name) : - tf(tf), name(name) - {} -}; -typedef std::vector sc_trace_params_vec; template class sc_signal : public sc_signal_inout_if, diff --git a/src/systemc/ext/core/sc_port.hh b/src/systemc/ext/core/sc_port.hh index c9d436ec3..3586fec73 100644 --- a/src/systemc/ext/core/sc_port.hh +++ b/src/systemc/ext/core/sc_port.hh @@ -47,6 +47,22 @@ namespace sc_core { class sc_interface; +class sc_trace_file; + +// Nonstandard +// Despite having a warning "FOR INTERNAL USE ONLY!" in all caps above this +// class definition in the Accellera implementation, it appears in their +// examples and test programs, and so we need to have it here as well. +struct sc_trace_params +{ + sc_trace_file *tf; + std::string name; + + sc_trace_params(sc_trace_file *tf, const std::string &name) : + tf(tf), name(name) + {} +}; +typedef std::vector sc_trace_params_vec; enum sc_port_policy { diff --git a/src/systemc/ext/dt/fx/sc_fxnum.hh b/src/systemc/ext/dt/fx/sc_fxnum.hh index 1138646f3..8a0b7f612 100644 --- a/src/systemc/ext/dt/fx/sc_fxnum.hh +++ b/src/systemc/ext/dt/fx/sc_fxnum.hh @@ -66,13 +66,11 @@ #include "sc_fxval.hh" #include "scfx_params.hh" -namespace sc_core +namespace sc_gem5 { -class vcd_sc_fxnum_trace; -class vcd_sc_fxnum_fast_trace; -class wif_sc_fxnum_trace; -class wif_sc_fxnum_fast_trace; +template +class TraceValFxnumBase; } // namespace sc_core @@ -490,8 +488,8 @@ class sc_fxnum friend class sc_fxnum_fast_bitref; friend class sc_fxnum_fast_subref; - friend class sc_core::vcd_sc_fxnum_trace; - friend class sc_core::wif_sc_fxnum_trace; + template + friend class sc_gem5::TraceValFxnumBase; protected: sc_fxnum_observer *observer() const; @@ -851,8 +849,8 @@ class sc_fxnum_fast friend class sc_fxnum_fast_bitref; friend class sc_fxnum_fast_subref; - friend class sc_core::vcd_sc_fxnum_fast_trace; - friend class sc_core::wif_sc_fxnum_fast_trace; + template + friend class sc_gem5::TraceValFxnumBase; protected: sc_fxnum_fast_observer *observer() const; diff --git a/src/systemc/ext/utils/sc_trace_file.hh b/src/systemc/ext/utils/sc_trace_file.hh index 0b4b0d02b..09f5bb254 100644 --- a/src/systemc/ext/utils/sc_trace_file.hh +++ b/src/systemc/ext/utils/sc_trace_file.hh @@ -63,7 +63,12 @@ class sc_time; class sc_trace_file { + protected: + sc_trace_file(); + public: + virtual ~sc_trace_file(); + virtual void set_time_unit(double, sc_time_unit) = 0; }; -- cgit v1.2.3