From: Gabe Black Date: Mon, 1 Oct 2018 09:33:55 +0000 (-0700) Subject: systemc: Add missing sc_interface::register_port, and add calls to it. X-Git-Tag: v19.0.0.0~1546 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b2e1f81f51e630ef4399f24024c82404601f8340;p=gem5.git systemc: Add missing sc_interface::register_port, and add calls to it. This function is standard and supposed to be on sc_interface, but it was somehow left out. This change adds it, and makes sure it's called by the port binding code. The default implementation does nothing, as it's supposed to according to the spec. Also note that only the ports farthest from the interfaces are suppose to call register_port. As the port bindings are completed, we keep track of whether a port has been bound to another port. If it has, the source port is farther from the interfaces than the target port (since it has to go "through" the target port to get to them, and so the target port should not call register_port. Change-Id: Ia98f9ff364385fd1699d88a1d99787d205816a08 Reviewed-on: https://gem5-review.googlesource.com/c/13199 Reviewed-by: Gabe Black Maintainer: Gabe Black --- diff --git a/src/systemc/core/kernel.cc b/src/systemc/core/kernel.cc index ff8e24e6a..5804f9683 100644 --- a/src/systemc/core/kernel.cc +++ b/src/systemc/core/kernel.cc @@ -93,6 +93,8 @@ Kernel::regStats() try { for (auto p: allPorts) p->finalize(); + for (auto p: allPorts) + p->regPort(); status(::sc_core::SC_END_OF_ELABORATION); for (auto p: allPorts) diff --git a/src/systemc/core/port.cc b/src/systemc/core/port.cc index 8ee0549a4..db025bbfe 100644 --- a/src/systemc/core/port.cc +++ b/src/systemc/core/port.cc @@ -120,6 +120,16 @@ Port::finalize() sensitivities.clear(); } +void +Port::regPort() +{ + if (!regPortNeeded) + return; + + for (int i = 0; i < size(); i++) + getInterface(i)->register_port(*portBase, portBase->_ifTypeName()); +} + std::list allPorts; } // namespace sc_gem5 diff --git a/src/systemc/core/port.hh b/src/systemc/core/port.hh index bf3b73a84..8c09ad0d3 100644 --- a/src/systemc/core/port.hh +++ b/src/systemc/core/port.hh @@ -31,6 +31,7 @@ #define __SYSTEMC_CORE_PORT_HH__ #include +#include #include #include "base/cprintf.hh" @@ -57,6 +58,8 @@ class Port int _maxSize; int _size; + bool regPortNeeded; + void finalizePort(StaticSensitivityPort *port); void finalizeFinder(StaticSensitivityFinder *finder); void finalizeReset(ResetSensitivityPort *reset); @@ -80,6 +83,8 @@ class Port void addInterfaces(::sc_core::sc_port_base *pb) { + // Only the ports farthest from the interfaces call register_port. + pb->_gem5Port->regPortNeeded = false; for (int i = 0; i < pb->size(); i++) addInterface(pb->_gem5Interface(i)); } @@ -136,7 +141,8 @@ class Port ::sc_core::sc_port_base *sc_port_base() { return portBase; } Port(::sc_core::sc_port_base *port_base, int max) : - portBase(port_base), finalized(false), _maxSize(max), _size(0) + portBase(port_base), finalized(false), _maxSize(max), _size(0), + regPortNeeded(true) { allPorts.push_front(this); } @@ -161,6 +167,7 @@ class Port void sensitive(ResetSensitivityPort *reset); void finalize(); + void regPort(); int size() { return _size; } int maxSize() { return _maxSize; } diff --git a/src/systemc/core/sc_interface.cc b/src/systemc/core/sc_interface.cc index a23612683..4b3865e13 100644 --- a/src/systemc/core/sc_interface.cc +++ b/src/systemc/core/sc_interface.cc @@ -35,6 +35,8 @@ namespace sc_core { +void sc_interface::register_port(sc_port_base &, const char *) {} + const sc_event & sc_interface::default_event() const { diff --git a/src/systemc/ext/core/sc_interface.hh b/src/systemc/ext/core/sc_interface.hh index 3c6a27dea..3b5abdf09 100644 --- a/src/systemc/ext/core/sc_interface.hh +++ b/src/systemc/ext/core/sc_interface.hh @@ -39,6 +39,7 @@ class sc_event; class sc_interface { public: + virtual void register_port(sc_port_base &, const char *); virtual const sc_event &default_event() const; virtual ~sc_interface() {}; diff --git a/src/systemc/ext/core/sc_port.hh b/src/systemc/ext/core/sc_port.hh index 3586fec73..904d35b8e 100644 --- a/src/systemc/ext/core/sc_port.hh +++ b/src/systemc/ext/core/sc_port.hh @@ -30,6 +30,7 @@ #ifndef __SYSTEMC_EXT_CORE_SC_PORT_HH__ #define __SYSTEMC_EXT_CORE_SC_PORT_HH__ +#include #include #include "../utils/sc_report_handler.hh" @@ -108,6 +109,7 @@ class sc_port_base : public sc_object virtual void _gem5AddInterface(sc_interface *i) = 0; ::sc_gem5::Port *_gem5Port; + virtual const char *_ifTypeName() const = 0; }; template @@ -210,6 +212,8 @@ class sc_port_b : public sc_port_base _interfaces.push_back(interface); } + const char *_ifTypeName() const { return typeid(IF).name(); } + // Disabled sc_port_b() {} sc_port_b(const sc_port_b &) {}