move get_net_connections to Module in utils.py
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 21 Apr 2020 18:18:57 +0000 (18:18 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 21 Apr 2020 18:18:57 +0000 (18:18 +0000)
experiments7/doAlu16.py
experiments7/utils.py

index 19bf8f74be69dbecdf0d5d6649f8cc27aa20069b..66f4043647d3a84e21c34591fbe580dc866f41a9 100755 (executable)
@@ -157,7 +157,7 @@ class ALU16(Module):
 
             self.create_pins()
 
-        find = self.get_net_connections(['add_o(1)', 'sub_o(1)', 'o(1)'],
+        find = self.get_net_connections(['o(15)'],
                                         ['clk', 'rst', 'op'])
         print (find)
         sys.exit(0)
@@ -194,40 +194,6 @@ class ALU16(Module):
         self.save()
         return result
 
-    def get_net_connections(self, find, already_found):
-        res = set()
-        search_more = []
-        for inst in self.cell.getInstances():
-            if (inst.getPlacementStatus() !=
-                    Instance.PlacementStatus.UNPLACED):
-                continue
-            print ("instance", inst)
-            for plug in inst.getConnectedPlugs():
-                netname = plug.getNet().getName()
-                if netname in already_found:
-                    continue
-                if plug.getNet().getName() in find:
-                    print ("plug", plug, plug.getNet().getName())
-                    for p in plug.getNet().getPlugs():
-                        c = p.getInstance()
-                        if (c.getPlacementStatus() !=
-                                Instance.PlacementStatus.UNPLACED):
-                            continue
-                        print ("notplaced", c)
-                        for pc in c.getConnectedPlugs():
-                            print ("plug", pc)
-                            pn = pc.getNet().getName()
-                            if pn not in find and pn not in already_found:
-                                search_more.append(pn)
-                        res.add(c)
-            print()
-        if search_more:
-            print("more", search_more)
-            new_found = find + already_found
-            more = self.get_net_connections(search_more, new_found)
-            res.update(more)
-        return res
-
 
 def scriptMain(editor=None, **kwargs):
     coriolis_setup()
index cfaf56e9db0b0cc19abd1b17f3d316e76da76ca1..4dcb8890a57df1150d2a2f08ebc5b16c5782e10c 100644 (file)
@@ -435,6 +435,10 @@ class Module(object):
 
         raise NotImplementedError('You need to implement the `build` method.')
 
+    def get_net_connections(self, to_find, already_found):
+        inst = self.cell.getInstances()
+        return get_net_connections(inst, to_find, already_found)
+
 
 class Config:
 
@@ -468,3 +472,39 @@ class Config:
         if self._priority is not None:
             Cfg.Configuration.popDefaultPriority()
 
+
+def get_net_connections(instances, find, already_found):
+    res = set()
+    new = set()
+    search_more = []
+    for inst in instances:
+        if (inst.getPlacementStatus() !=
+                Instance.PlacementStatus.UNPLACED):
+            continue
+        #print ("instance", inst)
+        for plug in inst.getConnectedPlugs():
+            netname = plug.getNet().getName()
+            if netname in already_found:
+                continue
+            if plug.getNet().getName() in find:
+                #print ("plug", plug, plug.getNet().getName())
+                for p in plug.getNet().getPlugs():
+                    c = p.getInstance()
+                    if (c.getPlacementStatus() !=
+                            Instance.PlacementStatus.UNPLACED):
+                        continue
+                    #print ("notplaced", c)
+                    for pc in c.getConnectedPlugs():
+                        #print ("plug", pc)
+                        pn = pc.getNet().getName()
+                        if pn not in find and pn not in already_found:
+                            search_more.append(pn)
+                    new.add(c)
+    res.update(new)
+    if search_more:
+        print("more", search_more)
+        new_found = find + already_found
+        more = get_net_connections(new, search_more, new_found)
+        res.update(more)
+
+    return res