From 4204e764950fe5429ffd1e7417b288a5aff6d025 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 18 Dec 2018 20:02:32 +0000 Subject: [PATCH] compat: add wrappers for Slice.stop, Cat.l, _ArrayProxy.choices. --- nmigen/compat/fhdl/structure.py | 26 ++++++++++++++++++++++++-- nmigen/tools.py | 10 ++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/nmigen/compat/fhdl/structure.py b/nmigen/compat/fhdl/structure.py index c00f033..c0cf3cf 100644 --- a/nmigen/compat/fhdl/structure.py +++ b/nmigen/compat/fhdl/structure.py @@ -1,8 +1,9 @@ from collections import OrderedDict -from ...tools import deprecated +from ...tools import deprecated, extend from ...hdl import ast -from ...hdl.ast import (DUID, Value, Signal, Mux, Cat, Repl, Const, C, ClockSignal, ResetSignal, +from ...hdl.ast import (DUID, Value, Signal, Mux, Slice as _Slice, Cat, Repl, Const, C, + ClockSignal, ResetSignal, Array, ArrayProxy as _ArrayProxy) from ...hdl.cd import ClockDomain @@ -17,6 +18,20 @@ def wrap(v): return Value.wrap(v) +@extend(_Slice) +@property +@deprecated("instead of `_Slice.stop`, use `Slice.end`") +def stop(self): + return self.end + + +@extend(Cat) +@property +@deprecated("instead of `Cat.l`, use `Cat.parts`") +def l(self): + return self.parts + + @deprecated("instead of `Replicate`, use `Repl`") def Replicate(v, n): return Repl(v, n) @@ -27,6 +42,13 @@ def Constant(value, bits_sign=None): return Const(value, bits_sign) +@extend(_ArrayProxy) +@property +@deprecated("instead `_ArrayProxy.choices`, use `ArrayProxy.elems`") +def choices(self): + return self.elems + + class If(ast.Switch): @deprecated("instead of `If(cond, ...)`, use `with m.If(cond): ...`") def __init__(self, cond, *stmts): diff --git a/nmigen/tools.py b/nmigen/tools.py index 1f03180..0cdbbce 100644 --- a/nmigen/tools.py +++ b/nmigen/tools.py @@ -52,3 +52,13 @@ def deprecated(message, stacklevel=2): return f(*args, **kwargs) return wrapper return decorator + + +def extend(cls): + def decorator(f): + if isinstance(f, property): + name = f.fget.__name__ + else: + name = f.__name__ + setattr(cls, name, f) + return decorator -- 2.30.2