Skip to content

Commit

Permalink
[Sim][#54] Node groups to know their gates.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Jun 18, 2023
1 parent 9b12851 commit c5e3ba6
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions tests/z80sim/z80sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1430,21 +1428,18 @@ 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:
# No further propagation is necessary if the state of
# 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:
Expand All @@ -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:
Expand Down

0 comments on commit c5e3ba6

Please sign in to comment.