diff --git a/amaranth/lib/io.py b/amaranth/lib/io.py index 2a179ec..09058d2 100644 --- a/amaranth/lib/io.py +++ b/amaranth/lib/io.py @@ -114,6 +114,10 @@ class Pin(wiring.PureInterface): self.dir == other.dir and self.xdr == other.xdr) + def __repr__(self): + xdr = f", xdr={self.xdr}" if self.xdr != 0 else "" + return f"Pin.Signature({self.width}, dir={self.dir!r}{xdr})" + def create(self, *, path=None, src_loc_at=0): return Pin(self.width, self.dir, xdr=self.xdr, path=path, src_loc_at=1 + src_loc_at) @@ -128,11 +132,11 @@ class Pin(wiring.PureInterface): @property def width(self): return self.signature.width - + @property def dir(self): return self.signature.dir - + @property def xdr(self): return self.signature.xdr diff --git a/tests/test_lib_io.py b/tests/test_lib_io.py index ae41c07..1c82b1f 100644 --- a/tests/test_lib_io.py +++ b/tests/test_lib_io.py @@ -199,6 +199,16 @@ class PinSignatureDDRTestCase(PinSignatureTestCase): }) +class PinSignatureReprCase(FHDLTestCase): + def test_repr(self): + sig_0 = Pin.Signature(1, dir="i") + self.assertRepr(sig_0, "Pin.Signature(1, dir='i')") + sig_0 = Pin.Signature(2, dir="o", xdr=1) + self.assertRepr(sig_0, "Pin.Signature(2, dir='o', xdr=1)") + sig_0 = Pin.Signature(3, dir="io", xdr=2) + self.assertRepr(sig_0, "Pin.Signature(3, dir='io', xdr=2)") + + class PinTestCase(FHDLTestCase): def test_attributes(self): pin = Pin(2, dir="io", xdr=2) @@ -208,4 +218,3 @@ class PinTestCase(FHDLTestCase): self.assertEqual(pin.signature.width, 2) self.assertEqual(pin.signature.dir, "io") self.assertEqual(pin.signature.xdr, 2) -