This notebook shows the various features for inspecting circuits using str
and repr
.
In [1]:
import magma as m
m.set_mantle_target("ice40")
In [2]:
import mantle
Logic2 = m.DefineCircuit('Logic2', 'I0', m.In(m.Bit), 'I1', m.In(m.Bit), 'O', m.Out(m.Bit))
m.wire((Logic2.I0 & Logic2.I1) ^ 1, Logic2.O)
m.EndCircuit()
Calling print on a circuit definition, call str
.
str
returns the type signature of the circuit.
In [3]:
print(Logic2)
Calling repr
on the circuit returns a python code snippet that could
be executed to recreate the circuit.
In [4]:
print(repr(Logic2))
Here's an example of introspecting the circuit definition instances. We can iterate over the instances
attribute of the circuit to get access to each instance. Then, we can print the instance out to get a debug string. We can also iterate over the IO.ports
dictionary to get the name and type of each port
In [5]:
for inst in Logic2.instances:
print(f"Instance={inst}")
print(" ports=")
for name, type_ in inst.IO.ports.items():
print(f" {name}: {type_}")
In [ ]: