move match_instance to Module
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 21 Apr 2020 15:07:11 +0000 (15:07 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 21 Apr 2020 15:07:11 +0000 (15:07 +0000)
experiments7/doAlu16.py
experiments7/utils.py

index d9c2a97c6d1c894f0d256dc1f7d945750de0631c..490f9b866004eafe11239b9eb17b90cd19bac9f2 100755 (executable)
@@ -2,7 +2,6 @@
 # -*- coding: utf-8 -*-
 from __future__ import print_function
 import sys
-import re
 
 import CRL
 import Cfg
@@ -68,37 +67,6 @@ class AddSub(Module):
 
 class ALU16(Module):
 
-    @staticmethod
-    def match_instance(datapath_insts, op, plug_name, inst):
-        """
-        Guess the position of an instance from its nets connections,
-        and put it at the right place in the datapath vector.
-
-        :param datapath_insts: vector of bit slices,
-        :param op: operator name,
-        :param inst: instance to classify,
-        :param plug_name: name of the plug to use to guess the bit index,
-        :return: boolean, True if the instance has been matched.
-        """
-        if not inst.getMasterCell().getName().startswith(op):
-            return False
-        re_net_index = re.compile(r'[^(]+\((?P<index>[\d]+)\)$')
-        for plug in inst.getPlugs():
-            if plug.getMasterNet().getName() != plug_name:
-                continue
-            m = re_net_index.match(plug.getNet().getName())
-            if not m:
-                continue
-            bit_slice = datapath_insts[int(m.group('index'))]
-            for column in bit_slice:
-                if column[0] == op:
-                    column[1] = inst
-                    print ("match", plug_name, int(m.group('index')),
-                            column, inst)
-                    return True
-            break
-        return False
-
     def place_datapath(self, datapath_insts, x_orig, y_orig, fold):
         channel_sff1 = self.to_dbu(0)
         with SessionManager():
@@ -130,9 +98,9 @@ class ALU16(Module):
                                    ['sff1', None]])
 
         for inst in self.cell.getInstances():
-            if (ALU16.match_instance(datapath_insts, 'nmx2', 'i0', inst) or
-                ALU16.match_instance(datapath_insts, 'no2', 'nq', inst) or
-                ALU16.match_instance(datapath_insts, 'sff1', 'i', inst)):
+            if (Module.match_instance(datapath_insts, 'nmx2', 'i0', inst) or
+                Module.match_instance(datapath_insts, 'no2', 'nq', inst) or
+                Module.match_instance(datapath_insts, 'sff1', 'i', inst)):
                 continue
 
         # place to right of add
index 47d29e7b1be7c7550a4bd9cf220c311c0e33852a..cfaf56e9db0b0cc19abd1b17f3d316e76da76ca1 100644 (file)
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 from __future__ import print_function
+import re
 
 import Anabatic
 import CRL
@@ -164,6 +165,37 @@ class Module(object):
     def ab_height(self):
         return self.from_dbu(self.ab.getXHeight())
 
+    @staticmethod
+    def match_instance(datapath_insts, op, plug_name, inst):
+        """
+        Guess the position of an instance from its nets connections,
+        and put it at the right place in the datapath vector.
+
+        :param datapath_insts: vector of bit slices,
+        :param op: operator name,
+        :param inst: instance to classify,
+        :param plug_name: name of the plug to use to guess the bit index,
+        :return: boolean, True if the instance has been matched.
+        """
+        if not inst.getMasterCell().getName().startswith(op):
+            return False
+        re_net_index = re.compile(r'[^(]+\((?P<index>[\d]+)\)$')
+        for plug in inst.getPlugs():
+            if plug.getMasterNet().getName() != plug_name:
+                continue
+            m = re_net_index.match(plug.getNet().getName())
+            if not m:
+                continue
+            bit_slice = datapath_insts[int(m.group('index'))]
+            for column in bit_slice:
+                if column[0] == op:
+                    column[1] = inst
+                    print ("match", plug_name, int(m.group('index')),
+                            column, inst)
+                    return True
+            break
+        return False
+
     def compute_ab(self):
         """ Compute default abutment box without placement. """
         etesian = Etesian.EtesianEngine.create(self.cell)