add redirection of __Assign__ to allow overrides for advanced behaviour
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 27 Sep 2021 19:47:56 +0000 (20:47 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 27 Sep 2021 19:47:56 +0000 (20:47 +0100)
without changing fundamental language characteristics or semantics of nmigen
https://bugs.libre-soc.org/show_bug.cgi?id=458

nmigen/hdl/ast.py
nmigen/hdl/dsl.py
nmigen/hdl/xfrm.py

index d6944d23ae3627a6007f6a97824505a70cce3095..227bf604983c5a24a29c6e002861cfe0982d1b08 100644 (file)
@@ -15,7 +15,7 @@ __all__ = [
     "Shape", "signed", "unsigned",
     "Value", "Const", "C", "AnyConst", "AnySeq", "Operator", "Mux", "Part", "Slice", "Cat", "Repl",
     "Array", "ArrayProxy",
-    "_InternalSwitch",
+    "_InternalSwitch", "_InternalAssign",
     "Signal", "ClockSignal", "ResetSignal",
     "UserValue", "ValueCastable",
     "Sample", "Past", "Stable", "Rose", "Fell", "Initial",
@@ -159,6 +159,9 @@ class Value(metaclass=ABCMeta):
                                src_loc_at=src_loc_at,
                                case_src_locs=case_src_locs)
 
+    def __Assign__(self, rhs, *, src_loc_at=0):
+        return _InternalAssign(self, rhs, src_loc_at=src_loc_at)
+
     def __bool__(self):
         raise TypeError("Attempted to convert nMigen value to Python boolean")
 
@@ -1430,7 +1433,11 @@ class Statement:
 
 
 @final
-class Assign(Statement):
+def Assign(lhs, rhs, *, src_loc_at=0):
+    return lhs.__Assign__(rhs, src_loc_at=src_loc_at)
+
+
+class _InternalAssign(Statement):
     def __init__(self, lhs, rhs, *, src_loc_at=0):
         super().__init__(src_loc_at=src_loc_at)
         self.lhs = Value.cast(lhs)
index 564d8b8aed62a7f87bf3d37e4bd7b6fef46a18bc..c4473692b9c1d3c37a9fd27939eea64999dd1c26 100644 (file)
@@ -484,7 +484,7 @@ class Module(_ModuleBuilderRoot, Elaboratable):
             self._pop_ctrl()
 
         for stmt in Statement.cast(assigns):
-            if not compat_mode and not isinstance(stmt, (Assign, Assert, Assume, Cover)):
+            if not compat_mode and not isinstance(stmt, (_InternalAssign, Assert, Assume, Cover)):
                 raise SyntaxError(
                     "Only assignments and property checks may be appended to d.{}"
                     .format(domain_name(domain)))
index 7cf142ad9d6d934c253a0fc910f407858260e462..9c527e0dd7233ba31737126c0bf3e8b12a4419ad 100644 (file)
@@ -205,7 +205,7 @@ class StatementVisitor(metaclass=ABCMeta):
         return True
 
     def on_statement(self, stmt):
-        if type(stmt) is Assign:
+        if type(stmt) is _InternalAssign:
             new_stmt = self.on_Assign(stmt)
         elif type(stmt) is Assert:
             new_stmt = self.on_Assert(stmt)