From e16ca903f240c750f34207b4c98735f81d2312b8 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 1 Oct 2018 03:59:05 -0700 Subject: systemc: Implement register_port in all the predefined channels. Something the Accellera implementation does which would be good to do in the gem5 implementation is to create a base class for sc_signal which isn't templated, and which holds the common/non-type specific versions of the various sc_signal methods. This will reduce code redundancy and binary size, and also let us hide more code in .cc files so that it's less likely we'd need to recompile model code to fix a bug. Also, since this all uses of sc_channel_warn_unimple have now been eliminated, remove that function. Change-Id: Ia574647c034e7136093c2047b69de725ac34f52f Reviewed-on: https://gem5-review.googlesource.com/c/13200 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/systemc/channel/SConscript | 1 - src/systemc/channel/warn_unimpl.cc | 42 --------- src/systemc/ext/channel/sc_fifo.hh | 35 ++++++-- src/systemc/ext/channel/sc_signal.hh | 100 +++++++++++++++++---- src/systemc/ext/channel/sc_signal_rv.hh | 7 +- src/systemc/ext/channel/warn_unimpl.hh | 40 --------- .../check_writer/test08/expected_returncode | 1 + .../check_writer/test09/expected_returncode | 1 + .../check_writer/test10/expected_returncode | 1 + .../check_writer/test11/expected_returncode | 1 + .../check_writer/test12/expected_returncode | 1 + .../register_port/test01/expected_returncode | 1 + .../register_port/test02/expected_returncode | 1 + .../register_port/test03/expected_returncode | 1 + 14 files changed, 120 insertions(+), 113 deletions(-) delete mode 100644 src/systemc/channel/warn_unimpl.cc delete mode 100644 src/systemc/ext/channel/warn_unimpl.hh create mode 100644 src/systemc/tests/systemc/communication/sc_signal/check_writer/test08/expected_returncode create mode 100644 src/systemc/tests/systemc/communication/sc_signal/check_writer/test09/expected_returncode create mode 100644 src/systemc/tests/systemc/communication/sc_signal/check_writer/test10/expected_returncode create mode 100644 src/systemc/tests/systemc/communication/sc_signal/check_writer/test11/expected_returncode create mode 100644 src/systemc/tests/systemc/communication/sc_signal/check_writer/test12/expected_returncode create mode 100644 src/systemc/tests/systemc/communication/sc_signal/register_port/test01/expected_returncode create mode 100644 src/systemc/tests/systemc/communication/sc_signal/register_port/test02/expected_returncode create mode 100644 src/systemc/tests/systemc/communication/sc_signal/register_port/test03/expected_returncode diff --git a/src/systemc/channel/SConscript b/src/systemc/channel/SConscript index 3ca8801c8..c83c233c9 100644 --- a/src/systemc/channel/SConscript +++ b/src/systemc/channel/SConscript @@ -36,4 +36,3 @@ if env['USE_SYSTEMC']: Source('sc_mutex.cc') Source('sc_semaphore.cc') Source('sc_signal_resolved.cc') - Source('warn_unimpl.cc') diff --git a/src/systemc/channel/warn_unimpl.cc b/src/systemc/channel/warn_unimpl.cc deleted file mode 100644 index 82fd8367b..000000000 --- a/src/systemc/channel/warn_unimpl.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2018 Google, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Gabe Black - */ - -#include "base/logging.hh" -#include "systemc/ext/channel/warn_unimpl.hh" - -namespace sc_core -{ - -void -sc_channel_warn_unimpl(const char *func) -{ - warn("%s not implemented.\n", func); -} - -} // namespace sc_core diff --git a/src/systemc/ext/channel/sc_fifo.hh b/src/systemc/ext/channel/sc_fifo.hh index 7bf9efce0..02a0ddb98 100644 --- a/src/systemc/ext/channel/sc_fifo.hh +++ b/src/systemc/ext/channel/sc_fifo.hh @@ -31,12 +31,13 @@ #define __SYSTEMC_EXT_CHANNEL_SC_FIFO_HH__ #include +#include #include "../core/sc_module.hh" // for sc_gen_unique_name #include "../core/sc_prim.hh" +#include "../utils/sc_report_handler.hh" #include "sc_fifo_in_if.hh" #include "sc_fifo_out_if.hh" -#include "warn_unimpl.hh" namespace sc_core { @@ -53,18 +54,39 @@ class sc_fifo : public sc_fifo_in_if, explicit sc_fifo(int size=16) : sc_fifo_in_if(), sc_fifo_out_if(), sc_prim_channel(sc_gen_unique_name("fifo")), - _size(size), _readsHappened(false) + _size(size), _readsHappened(false), _reader(NULL), _writer(NULL) {} explicit sc_fifo(const char *name, int size=16) : sc_fifo_in_if(), sc_fifo_out_if(), - sc_prim_channel(name), _size(size), _readsHappened(false) + sc_prim_channel(name), _size(size), _readsHappened(false), + _reader(NULL), _writer(NULL) {} virtual ~sc_fifo() {} virtual void - register_port(sc_port_base &, const char *) + register_port(sc_port_base &port, const char *iface_type_name) { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + std::string tn(iface_type_name); + if (tn == typeid(sc_fifo_in_if).name() || + tn == typeid(sc_fifo_blocking_in_if).name()) { + if (_reader) { + SC_REPORT_ERROR( + "(E104) sc_fifo cannot have more than one reader", + ""); + } + _reader = &port; + } else if (tn == typeid(sc_fifo_out_if).name() || + tn == typeid(sc_fifo_blocking_out_if).name()) { + if (_writer) { + SC_REPORT_ERROR( + "(E105) sc_fifo cannot have more than one writer", + ""); + } + _writer = &port; + } else { + SC_REPORT_ERROR("(E107) bind interface to port failed", + "sc_fifo port not recognized"); + } } virtual void @@ -192,6 +214,9 @@ class sc_fifo : public sc_fifo_in_if, sc_event _dataReadEvent; sc_event _dataWriteEvent; + sc_port_base *_reader; + sc_port_base *_writer; + int _size; mutable std::list _entries; mutable std::list _pending; diff --git a/src/systemc/ext/channel/sc_signal.hh b/src/systemc/ext/channel/sc_signal.hh index 7c0183763..672eef596 100644 --- a/src/systemc/ext/channel/sc_signal.hh +++ b/src/systemc/ext/channel/sc_signal.hh @@ -31,6 +31,7 @@ #define __SYSTEMC_EXT_CHANNEL_SC_SIGNAL_HH__ #include +#include #include #include @@ -39,7 +40,6 @@ #include "../core/sc_prim.hh" #include "../dt/bit/sc_logic.hh" #include "sc_signal_inout_if.hh" -#include "warn_unimpl.hh" // for warn_unimpl namespace sc_core { @@ -53,22 +53,41 @@ class sc_signal : public sc_signal_inout_if, public: sc_signal() : sc_signal_inout_if(), sc_prim_channel(sc_gen_unique_name("signal")), - m_cur_val(T()), m_new_val(T()), _changeStamp(~0ULL) + m_cur_val(T()), m_new_val(T()), _changeStamp(~0ULL), + _gem5Writer(NULL) {} explicit sc_signal(const char *name) : sc_signal_inout_if(), sc_prim_channel(name), - m_cur_val(T()), m_new_val(T()), _changeStamp(~0ULL) + m_cur_val(T()), m_new_val(T()), _changeStamp(~0ULL), + _gem5Writer(NULL) {} explicit sc_signal(const char *name, const T &initial_value) : sc_signal_inout_if(), sc_prim_channel(name), - m_cur_val(initial_value), m_new_val(initial_value), _changeStamp(~0ULL) + m_cur_val(initial_value), m_new_val(initial_value), + _changeStamp(~0ULL), _gem5Writer(NULL) {} virtual ~sc_signal() {} virtual void - register_port(sc_port_base &, const char *) - { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + register_port(sc_port_base &port, const char *iface_type_name) + { + if (WRITER_POLICY == SC_ONE_WRITER && + std::string(iface_type_name) == + typeid(sc_signal_inout_if).name()) { + if (_gem5Writer) { + std::ostringstream ss; + ss << "\n signal " << "`" << name() << "' (" << + kind() << ")"; + ss << "\n first driver `" << _gem5Writer->name() << "' (" << + _gem5Writer->kind() << ")"; + ss << "\n second driver `" << port.name() << "' (" << + port.kind() << ")"; + SC_REPORT_ERROR( + "(E115) sc_signal cannot have more than one driver", + ss.str().c_str()); + } + _gem5Writer = &port; + } } virtual const T &read() const { return m_cur_val; } @@ -156,6 +175,7 @@ class sc_signal : public sc_signal_inout_if, private: sc_event _valueChangedEvent; uint64_t _changeStamp; + sc_port_base *_gem5Writer; // Disabled sc_signal(const sc_signal &) : @@ -179,24 +199,43 @@ class sc_signal : sc_signal() : sc_signal_inout_if(), sc_prim_channel(sc_gen_unique_name("signal")), m_cur_val(bool()), m_new_val(bool()), - _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL) + _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL), + _gem5Writer(NULL) {} explicit sc_signal(const char *name) : sc_signal_inout_if(), sc_prim_channel(name), m_cur_val(bool()), m_new_val(bool()), - _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL) + _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL), + _gem5Writer(NULL) {} explicit sc_signal(const char *name, const bool &initial_value) : sc_signal_inout_if(), sc_prim_channel(name), m_cur_val(initial_value), m_new_val(initial_value), - _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL) + _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL), + _gem5Writer(NULL) {} virtual ~sc_signal() {} virtual void - register_port(sc_port_base &, const char *) - { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + register_port(sc_port_base &port, const char *iface_type_name) + { + if (WRITER_POLICY == SC_ONE_WRITER && + std::string(iface_type_name) == + typeid(sc_signal_inout_if).name()) { + if (_gem5Writer) { + std::ostringstream ss; + ss << "\n signal " << "`" << name() << "' (" << + kind() << ")"; + ss << "\n first driver `" << _gem5Writer->name() << "' (" << + _gem5Writer->kind() << ")"; + ss << "\n second driver `" << port.name() << "' (" << + port.kind() << ")"; + SC_REPORT_ERROR( + "(E115) sc_signal cannot have more than one driver", + ss.str().c_str()); + } + _gem5Writer = &port; + } } virtual const bool &read() const { return m_cur_val; } @@ -314,6 +353,8 @@ class sc_signal : uint64_t _posStamp; uint64_t _negStamp; + sc_port_base *_gem5Writer; + // Disabled sc_signal(const sc_signal &) : sc_signal_inout_if(), sc_prim_channel("") @@ -328,25 +369,44 @@ class sc_signal : sc_signal() : sc_signal_inout_if(), sc_prim_channel(sc_gen_unique_name("signal")), m_cur_val(sc_dt::sc_logic()), m_new_val(sc_dt::sc_logic()), - _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL) + _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL), + _gem5Writer(NULL) {} explicit sc_signal(const char *name) : sc_signal_inout_if(), sc_prim_channel(name), m_cur_val(sc_dt::sc_logic()), m_new_val(sc_dt::sc_logic()), - _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL) + _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL), + _gem5Writer(NULL) {} explicit sc_signal(const char *name, const sc_dt::sc_logic &initial_value) : sc_signal_inout_if(), sc_prim_channel(name), m_cur_val(initial_value), m_new_val(initial_value), - _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL) + _changeStamp(~0ULL), _posStamp(~0ULL), _negStamp(~0ULL), + _gem5Writer(NULL) {} virtual ~sc_signal() {} virtual void - register_port(sc_port_base &, const char *) - { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); + register_port(sc_port_base &port, const char *iface_type_name) + { + if (WRITER_POLICY == SC_ONE_WRITER && + std::string(iface_type_name) == + typeid(sc_signal_inout_if).name()) { + if (_gem5Writer) { + std::ostringstream ss; + ss << "\n signal " << "`" << name() << "' (" << + kind() << ")"; + ss << "\n first driver `" << _gem5Writer->name() << "' (" << + _gem5Writer->kind() << ")"; + ss << "\n second driver `" << port.name() << "' (" << + port.kind() << ")"; + SC_REPORT_ERROR( + "(E115) sc_signal cannot have more than one driver", + ss.str().c_str()); + } + _gem5Writer = &port; + } } virtual const sc_dt::sc_logic &read() const { return m_cur_val; } @@ -464,6 +524,8 @@ class sc_signal : uint64_t _posStamp; uint64_t _negStamp; + sc_port_base *_gem5Writer; + // Disabled sc_signal(const sc_signal &) : sc_signal_inout_if(), sc_prim_channel("") diff --git a/src/systemc/ext/channel/sc_signal_rv.hh b/src/systemc/ext/channel/sc_signal_rv.hh index d333da052..1a47e84ad 100644 --- a/src/systemc/ext/channel/sc_signal_rv.hh +++ b/src/systemc/ext/channel/sc_signal_rv.hh @@ -35,7 +35,6 @@ #include "../dt/bit/sc_logic.hh" #include "../dt/bit/sc_lv.hh" #include "sc_signal.hh" -#include "warn_unimpl.hh" namespace sc_dt { @@ -62,11 +61,7 @@ class sc_signal_rv : public sc_signal, SC_MANY_WRITERS> {} virtual ~sc_signal_rv() {} - virtual void - register_port(sc_port_base &, const char *) - { - sc_channel_warn_unimpl(__PRETTY_FUNCTION__); - } + virtual void register_port(sc_port_base &, const char *) {} virtual void write(const sc_dt::sc_lv &l) diff --git a/src/systemc/ext/channel/warn_unimpl.hh b/src/systemc/ext/channel/warn_unimpl.hh deleted file mode 100644 index 8262ae29e..000000000 --- a/src/systemc/ext/channel/warn_unimpl.hh +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2018 Google, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer; - * redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution; - * neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: Gabe Black - */ - -#ifndef __SYSTEMC_EXT_CHANNEL_WARN_UNIMPL_HH__ -#define __SYSTEMC_EXT_CHANNEL_WARN_UNIMPL_HH__ - -namespace sc_core -{ - -void sc_channel_warn_unimpl(const char *func); - -} // namespace sc_core - -#endif //__SYSTEMC_EXT_CHANNEL_WARN_UNIMPL_HH__ diff --git a/src/systemc/tests/systemc/communication/sc_signal/check_writer/test08/expected_returncode b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test08/expected_returncode new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test08/expected_returncode @@ -0,0 +1 @@ +1 diff --git a/src/systemc/tests/systemc/communication/sc_signal/check_writer/test09/expected_returncode b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test09/expected_returncode new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test09/expected_returncode @@ -0,0 +1 @@ +1 diff --git a/src/systemc/tests/systemc/communication/sc_signal/check_writer/test10/expected_returncode b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test10/expected_returncode new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test10/expected_returncode @@ -0,0 +1 @@ +1 diff --git a/src/systemc/tests/systemc/communication/sc_signal/check_writer/test11/expected_returncode b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test11/expected_returncode new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test11/expected_returncode @@ -0,0 +1 @@ +1 diff --git a/src/systemc/tests/systemc/communication/sc_signal/check_writer/test12/expected_returncode b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test12/expected_returncode new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test12/expected_returncode @@ -0,0 +1 @@ +1 diff --git a/src/systemc/tests/systemc/communication/sc_signal/register_port/test01/expected_returncode b/src/systemc/tests/systemc/communication/sc_signal/register_port/test01/expected_returncode new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/register_port/test01/expected_returncode @@ -0,0 +1 @@ +1 diff --git a/src/systemc/tests/systemc/communication/sc_signal/register_port/test02/expected_returncode b/src/systemc/tests/systemc/communication/sc_signal/register_port/test02/expected_returncode new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/register_port/test02/expected_returncode @@ -0,0 +1 @@ +1 diff --git a/src/systemc/tests/systemc/communication/sc_signal/register_port/test03/expected_returncode b/src/systemc/tests/systemc/communication/sc_signal/register_port/test03/expected_returncode new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/register_port/test03/expected_returncode @@ -0,0 +1 @@ +1 -- cgit v1.2.3