From 97615337ee4a919e5d77032fccd8b96d80a1b2d5 Mon Sep 17 00:00:00 2001 From: Catherine Date: Wed, 25 Jun 2025 11:21:48 +0000 Subject: [PATCH 1/2] lib.io: fix type check in `io.Buffer.elaborate`. Before this commit, the elaboration would access `self._port.invert`, which may not be present on custom `PortLike`s. --- amaranth/lib/io.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/amaranth/lib/io.py b/amaranth/lib/io.py index c2bc59a10..7c09eea55 100644 --- a/amaranth/lib/io.py +++ b/amaranth/lib/io.py @@ -587,6 +587,8 @@ def direction(self): def elaborate(self, platform): if hasattr(platform, "get_io_buffer"): return platform.get_io_buffer(self) + elif not isinstance(self._port, (SingleEndedPort, DifferentialPort, SimulationPort)): + raise TypeError("Cannot elaborate generic 'Buffer' with port {self._port!r}") # :nocov: m = Module() @@ -632,8 +634,6 @@ def elaborate(self, platform): if self.direction in (Direction.Output, Direction.Bidir): m.d.comb += self._port.o.eq(o_inv) m.d.comb += self._port.oe.eq(self.oe.replicate(len(self._port))) - else: - raise TypeError("Cannot elaborate generic 'Buffer' with port {self._port!r}") # :nocov: return m From 6a5164de3cfe6b5c23006c05e1dd4008c039f89c Mon Sep 17 00:00:00 2001 From: Catherine Date: Wed, 25 Jun 2025 11:25:29 +0000 Subject: [PATCH 2/2] lib.io: document `platform.get_io_buffer()` override. --- amaranth/lib/io.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/amaranth/lib/io.py b/amaranth/lib/io.py index 7c09eea55..c7a4bc2f0 100644 --- a/amaranth/lib/io.py +++ b/amaranth/lib/io.py @@ -518,6 +518,11 @@ class Buffer(wiring.Component): ---------- signature : :class:`Buffer.Signature` :py:`Signature(direction, len(port)).flip()`. + + Platform overrides + ------------------ + Define the :py:`get_io_buffer()` platform method to override the implementation of + :class:`Buffer`, e.g. to instantiate library cells directly. """ class Signature(wiring.Signature): """Signature of a combinational I/O buffer. @@ -690,6 +695,11 @@ class FFBuffer(wiring.Component): ---------- signature : :class:`FFBuffer.Signature` :py:`Signature(direction, len(port)).flip()`. + + Platform overrides + ------------------ + Define the :py:`get_io_buffer()` platform method to override the implementation of + :class:`FFBuffer`, e.g. to instantiate library cells directly. """ class Signature(wiring.Signature): """Signature of a registered I/O buffer. @@ -898,6 +908,11 @@ class DDRBuffer(wiring.Component): ---------- signature : :class:`DDRBuffer.Signature` :py:`Signature(direction, len(port)).flip()`. + + Platform overrides + ------------------ + Define the :py:`get_io_buffer()` platform method to override the implementation of + :class:`DDRBuffer`, e.g. to instantiate library cells directly. """ class Signature(wiring.Signature): """Signature of a double data rate I/O buffer.