compat: add wrappers for Slice.stop, Cat.l, _ArrayProxy.choices.

This commit is contained in:
whitequark 2018-12-18 20:02:32 +00:00
parent dbbcc49a71
commit a90748303c
2 changed files with 34 additions and 2 deletions

View file

@ -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):

View file

@ -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