From 8e91764a3642c3ef5e630d02908f8c9072d5b538 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 13 Aug 2018 18:19:15 -0700 Subject: systemc: Implement port binding except positional binding. This change adds code which keeps track of ports and interfaces which are being bound to be finalized later, and the actual port binding of interfaces and recursive binding port ports. Change-Id: Ifa885ed44b667254762cc101580be4f0a7d7a131 Reviewed-on: https://gem5-review.googlesource.com/12084 Reviewed-by: Gabe Black Maintainer: Gabe Black --- src/systemc/core/kernel.cc | 4 ++++ src/systemc/core/module.hh | 10 ++++++++++ src/systemc/core/process.hh | 2 +- src/systemc/core/sc_port.cc | 44 +++++++++++++++++++++++++++++++++++++------- 4 files changed, 52 insertions(+), 8 deletions(-) (limited to 'src/systemc/core') diff --git a/src/systemc/core/kernel.cc b/src/systemc/core/kernel.cc index 4eb0bb765..65a444536 100644 --- a/src/systemc/core/kernel.cc +++ b/src/systemc/core/kernel.cc @@ -77,6 +77,10 @@ Kernel::init() void Kernel::regStats() { + for (auto m: sc_gem5::allModules) + for (auto p: m->ports) + p->_gem5Finalize(); + status(::sc_core::SC_END_OF_ELABORATION); for (auto m: sc_gem5::allModules) m->sc_mod()->end_of_elaboration(); diff --git a/src/systemc/core/module.hh b/src/systemc/core/module.hh index a5bf92975..0a6d9b7bb 100644 --- a/src/systemc/core/module.hh +++ b/src/systemc/core/module.hh @@ -35,10 +35,18 @@ #include #include #include +#include #include "systemc/core/object.hh" #include "systemc/ext/core/sc_module.hh" +namespace sc_core +{ + +class sc_port_base; + +} // namespace sc_core + namespace sc_gem5 { @@ -101,6 +109,8 @@ class Module void pop(); const char *uniqueName(const char *seed) { return nameGen.gen(seed); } + + std::vector<::sc_core::sc_port_base *> ports; }; Module *currentModule(); diff --git a/src/systemc/core/process.hh b/src/systemc/core/process.hh index 5f0a72d1e..33dcf870d 100644 --- a/src/systemc/core/process.hh +++ b/src/systemc/core/process.hh @@ -221,7 +221,7 @@ class PendingSensitivityPort : public PendingSensitivity { for (int i = 0; i < port->size(); i++) { const ::sc_core::sc_event *e = - &port->_gem5BindInfo[i]->interface->default_event(); + &port->_gem5Interface(i)->default_event(); s.push_back(new SensitivityEvent(process, e)); } } diff --git a/src/systemc/core/sc_port.cc b/src/systemc/core/sc_port.cc index ad228548f..d10ceeab3 100644 --- a/src/systemc/core/sc_port.cc +++ b/src/systemc/core/sc_port.cc @@ -29,14 +29,18 @@ #include "base/logging.hh" #include "systemc/core/bindinfo.hh" +#include "systemc/core/module.hh" #include "systemc/ext/core/sc_port.hh" namespace sc_core { sc_port_base::sc_port_base(const char *name, int n, sc_port_policy p) : - sc_object(name) -{} + sc_object(name), _maxSize(n), _size(0), finalized(false) +{ + ::sc_gem5::Module *m = ::sc_gem5::currentModule(); + m->ports.push_back(this); +} void sc_port_base::warn_unimpl(const char *func) const @@ -45,18 +49,44 @@ sc_port_base::warn_unimpl(const char *func) const } int sc_port_base::maxSize() const { return _maxSize; } -int sc_port_base::size() const { return _gem5BindInfo.size(); } +int sc_port_base::size() const { return _size; } + +void +sc_port_base::bind(sc_interface &i) +{ + _gem5BindInfo.push_back(new ::sc_gem5::BindInfo(&i)); +} void -sc_port_base::bind(sc_interface &) +sc_port_base::bind(sc_port_base &p) { - warn("%s not implemented.\n", __PRETTY_FUNCTION__); + _gem5BindInfo.push_back(new ::sc_gem5::BindInfo(&p)); } void -sc_port_base::bind(sc_port_base &) +sc_port_base::_gem5Finalize() { - warn("%s not implemented.\n", __PRETTY_FUNCTION__); + if (finalized) + return; + finalized = true; + + for (auto &bi: _gem5BindInfo) { + if (bi->interface) { + _size++; + _gem5AddInterface(bi->interface); + } else { + sc_port_base *port = bi->port; + port->_gem5Finalize(); + int size = port->size(); + for (int i = 0; i < size; i++) { + _size++; + _gem5AddInterface(port->_gem5Interface(i)); + } + } + delete bi; + } + + _gem5BindInfo.clear(); } } // namespace sc_core -- cgit v1.2.3