Browse Source

locating io ports and busses by name

devel
Stefan Holst 2 years ago
parent
commit
4847ad9c40
  1. 20
      src/kyupy/circuit.py

20
src/kyupy/circuit.py

@ -6,6 +6,7 @@ and a line is an instance of class :class:`Line`.
""" """
from collections import deque from collections import deque
import re
class GrowingList(list): class GrowingList(list):
@ -371,3 +372,22 @@ class Circuit:
queue.extend(preds) queue.extend(preds)
region.append(n) region.append(n)
yield stem, region yield stem, region
def io_loc(self, prefix):
d_top = dict()
for i, n in enumerate(self.interface):
if m := re.match(fr'({prefix}.*?)((?:[_\[\]]\d+)*[_\[\]]*$)', n.name):
path = [m[1]] + [int(v) for v in re.split(r'[_\[\]]+', m[2]) if len(v) > 0]
d = d_top
for j in path[:-1]:
d[j] = d.get(j, dict())
d = d[j]
d[path[-1]] = i
def sorted_values(d):
return [sorted_values(v) for k, v in sorted(d.items())] if isinstance(d, dict) else d
l = sorted_values(d_top)
while isinstance(l, list) and len(l) == 1: l = l[0]
return l

Loading…
Cancel
Save