From: Luke Kenneth Casson Leighton Date: Mon, 27 Sep 2021 19:47:56 +0000 (+0100) Subject: add redirection of __Assign__ to allow overrides for advanced behaviour X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6a66c8a2283f031dbc7aec12bbf7b5b708e66469;p=nmigen.git add redirection of __Assign__ to allow overrides for advanced behaviour without changing fundamental language characteristics or semantics of nmigen https://bugs.libre-soc.org/show_bug.cgi?id=458 --- diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index d6944d2..227bf60 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -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) diff --git a/nmigen/hdl/dsl.py b/nmigen/hdl/dsl.py index 564d8b8..c447369 100644 --- a/nmigen/hdl/dsl.py +++ b/nmigen/hdl/dsl.py @@ -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))) diff --git a/nmigen/hdl/xfrm.py b/nmigen/hdl/xfrm.py index 7cf142a..9c527e0 100644 --- a/nmigen/hdl/xfrm.py +++ b/nmigen/hdl/xfrm.py @@ -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)