config: De-nest the code in Port.splice().
authorGabe Black <gabeblack@google.com>
Sat, 12 Jan 2019 01:04:44 +0000 (17:04 -0800)
committerGabe Black <gabeblack@google.com>
Mon, 14 Jan 2019 21:28:17 +0000 (21:28 +0000)
The error checking in that function used an if/else structure where
one of the two branches would be the error condition which would cause
the function to exit. Because the function would exit if an error was
detected, there's no reason to have the non-error condition guarded in
the other half of the if.

This change de-nests the non-error cases to make the function simpler
and easier to read.

Change-Id: Idedf54e84a178fa5a2a47f96373374152e420cf3
Reviewed-on: https://gem5-review.googlesource.com/c/15516
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>

src/python/m5/params.py

index ac712dc1fb86df19bdbea775306fcf45c1613808..1b03a665abc2390c5edb450c4df2898b3036c877 100644 (file)
@@ -1785,30 +1785,30 @@ class PortRef(object):
     # to connect the instrumentation after the full system has been
     # constructed.
     def splice(self, new_master_peer, new_slave_peer):
-        if self.peer and not proxy.isproxy(self.peer):
-            if isinstance(new_master_peer, PortRef) and \
-               isinstance(new_slave_peer, PortRef):
-                 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)
-                 else:
-                     panic("Port %s has unknown role, "+\
-                           "cannot splice in new peers\n", self)
-            else:
-                raise TypeError, \
-                      "Splicing non-port references '%s','%s' to port '%s'"\
-                      % (new_master_peer, new_slave_peer, self)
-        else:
+        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):
+            raise TypeError, \
+                  "Splicing non-port references '%s','%s' to port '%s'" % \
+                  (new_master_peer, new_slave_peer, 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)
+        else:
+            panic("Port %s has unknown role, "+\
+                  "cannot splice in new peers\n", self)
+
     def clone(self, simobj, memo):
         if memo.has_key(self):
             return memo[self]