From 4f7e605819d4ae7f765ec52281e0d3f0619377cd Mon Sep 17 00:00:00 2001 From: stefan Date: Sun, 21 Jun 2026 09:28:19 +0900 Subject: [PATCH] use tlib functions to identify ffs and latches --- src/kyupy/circuit.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/kyupy/circuit.py b/src/kyupy/circuit.py index 638d311..fa4fe9a 100644 --- a/src/kyupy/circuit.py +++ b/src/kyupy/circuit.py @@ -347,9 +347,9 @@ class Circuit: stats['__line__'] = len(self.lines) for n in self.cells.values(): stats[n.kind] += 1 - if 'dff' in n.kind.lower(): stats['__dff__'] += 1 - elif 'latch' in n.kind.lower(): stats['__latch__'] += 1 - elif 'put' not in n.kind.lower(): stats['__comb__'] += 1 # no input or output + if tlib.is_dff(n.kind): stats['__dff__'] += 1 + elif tlib.is_latch(n.kind): stats['__latch__'] += 1 + elif 'put' not in n.kind.lower(): stats['__comb__'] += 1 # don't count input or output towards comb stats['__seq__'] = stats['__dff__'] + stats['__latch__'] return dict(stats) @@ -581,24 +581,23 @@ class Circuit: if line is not None: yield line - def reversed_topological_order(self): + def reversed_topological_order(self, tlib: 'TechLib'): # type: ignore """Generator function to iterate over all nodes in reversed topological order. - Nodes without output lines and nodes whose :py:attr:`Node.kind` contains the - substrings 'dff' or 'latch' are yielded first. + Nodes without output lines and sequential nodes (flip-flops, latches) are yielded first. """ visit_count = [0] * len(self.nodes) - queue = deque(n for n in self.nodes if len(n.outs) == 0 or 'dff' in n.kind.lower() or 'latch' in n.kind.lower()) + queue = deque(n for n in self.nodes if len(n.outs) == 0 or tlib.is_dff(n.kind) or tlib.is_latch(n.kind)) while len(queue) > 0: n = queue.popleft() for line in n.ins: pred = line.driver visit_count[pred] += 1 - if visit_count[pred] == len(pred.outs) and 'dff' not in pred.kind.lower() and 'latch' not in pred.kind.lower(): + if visit_count[pred] == len(pred.outs) and not tlib.is_dff(pred.kind) and not tlib.is_latch(pred.kind): queue.append(pred) yield n - def fanin(self, origin_nodes): + def fanin(self, origin_nodes, tlib: 'TechLib'): # type: ignore """Generator function to iterate over the fan-in cone of a given list of origin nodes. Nodes are yielded in reversed topological order. @@ -606,11 +605,10 @@ class Circuit: marks = [False] * len(self.nodes) for n in origin_nodes: marks[n] = True - for n in self.reversed_topological_order(): + for n in self.reversed_topological_order(tlib): if not marks[n]: - for line in n.outs: - if line is not None: - marks[n] |= marks[line.reader] + for line in n.outs.without_nones(): + marks[n] |= marks[line.reader] if marks[n]: yield n