do an SRAM search by looking for matching along the path
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 30 Apr 2021 17:47:47 +0000 (17:47 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 30 Apr 2021 17:47:47 +0000 (17:47 +0000)
goodbye explicit yosys ids!

experiments9/freepdk_c4m45/doDesign.py

index e1a04aa921da94b345b379434d91bf800eec511b..f2a65f227bbc94cacfb9190cef25f6ab12992457 100644 (file)
@@ -94,6 +94,49 @@ def doIoPinVector ( ioSpec, bits ):
     return v
 
 
+def get_instance_like(cell, name_contains, lev=0):
+    """get_instance_like: returns first instance with the word being searched
+    """
+    for inst in cell.getInstances():
+        name = inst.getName()
+        if name_contains in name:
+            print ("\t"*lev + "found instance like", name_contains, inst, name)
+            return inst
+
+    return None
+
+def rgetInstanceLike ( cell, path, lev=0):
+    """
+    Get the instance designated by path (recursively). The path argument can be
+    either a string of instance names separated by dots or directly a list of
+    instances names.
+
+    it also "reconstructs" the actual full path name of the instances
+    found recursively.
+    """
+    if isinstance(path,str):
+        path = path.split( '.' )
+    elif not isinstance(path, list):
+        raise ErrorMessage( 1, 'rgetInstanceLike(): "path" argument is ' \
+                               'neither a string or a list ({})"' \
+                               .format(path) )
+    # find instance at this level
+    instance = get_instance_like(cell, path[0], lev)
+    if instance is None:
+        raise ErrorMessage( 1, 'rgetInstanceLike(): no instance "{}" ' \
+                               'in cell "{}"' \
+                               .format(path[0], cell.getName()) )
+    iname = instance.getName()
+    # last instance (leaf search), return it
+    if len(path) == 1:
+        return instance, iname
+    # chew down another level, another brick in the wall
+    rinstance, rname = rgetInstanceLike(instance.getMasterCell(),
+                                        path[1:], lev+1)
+    # accumulate the names recursively found "level0.level1.level2..."
+    return rinstance, "%s.%s" % (iname, rname)
+
+
 def rgetInstance ( cell, path ):
     """
     Get the instance designated by path (recursively). The path argument can be
@@ -255,34 +298,25 @@ def scriptMain (**kw):
 
         with UpdateSession():
             #######
-            # placement of SRAM blackboxes, manually
+            # placement of SRAM blackboxes, manually.
 
-            # Thoses ids are dependent on Yosys. They need to be adjusted
-            # whenever the design changes.
-            tiId   = 38695
-            tiId   = 38381
-            sramId = 3695
-            sramId = 3300
-            tiPath = 'subckt_{}_test_issuer.subckt_1_ti.'.format(tiId)
-            sramPaths = [ tiPath+'subckt_{}_sram4k_0.subckt_144_SPBlock_512W64B8W'.format(sramId)
-                         , tiPath+'subckt_{}_sram4k_1.subckt_144_SPBlock_512W64B8W'.format(sramId+1)
-                         , tiPath+'subckt_{}_sram4k_2.subckt_144_SPBlock_512W64B8W'.format(sramId+2)
-                         , tiPath+'subckt_{}_sram4k_3.subckt_144_SPBlock_512W64B8W'.format(sramId+3)
-                         ]
-            # each sram is named differently (yosys blackbox issue)
+            # a "search by like" function is used which matches against
+            # the dotted component.  brute force and ignorance...
+            tiPath = 'test_issuer.subckt_1_ti.sram4k_%d.spblock_512w64b8w'
             for i in range(4):
-                sram = DataBase.getDB().getCell( 'spblock512w64b8w_%i' )
+                sram = DataBase.getDB().getCell( 'spblock_512w64b8w' )
                 if sram:
                     sramAb = sram.getAbutmentBox()
                     coreAb = cell.getAbutmentBox()
                     sliceHeight = chipBuilder.conf.sliceHeight
                     originX = coreAb.getXMin() + 2*chipBuilder.conf.sliceStep
-                    sram = rgetInstance( cell, sramPaths[i] )
+                    sram, path = rgetInstanceLike( cell, tiPath % i )
+                    print ("found SRAM", sram, path)
                     y = coreAb.getYMax() - sramAb.getHeight() - 2*sliceHeight
                     t = Transformation( originX
                                       , y
                                       , Transformation.Orientation.ID )
-                    chipBuilder.placeMacro ( sramPaths[i], t )
+                    chipBuilder.placeMacro ( path, t )
                     originX += sramAb.getWidth () + 3*sliceHeight
                 else:
                     print (ErrorMessage( 1, 'SRAM instance %d not found.' % i))