From ec7fcd369733aca520c83c6cee64a50edf3eca8d Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 8 Jul 2019 09:57:14 +0000 Subject: [PATCH] hdl.xfrm: don't overwrite source locations on ClockDomain signals. On the sample of examples/basic/*.py, there are no remaining incorrectly inferred locations. --- nmigen/hdl/xfrm.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nmigen/hdl/xfrm.py b/nmigen/hdl/xfrm.py index 05479ea..9448c0c 100644 --- a/nmigen/hdl/xfrm.py +++ b/nmigen/hdl/xfrm.py @@ -81,6 +81,9 @@ class ValueVisitor(metaclass=ABCMeta): def on_unknown_value(self, value): raise TypeError("Cannot transform value '{!r}'".format(value)) # :nocov: + def replace_value_src_loc(self, value, new_value): + return True + def on_value(self, value): if type(value) is Const: new_value = self.on_Const(value) @@ -117,7 +120,7 @@ class ValueVisitor(metaclass=ABCMeta): new_value = self.on_value(value._lazy_lower()) else: new_value = self.on_unknown_value(value) - if isinstance(new_value, Value): + if isinstance(new_value, Value) and self.replace_value_src_loc(value, new_value): new_value.src_loc = value.src_loc return new_value @@ -194,6 +197,9 @@ class StatementVisitor(metaclass=ABCMeta): def on_unknown_statement(self, stmt): raise TypeError("Cannot transform statement '{!r}'".format(stmt)) # :nocov: + def replace_statement_src_loc(self, stmt, new_stmt): + return True + def on_statement(self, stmt): if type(stmt) is Assign: new_stmt = self.on_Assign(stmt) @@ -208,7 +214,7 @@ class StatementVisitor(metaclass=ABCMeta): new_stmt = self.on_statements(stmt) else: new_stmt = self.on_unknown_statement(stmt) - if isinstance(new_stmt, Statement): + if isinstance(new_stmt, Statement) and self.replace_statement_src_loc(stmt, new_stmt): new_stmt.src_loc = stmt.src_loc return new_stmt @@ -365,6 +371,9 @@ class DomainLowerer(FragmentTransformer, ValueTransformer, StatementTransformer) for domain, signal in fragment.iter_drivers(): new_fragment.add_driver(self.on_value(signal), domain) + def replace_value_src_loc(self, value, new_value): + return not isinstance(value, (ClockSignal, ResetSignal)) + def on_ClockSignal(self, value): cd = self._resolve(value.domain, value) return cd.clk -- 2.30.2