From 3420b683a30f99c85a26b8e849f85622b1df35d7 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 20 May 2020 05:35:47 +0000 Subject: [PATCH] build.plat: skip clock constraints on unused signals. It's not very nice to add more internal mutable state to Platform related classes, but our whole approach for Platform is inherently stateful, and other solutions (like changing every individual vendor platform to check for unused signals) are even worse. Fixes #374. --- nmigen/build/plat.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nmigen/build/plat.py b/nmigen/build/plat.py index 17f147b..523e1ae 100644 --- a/nmigen/build/plat.py +++ b/nmigen/build/plat.py @@ -276,6 +276,15 @@ class TemplatedPlatform(Platform): """, } + def iter_clock_constraints(self): + for net_signal, port_signal, frequency in super().iter_clock_constraints(): + # Skip any clock constraints placed on signals that are never used in the design. + # Otherwise, it will cause a crash in the vendor platform if it supports clock + # constraints on non-port nets. + if net_signal not in self._name_map: + continue + yield net_signal, port_signal, frequency + def toolchain_prepare(self, fragment, name, **kwargs): # Restrict the name of the design to a strict alphanumeric character set. Platforms will # interpolate the name of the design in many different contexts: filesystem paths, Python @@ -292,7 +301,7 @@ class TemplatedPlatform(Platform): # and to incorporate the nMigen version into generated code. autogenerated = "Automatically generated by nMigen {}. Do not edit.".format(__version__) - rtlil_text, name_map = rtlil.convert_fragment(fragment, name=name) + rtlil_text, self._name_map = rtlil.convert_fragment(fragment, name=name) def emit_rtlil(): return rtlil_text @@ -366,7 +375,7 @@ class TemplatedPlatform(Platform): return " ".join(opts) def hierarchy(signal, separator): - return separator.join(name_map[signal][1:]) + return separator.join(self._name_map[signal][1:]) def ascii_escape(string): def escape_one(match): -- 2.30.2