From 1bff74a56e8b873f5c7910d427daeaf3de70d207 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sat, 22 May 2021 22:10:26 +0200 Subject: [PATCH] Use simple pattern matching in Block._rgetInstance() (LKCL). --- cumulus/src/plugins/alpha/block/block.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/cumulus/src/plugins/alpha/block/block.py b/cumulus/src/plugins/alpha/block/block.py index 90a5d62d..b6726e31 100644 --- a/cumulus/src/plugins/alpha/block/block.py +++ b/cumulus/src/plugins/alpha/block/block.py @@ -329,8 +329,21 @@ class Block ( object ): .format(self.conf.cell.getName()) ) Block.LUT[ self.conf.cell ] = self + @staticmethod - def _rgetInstance ( cell, path ): + def _getInstance ( cell, pattern, level=0 ): + """ + getInstanceMatching(): returns first instance with the word being searched. + """ + for instance in cell.getInstances(): + name = instance.getName() + if pattern in name: + trace( 550, '\t{} {} match pattern "{}"\n'.format(' '*level,instance,pattern) ) + return instance + return None + + @staticmethod + def _rgetInstance ( cell, path, level=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 @@ -341,13 +354,13 @@ class Block ( object ): elif not isinstance(path,list): raise ErrorMessage( 1, 'Block._rgetInstance(): "path" argument is neither a string or a list ({})"' \ .format(path) ) - instance = cell.getInstance( path[0] ) + instance = Block._getInstance( cell, path[0], level ) if instance is None: - raise ErrorMessage( 1, 'Block._rgetInstance(): no instance "{}" in cell "{}"' \ + raise ErrorMessage( 1, 'Block._rgetInstance(): no instance matching "{}" in cell "{}"' \ .format(path[0],cell.getName()) ) if len(path) == 1: return instance - return Block._rgetInstance( instance.getMasterCell(), path[1:] ) + return Block._rgetInstance( instance.getMasterCell(), path[1:], level+1 ) def rgetCoreInstance ( self, path ): """