Skip to content

Commit

Permalink
Sort instances during repr
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Apr 27, 2019
1 parent f4ae6ca commit 1e87228
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions magma/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ def __repr__(cls):
if hasattr(cls,"instances"):
s = '{} = DefineCircuit("{}", {})\n'.format(name, name, args)

sorted_instances = sorted(cls.instances, key=lambda x : x.name)
# emit instances
for instance in cls.instances:
for instance in sorted_instances:
s += repr(instance) + '\n'

# emit wires from instances
for instance in cls.instances:
for instance in sorted_instances:
s += repr(instance.interface)

# for input in cls.interface.inputs():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_circuit/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def test_str_repr():
print(repr(Logic2))
assert repr(Logic2) == """\
Logic2 = DefineCircuit("Logic2", "I0", In(Bit), "I1", In(Bit), "O", Out(Bit))
XOr2_inst0 = XOr2()
And2_inst0 = And2()
wire(And2_inst0.O, XOr2_inst0.I0)
wire(1, XOr2_inst0.I1)
XOr2_inst0 = XOr2()
wire(Logic2.I0, And2_inst0.I0)
wire(Logic2.I1, And2_inst0.I1)
wire(And2_inst0.O, XOr2_inst0.I0)
wire(1, XOr2_inst0.I1)
wire(XOr2_inst0.O, Logic2.O)
EndCircuit()\
"""
Expand Down

0 comments on commit 1e87228

Please sign in to comment.