Remove everything deprecated in nmigen 0.1.

Closes #275.
This commit is contained in:
whitequark 2020-01-12 13:59:26 +00:00
parent e4e26717be
commit e18385b613
13 changed files with 208 additions and 240 deletions

View file

@ -5,8 +5,7 @@ from .cd import ClockDomain
from .ir import Elaboratable, Fragment, Instance
from .mem import Memory
from .rec import Record
from .xfrm import DomainRenamer, ResetInserter, EnableInserter, \
CEInserter # TODO(nmigen-0.2): remove this
from .xfrm import DomainRenamer, ResetInserter, EnableInserter
__all__ = [
@ -18,5 +17,4 @@ __all__ = [
"Memory",
"Record",
"DomainRenamer", "ResetInserter", "EnableInserter",
"CEInserter", # TODO(nmigen-0.2): remove this
]

View file

@ -1,5 +1,4 @@
from abc import ABCMeta, abstractmethod
import builtins
import traceback
import warnings
import typing
@ -124,12 +123,6 @@ class Value(metaclass=ABCMeta):
return Const(obj.value, Shape.cast(type(obj)))
raise TypeError("Object {!r} cannot be converted to an nMigen value".format(obj))
# TODO(nmigen-0.2): remove this
@classmethod
@deprecated("instead of `Value.wrap`, use `Value.cast`")
def wrap(cls, obj):
return cls.cast(obj)
def __init__(self, *, src_loc_at=0):
super().__init__()
self.src_loc = tracer.get_src_loc(1 + src_loc_at)
@ -281,11 +274,6 @@ class Value(metaclass=ABCMeta):
"""
return ~premise | conclusion
# TODO(nmigen-0.2): move this to nmigen.compat and make it a deprecated extension
@deprecated("instead of `.part`, use `.bit_select`")
def part(self, offset, width):
return Part(self, offset, width, src_loc_at=1)
def bit_select(self, offset, width):
"""Part-select with bit granularity.
@ -471,12 +459,6 @@ class Const(Value):
self.width, self.signed = shape
self.value = self.normalize(self.value, shape)
# TODO(nmigen-0.2): move this to nmigen.compat and make it a deprecated extension
@property
@deprecated("instead of `const.nbits`, use `const.width`")
def nbits(self):
return self.width
def shape(self):
return Shape(self.width, self.signed)
@ -527,12 +509,6 @@ class Operator(Value):
self.operator = operator
self.operands = [Value.cast(op) for op in operands]
# TODO(nmigen-0.2): move this to nmigen.compat and make it a deprecated extension
@property
@deprecated("instead of `.op`, use `.operator`")
def op(self):
return self.operator
def shape(self):
def _bitwise_binary_shape(a_shape, b_shape):
a_bits, a_sign = a_shape
@ -644,13 +620,7 @@ class Slice(Value):
super().__init__(src_loc_at=src_loc_at)
self.value = Value.cast(value)
self.start = start
self.stop = stop
# TODO(nmigen-0.2): remove this
@property
@deprecated("instead of `slice.end`, use `slice.stop`")
def end(self):
return self.stop
self.stop = stop
def shape(self):
return Shape(self.stop - self.start)
@ -782,7 +752,7 @@ class Repl(Value):
return "(repl {!r} {})".format(self.value, self.count)
@final
# @final
class Signal(Value, DUID):
"""A varying integer value.
@ -830,46 +800,22 @@ class Signal(Value, DUID):
attrs : dict
"""
def __init__(self, shape=None, *, name=None, reset=0, reset_less=False, min=None, max=None,
def __init__(self, shape=None, *, name=None, reset=0, reset_less=False,
attrs=None, decoder=None, src_loc_at=0):
super().__init__(src_loc_at=src_loc_at)
if isinstance(reset, Enum):
reset = reset.value
if not isinstance(reset, int):
raise TypeError("Reset value has to be an int or an integral Enum")
# TODO(nmigen-0.2): move this to nmigen.compat and make it a deprecated extension
if min is not None or max is not None:
warnings.warn("instead of `Signal(min={min}, max={max})`, "
"use `Signal(range({min}, {max}))`"
.format(min=min or 0, max=max or 2),
DeprecationWarning, stacklevel=2 + src_loc_at)
if name is not None and not isinstance(name, str):
raise TypeError("Name must be a string, not {!r}".format(name))
self.name = name or tracer.get_var_name(depth=2 + src_loc_at, default="$signal")
if shape is None:
if min is None:
min = 0
if max is None:
max = 2
max -= 1 # make both bounds inclusive
if min > max:
raise ValueError("Lower bound {} should be less or equal to higher bound {}"
.format(min, max + 1))
self.signed = min < 0 or max < 0
if min == max:
self.width = 0
else:
self.width = builtins.max(bits_for(min, self.signed),
bits_for(max, self.signed))
shape = unsigned(1)
self.width, self.signed = Shape.cast(shape, src_loc_at=1 + src_loc_at)
else:
if not (min is None and max is None):
raise ValueError("Only one of bits/signedness or bounds may be specified")
self.width, self.signed = Shape.cast(shape, src_loc_at=1 + src_loc_at)
if isinstance(reset, Enum):
reset = reset.value
if not isinstance(reset, int):
raise TypeError("Reset value has to be an int or an integral Enum")
reset_width = bits_for(reset, self.signed)
if reset != 0 and reset_width > self.width:
@ -878,7 +824,7 @@ class Signal(Value, DUID):
.format(reset, reset_width, self.width),
SyntaxWarning, stacklevel=2 + src_loc_at)
self.reset = int(reset)
self.reset = reset
self.reset_less = bool(reset_less)
self.attrs = OrderedDict(() if attrs is None else attrs)
@ -895,20 +841,9 @@ class Signal(Value, DUID):
else:
self.decoder = decoder
@classmethod
@deprecated("instead of `Signal.range(...)`, use `Signal(range(...))`")
def range(cls, *args, src_loc_at=0, **kwargs):
return cls(range(*args), src_loc_at=2 + src_loc_at, **kwargs)
@classmethod
@deprecated("instead of `Signal.enum(...)`, use `Signal(...)`")
def enum(cls, enum_type, *, src_loc_at=0, **kwargs):
if not issubclass(enum_type, Enum):
raise TypeError("Type {!r} is not an enumeration")
return cls(enum_type, src_loc_at=2 + src_loc_at, **kwargs)
@classmethod
def like(cls, other, *, name=None, name_suffix=None, src_loc_at=0, **kwargs):
# Not a @classmethod because nmigen.compat requires it.
@staticmethod
def like(other, *, name=None, name_suffix=None, src_loc_at=0, **kwargs):
"""Create Signal based on another.
Parameters
@ -922,23 +857,12 @@ class Signal(Value, DUID):
new_name = other.name + str(name_suffix)
else:
new_name = tracer.get_var_name(depth=2 + src_loc_at, default="$like")
kw = dict(shape=cls.cast(other).shape(), name=new_name)
if isinstance(other, cls):
kw = dict(shape=Value.cast(other).shape(), name=new_name)
if isinstance(other, Signal):
kw.update(reset=other.reset, reset_less=other.reset_less,
attrs=other.attrs, decoder=other.decoder)
kw.update(kwargs)
return cls(**kw, src_loc_at=1 + src_loc_at)
# TODO(nmigen-0.2): move this to nmigen.compat and make it a deprecated extension
@property
@deprecated("instead of `signal.nbits`, use `signal.width`")
def nbits(self):
return self.width
@nbits.setter
@deprecated("instead of `signal.nbits = x`, use `signal.width = x`")
def nbits(self, value):
self.width = value
return Signal(**kw, src_loc_at=1 + src_loc_at)
def shape(self):
return Shape(self.width, self.signed)
@ -1269,12 +1193,6 @@ class Statement:
def __init__(self, *, src_loc_at=0):
self.src_loc = tracer.get_src_loc(1 + src_loc_at)
# TODO(nmigen-0.2): remove this
@classmethod
@deprecated("instead of `Statement.wrap`, use `Statement.cast`")
def wrap(cls, obj):
return cls.cast(obj)
@staticmethod
def cast(obj):
if isinstance(obj, Iterable):
@ -1507,7 +1425,7 @@ class ValueKey:
self._hash = hash((self.value.operator,
tuple(ValueKey(o) for o in self.value.operands)))
elif isinstance(self.value, Slice):
self._hash = hash((ValueKey(self.value.value), self.value.start, self.value.end))
self._hash = hash((ValueKey(self.value.value), self.value.start, self.value.stop))
elif isinstance(self.value, Part):
self._hash = hash((ValueKey(self.value.value), ValueKey(self.value.offset),
self.value.width, self.value.stride))
@ -1547,7 +1465,7 @@ class ValueKey:
elif isinstance(self.value, Slice):
return (ValueKey(self.value.value) == ValueKey(other.value.value) and
self.value.start == other.value.start and
self.value.end == other.value.end)
self.value.stop == other.value.stop)
elif isinstance(self.value, Part):
return (ValueKey(self.value.value) == ValueKey(other.value.value) and
ValueKey(self.value.offset) == ValueKey(other.value.offset) and
@ -1606,7 +1524,7 @@ class ValueSet(_MappedKeySet):
class SignalKey:
def __init__(self, signal):
self.signal = signal
if type(signal) is Signal:
if isinstance(signal, Signal):
self._intern = (0, signal.duid)
elif type(signal) is ClockSignal:
self._intern = (1, signal.domain)

View file

@ -24,12 +24,6 @@ class Layout:
return obj
return Layout(obj, src_loc_at=1 + src_loc_at)
# TODO(nmigen-0.2): remove this
@classmethod
@deprecated("instead of `Layout.wrap`, use `Layout.cast`")
def wrap(cls, obj, *, src_loc_at=0):
return cls.cast(obj, src_loc_at=1 + src_loc_at)
def __init__(self, fields, *, src_loc_at=0):
self.fields = OrderedDict()
for field in fields:

View file

@ -18,7 +18,7 @@ __all__ = ["ValueVisitor", "ValueTransformer",
"DomainCollector", "DomainRenamer", "DomainLowerer",
"SampleDomainInjector", "SampleLowerer",
"SwitchCleaner", "LHSGroupAnalyzer", "LHSGroupFilter",
"ResetInserter", "EnableInserter", "CEInserter"]
"ResetInserter", "EnableInserter"]
class ValueVisitor(metaclass=ABCMeta):
@ -95,7 +95,8 @@ class ValueVisitor(metaclass=ABCMeta):
new_value = self.on_AnyConst(value)
elif type(value) is AnySeq:
new_value = self.on_AnySeq(value)
elif type(value) is Signal:
elif isinstance(value, Signal):
# Uses `isinstance()` and not `type() is` because nmigen.compat requires it.
new_value = self.on_Signal(value)
elif isinstance(value, Record):
# Uses `isinstance()` and not `type() is` to allow inheriting from Record.
@ -110,8 +111,7 @@ class ValueVisitor(metaclass=ABCMeta):
new_value = self.on_Slice(value)
elif type(value) is Part:
new_value = self.on_Part(value)
elif isinstance(value, Cat):
# Uses `isinstance()` and not `type() is` because nmigen.compat requires it.
elif type(value) is Cat:
new_value = self.on_Cat(value)
elif type(value) is Repl:
new_value = self.on_Repl(value)
@ -750,7 +750,3 @@ class EnableInserter(_ControlInserter):
en_port = Mux(self.controls[clk_port.domain], en_port, Const(0, len(en_port)))
new_fragment.named_ports["EN"] = en_port, en_dir
return new_fragment
CEInserter = staticmethod(
deprecated("instead of `CEInserter`, use `EnableInserter`")(EnableInserter))