From 2a566b4fa7fbd805746d598d0ffc096c2710cef9 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 16 Aug 2019 15:27:35 -0700 Subject: mem, sim, systemc: Reorganize Port and co.s bind, unbind slightly. The base Port class can keep track of its peer, and also whether it's connected. This is partially delegated away from the port subclasses which still keep track of a cast version of their peer pointer for their own conveneince, so that it can be used by generic code. Even with the Port mechanism's new flexibility, each port still has exactly one peer and is either connected or not based on whether there is a peer currently. Change-Id: Id3228617dd1604d196814254a1aadeac5ade7cde Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20232 Tested-by: kokoro Reviewed-by: Nikos Nikoleris Reviewed-by: Andreas Sandberg Maintainer: Gabe Black --- src/sim/port.cc | 2 +- src/sim/port.hh | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src/sim') diff --git a/src/sim/port.cc b/src/sim/port.cc index b3139a630..fa7df18cf 100644 --- a/src/sim/port.cc +++ b/src/sim/port.cc @@ -50,6 +50,6 @@ #include "sim/port.hh" Port::Port(const std::string& _name, PortID _id) : - portName(_name), id(_id), _connected(false) + portName(_name), id(_id), _peer(nullptr), _connected(false) {} Port::~Port() {} diff --git a/src/sim/port.hh b/src/sim/port.hh index e1811643f..ee4b548a5 100644 --- a/src/sim/port.hh +++ b/src/sim/port.hh @@ -72,6 +72,13 @@ class Port * to InvalidPortID in case this port is not part of a vector. */ const PortID id; + + /** + * A pointer to this port's peer. + */ + Port *_peer; + + /** * Whether this port is currently connected to a peer port. */ @@ -92,6 +99,9 @@ class Port public: + /** Return a reference to this port's peer. */ + Port &getPeer() { return *_peer; } + /** Return port name (for DPRINTF). */ const std::string name() const { return portName; } @@ -99,10 +109,20 @@ class Port PortID getId() const { return id; } /** Attach to a peer port. */ - virtual void bind(Port &peer) = 0; + virtual void + bind(Port &peer) + { + _peer = &peer; + _connected = true; + } /** Dettach from a peer port. */ - virtual void unbind() = 0; + virtual void + unbind() + { + _peer = nullptr; + _connected = false; + } /** Is this port currently connected to a peer? */ bool isConnected() const { return _connected; } -- cgit v1.2.3