Skip to content

Commit

Permalink
build: get list of used I/O ports from Design.
Browse files Browse the repository at this point in the history
Fixes #1365.
  • Loading branch information
wanda-phi authored and whitequark committed Jun 14, 2024
1 parent 86fdaba commit 66ad0a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
14 changes: 11 additions & 3 deletions amaranth/build/plat.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self):
self.extra_files = OrderedDict()

self._prepared = False
self._design = None

@property
def default_clk_constraint(self):
Expand Down Expand Up @@ -148,9 +149,16 @@ def missing_domain_error(name):
buffer = DomainLowerer()(buffer)
fragment.add_subfragment(buffer, name=f"pin_{pin.name}")

ports = [(port.name, port, None) for port in self.iter_ports()]
design = Design(fragment, ports, hierarchy=(name,))
return self.toolchain_prepare(design, name, **kwargs)
self._design = Design(fragment, [], hierarchy=(name,))
return self.toolchain_prepare(self._design, name, **kwargs)

def iter_port_constraints_bits(self):
for (name, port, _dir) in self._design.ports:
if len(port) == 1:
yield name, port.metadata[0].name, port.metadata[0].attrs
else:
for bit, meta in enumerate(port.metadata):
yield f"{name}[{bit}]", meta.name, meta.attrs

@abstractmethod
def toolchain_prepare(self, fragment, name, **kwargs):
Expand Down
15 changes: 0 additions & 15 deletions amaranth/build/res.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ def __init__(self, resources, connectors):
self.connectors = OrderedDict()
self._conn_pins = OrderedDict()

# List of all IOPort instances created
self._ports = []
# List of (pin, port, buffer) pairs for non-dir="-" requests.
self._pins = []
# Constraint list
Expand Down Expand Up @@ -220,7 +218,6 @@ def resolve(resource, dir, xdr, path, attrs):
PortMetadata(name, attrs)
for name in phys_names
])
self._ports.append(iop)
port = io.SingleEndedPort(iop, invert=phys.invert, direction=direction)
if isinstance(phys, DiffPairs):
phys_names_p = phys.p.map_names(self._conn_pins, resource)
Expand All @@ -234,7 +231,6 @@ def resolve(resource, dir, xdr, path, attrs):
PortMetadata(name, attrs)
for name in phys_names_n
])
self._ports += [p, n]
port = io.DifferentialPort(p, n, invert=phys.invert, direction=direction)

for phys_name in phys_names:
Expand Down Expand Up @@ -274,17 +270,6 @@ def resolve(resource, dir, xdr, path, attrs):
def iter_pins(self):
yield from self._pins

def iter_ports(self):
yield from self._ports

def iter_port_constraints_bits(self):
for port in self._ports:
if len(port) == 1:
yield port.name, port.metadata[0].name, port.metadata[0].attrs
else:
for bit, meta in enumerate(port.metadata):
yield f"{port.name}[{bit}]", meta.name, meta.attrs

def add_clock_constraint(self, clock, frequency):
if isinstance(clock, ClockSignal):
raise TypeError(f"A clock constraint can only be applied to a Signal, but a "
Expand Down

0 comments on commit 66ad0a2

Please sign in to comment.