From: Gabe Black Date: Tue, 16 Apr 2019 04:05:55 +0000 (-0700) Subject: python: Generalize the Port.splice function. X-Git-Tag: v19.0.0.0~948 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3c3f360bbe8a3394657a0fa78bae90826100a235;p=gem5.git python: Generalize the Port.splice function. Now that the MASTER and SLAVE roles aren't special, the splice function needs to be able to handle arbitrarily role-d peers. Change-Id: I22a28b7cdcb93f7f370730b7e38b0e6d3500a6a0 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18170 Tested-by: kokoro Reviewed-by: Andreas Sandberg Maintainer: Andreas Sandberg --- diff --git a/src/python/m5/params.py b/src/python/m5/params.py index 9b2ee3972..60d4a14b9 100644 --- a/src/python/m5/params.py +++ b/src/python/m5/params.py @@ -1895,35 +1895,36 @@ class PortRef(object): if other.peer is not self: other.connect(self) - # Allow a master/slave port pair to be spliced between - # a port and its connected peer. Useful operation for connecting - # instrumentation structures into a system when it is necessary - # to connect the instrumentation after the full system has been - # constructed. - def splice(self, new_master_peer, new_slave_peer): + # Allow a compatible port pair to be spliced between a port and its + # connected peer. Useful operation for connecting instrumentation + # structures into a system when it is necessary to connect the + # instrumentation after the full system has been constructed. + def splice(self, new_1, new_2): if not self.peer or proxy.isproxy(self.peer): fatal("Port %s not connected, cannot splice in new peers\n", self) - if not isinstance(new_master_peer, PortRef) or \ - not isinstance(new_slave_peer, PortRef): + if not isinstance(new_1, PortRef) or not isinstance(new_2, PortRef): raise TypeError( "Splicing non-port references '%s','%s' to port '%s'" % \ - (new_master_peer, new_slave_peer, self)) + (new_1, new_2, self)) old_peer = self.peer - if self.role == 'SLAVE': - self.peer = new_master_peer - old_peer.peer = new_slave_peer - new_master_peer.connect(self) - new_slave_peer.connect(old_peer) - elif self.role == 'MASTER': - self.peer = new_slave_peer - old_peer.peer = new_master_peer - new_slave_peer.connect(self) - new_master_peer.connect(old_peer) + + if Port.is_compat(old_peer, new_1) and Port.is_compat(self, new_2): + old_peer.peer = new_1 + new_1.peer = old_peer + self.peer = new_2 + new_2.peer = self + elif Port.is_compat(old_peer, new_2) and Port.is_compat(self, new_1): + old_peer.peer = new_2 + new_2.peer = old_peer + self.peer = new_1 + new_1.peer = self else: - panic("Port %s has unknown role, "+\ - "cannot splice in new peers\n", self) + fatal("Ports %s(%s) and %s(%s) can't be compatibly spliced with " + "%s(%s) and %s(%s)", self, self.role, + old_peer, old_peer.role, new_1, new_1.role, + new_2, new_2.role) def clone(self, simobj, memo): if self in memo: