Skip to content

Commit

Permalink
[Sim][#51] Nodes to know their groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Jun 12, 2023
1 parent 6de5a76 commit da658b6
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tests/z80sim/z80sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,8 @@ def __init__(self, index, pull, *, custom_id=None, state=None):
self.gate_of = []
self.conn_of = []

self.group = None

def __repr__(self):
return self.id

Expand Down Expand Up @@ -1309,25 +1311,24 @@ def __identify_group_of(self, n):
return sorted(group)

def __identify_groups(self):
self.__groups = {}
for n in self.__nodes.values():
if n in self.__groups:
if n.group is not None:
continue

group = self.__identify_group_of(n)
for m in group:
self.__groups[m] = group
m.group = group

assert self.__gnd not in self.__groups
assert self.__pwr not in self.__groups
assert self.__gnd.group is None
assert self.__pwr.group is None

for t in self.__trans.values():
if t.c1.is_gnd_or_pwr:
assert not t.c2.is_gnd_or_pwr
elif t.c2.is_gnd_or_pwr:
assert not t.c1.is_gnd_or_pwr
else:
assert self.__groups[t.c1] is self.__groups[t.c2]
assert t.c1.group is t.c2.group

def __get_node_preds(self, n):
def get_group_pred(n, get_node_pred, stack, preds):
Expand Down Expand Up @@ -1400,11 +1401,9 @@ def get_pulldown_pred(n):
return gnd, pwr, pullup, pulldown

def __update_group_of(self, n, next_round_nodes, updated):
group = self.__groups[n]

# Update node and transistor states.
for i, n in enumerate(group):
with Status.do(f'update {i}/{len(group)} {n}', '--show-nodes'):
for i, n in enumerate(n.group):
with Status.do(f'update {i}/{len(n.group)} {n}', '--show-nodes'):
assert not n.is_gnd_or_pwr
gnd, pwr, pullup, pulldown = self.__get_node_preds(n)

Expand Down

0 comments on commit da658b6

Please sign in to comment.