From c5e3ba647dd7a1341babc6652bc9405be8346784 Mon Sep 17 00:00:00 2001 From: Ivan Kosarev Date: Sun, 18 Jun 2023 09:07:41 +0100 Subject: [PATCH] [Sim][#54] Node groups to know their gates. --- tests/z80sim/z80sim.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/z80sim/z80sim.py b/tests/z80sim/z80sim.py index 6ff1246..c1f03ab 100755 --- a/tests/z80sim/z80sim.py +++ b/tests/z80sim/z80sim.py @@ -1019,10 +1019,8 @@ def is_pin(self): class NodeGroup(object): def __init__(self, nodes): - self.__nodes = tuple(sorted(nodes)) - - def __iter__(self): - yield from self.__nodes + self.nodes = tuple(sorted(nodes)) + self.gates = tuple(n for n in self.nodes if len(n.gate_of) > 0) class Transistor(object): @@ -1326,7 +1324,7 @@ def __identify_groups(self): continue group = self.__identify_group_of(n) - for m in group: + for m in group.nodes: m.group = group assert self.__gnd.group is None @@ -1430,11 +1428,6 @@ def get_node_state(self, n): def __update_node(self, n, next_round_groups): assert not n.is_gnd_or_pwr - - # TODO: Groups should comprise of gates, not nodes. - if len(n.gate_of) == 0: - return - state = self.get_node_state(n) for t in n.gate_of: @@ -1442,9 +1435,11 @@ def __update_node(self, n, next_round_groups): # the transistor is known to be same. This includes # the case of a floating gate. if state.is_equiv(t.state): - # Choose the simplest of the two equivalent states. + # Use the simplest of the two equivalent states. if state.size < t.state.size: t.state = state + else: + state = t.state else: t.state = state if t.conns_group not in next_round_groups: @@ -1467,7 +1462,7 @@ def __update_groups_of(self, nodes, *, shuffle=True): round += 1 assert round < 100, 'Loop encountered!' - nodes = sum((tuple(g) for g in groups), start=()) + nodes = sum((g.gates for g in groups), start=()) assert len(nodes) == len(set(nodes)) if shuffle: