python: Generalize the Port.splice function.
authorGabe Black <gabeblack@google.com>
Tue, 16 Apr 2019 04:05:55 +0000 (21:05 -0700)
committerGabe Black <gabeblack@google.com>
Wed, 24 Apr 2019 11:00:20 +0000 (11:00 +0000)
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 <noreply+kokoro@google.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>

src/python/m5/params.py

index 9b2ee39721e1b002c4e84610e26cf3485231bd1d..60d4a14b99b05e7a912e97c7eed56fad49bbe118 100644 (file)
@@ -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: