@@ -173,15 +173,15 @@ class ShapeCastable:
173
173
174
174
.. code::
175
175
176
- value_like = Signal(shape_castable, reset =initializer)
176
+ value_like = Signal(shape_castable, init =initializer)
177
177
178
178
The code above is equivalent to:
179
179
180
180
.. code::
181
181
182
182
value_like = shape_castable(Signal(
183
183
shape_castable.as_shape(),
184
- reset =shape_castable.const(initializer)
184
+ init =shape_castable.const(initializer)
185
185
))
186
186
187
187
Note that the :py:`shape_castable(x)` syntax performs :py:`shape_castable.__call__(x)`.
@@ -1731,15 +1731,15 @@ class Signal(Value, DUID, metaclass=_SignalMeta):
1731
1731
name : str
1732
1732
Name hint for this signal. If ``None`` (default) the name is inferred from the variable
1733
1733
name this ``Signal`` is assigned to.
1734
- reset : int or integral Enum
1734
+ init : int or integral Enum
1735
1735
Reset (synchronous) or default (combinatorial) value.
1736
1736
When this ``Signal`` is assigned to in synchronous context and the corresponding clock
1737
1737
domain is reset, the ``Signal`` assumes the given value. When this ``Signal`` is unassigned
1738
1738
in combinatorial context (due to conditional assignments not being taken), the ``Signal``
1739
- assumes its ``reset `` value. Defaults to 0.
1739
+ assumes its ``init `` value. Defaults to 0.
1740
1740
reset_less : bool
1741
1741
If ``True``, do not generate reset logic for this ``Signal`` in synchronous statements.
1742
- The ``reset `` value is only used as a combinatorial default or as the initial value.
1742
+ The ``init `` value is only used as a combinatorial default or as the initial value.
1743
1743
Defaults to ``False``.
1744
1744
attrs : dict
1745
1745
Dictionary of synthesis attributes.
@@ -1754,13 +1754,13 @@ class Signal(Value, DUID, metaclass=_SignalMeta):
1754
1754
width : int
1755
1755
signed : bool
1756
1756
name : str
1757
- reset : int
1757
+ init : int
1758
1758
reset_less : bool
1759
1759
attrs : dict
1760
1760
decoder : function
1761
1761
"""
1762
1762
1763
- def __init__ (self , shape = None , * , name = None , reset = None , reset_less = False ,
1763
+ def __init__ (self , shape = None , * , name = None , init = None , reset = None , reset_less = False ,
1764
1764
attrs = None , decoder = None , src_loc_at = 0 ):
1765
1765
super ().__init__ (src_loc_at = src_loc_at )
1766
1766
@@ -1776,53 +1776,61 @@ def __init__(self, shape=None, *, name=None, reset=None, reset_less=False,
1776
1776
self .width = shape .width
1777
1777
self .signed = shape .signed
1778
1778
1779
- orig_reset = reset
1779
+ # TODO(amaranth-0.7): remove
1780
+ if reset is not None :
1781
+ if init is not None :
1782
+ raise ValueError ("Cannot specify both `reset` and `init`" )
1783
+ warnings .warn ("`reset=` is deprecated, use `init=` instead" ,
1784
+ DeprecationWarning , stacklevel = 2 )
1785
+ init = reset
1786
+
1787
+ orig_init = init
1780
1788
if isinstance (orig_shape , ShapeCastable ):
1781
1789
try :
1782
- reset = Const .cast (orig_shape .const (reset ))
1790
+ init = Const .cast (orig_shape .const (init ))
1783
1791
except Exception :
1784
- raise TypeError ("Reset value must be a constant initializer of {!r}"
1792
+ raise TypeError ("Initial value must be a constant initializer of {!r}"
1785
1793
.format (orig_shape ))
1786
- if reset .shape () != Shape .cast (orig_shape ):
1794
+ if init .shape () != Shape .cast (orig_shape ):
1787
1795
raise ValueError ("Constant returned by {!r}.const() must have the shape that "
1788
1796
"it casts to, {!r}, and not {!r}"
1789
1797
.format (orig_shape , Shape .cast (orig_shape ),
1790
- reset .shape ()))
1798
+ init .shape ()))
1791
1799
else :
1792
- if reset is None :
1793
- reset = 0
1800
+ if init is None :
1801
+ init = 0
1794
1802
try :
1795
- reset = Const .cast (reset )
1803
+ init = Const .cast (init )
1796
1804
except TypeError :
1797
- raise TypeError ("Reset value must be a constant-castable expression, not {!r}"
1798
- .format (orig_reset ))
1805
+ raise TypeError ("Initial value must be a constant-castable expression, not {!r}"
1806
+ .format (orig_init ))
1799
1807
# Avoid false positives for all-zeroes and all-ones
1800
- if orig_reset is not None and not (isinstance (orig_reset , int ) and orig_reset in (0 , - 1 )):
1801
- if reset .shape ().signed and not self .signed :
1808
+ if orig_init is not None and not (isinstance (orig_init , int ) and orig_init in (0 , - 1 )):
1809
+ if init .shape ().signed and not self .signed :
1802
1810
warnings .warn (
1803
- message = "Reset value {!r} is signed, but the signal shape is {!r}"
1804
- .format (orig_reset , shape ),
1811
+ message = "Initial value {!r} is signed, but the signal shape is {!r}"
1812
+ .format (orig_init , shape ),
1805
1813
category = SyntaxWarning ,
1806
1814
stacklevel = 2 )
1807
- elif (reset .shape ().width > self .width or
1808
- reset .shape ().width == self .width and
1809
- self .signed and not reset .shape ().signed ):
1815
+ elif (init .shape ().width > self .width or
1816
+ init .shape ().width == self .width and
1817
+ self .signed and not init .shape ().signed ):
1810
1818
warnings .warn (
1811
- message = "Reset value {!r} will be truncated to the signal shape {!r}"
1812
- .format (orig_reset , shape ),
1819
+ message = "Initial value {!r} will be truncated to the signal shape {!r}"
1820
+ .format (orig_init , shape ),
1813
1821
category = SyntaxWarning ,
1814
1822
stacklevel = 2 )
1815
- self .reset = reset .value
1823
+ self .init = init .value
1816
1824
self .reset_less = bool (reset_less )
1817
1825
1818
- if isinstance (orig_shape , range ) and orig_reset is not None and orig_reset not in orig_shape :
1819
- if orig_reset == orig_shape .stop :
1826
+ if isinstance (orig_shape , range ) and orig_init is not None and orig_init not in orig_shape :
1827
+ if orig_init == orig_shape .stop :
1820
1828
raise SyntaxError (
1821
- f"Reset value { orig_reset !r} equals the non-inclusive end of the signal "
1829
+ f"Initial value { orig_init !r} equals the non-inclusive end of the signal "
1822
1830
f"shape { orig_shape !r} ; this is likely an off-by-one error" )
1823
1831
else :
1824
1832
raise SyntaxError (
1825
- f"Reset value { orig_reset !r} is not within the signal shape { orig_shape !r} " )
1833
+ f"Initial value { orig_init !r} is not within the signal shape { orig_shape !r} " )
1826
1834
1827
1835
self .attrs = OrderedDict (() if attrs is None else attrs )
1828
1836
@@ -1850,6 +1858,18 @@ def __init__(self, shape=None, *, name=None, reset=None, reset_less=False,
1850
1858
# Any other case is formatted as a plain integer.
1851
1859
self ._value_repr = (Repr (FormatInt (), self ),)
1852
1860
1861
+ @property
1862
+ def reset (self ):
1863
+ warnings .warn ("`Signal.reset` is deprecated, use `Signal.init` instead" ,
1864
+ DeprecationWarning , stacklevel = 2 )
1865
+ return self .init
1866
+
1867
+ @reset .setter
1868
+ def reset (self , value ):
1869
+ warnings .warn ("`Signal.reset` is deprecated, use `Signal.init` instead" ,
1870
+ DeprecationWarning , stacklevel = 2 )
1871
+ self .init = value
1872
+
1853
1873
@property
1854
1874
def decoder (self ):
1855
1875
return self ._decoder
@@ -1873,7 +1893,7 @@ def enum_decoder(value):
1873
1893
self ._decoder = enum_decoder
1874
1894
1875
1895
@classmethod
1876
- def like (cls , other , * , name = None , name_suffix = None , src_loc_at = 0 , ** kwargs ):
1896
+ def like (cls , other , * , name = None , name_suffix = None , init = None , reset = None , src_loc_at = 0 , ** kwargs ):
1877
1897
"""Create Signal based on another.
1878
1898
1879
1899
Parameters
@@ -1887,15 +1907,24 @@ def like(cls, other, *, name=None, name_suffix=None, src_loc_at=0, **kwargs):
1887
1907
new_name = other .name + str (name_suffix )
1888
1908
else :
1889
1909
new_name = tracer .get_var_name (depth = 2 + src_loc_at , default = "$like" )
1910
+ # TODO(amaranth-0.7): remove
1911
+ if reset is not None :
1912
+ if init is not None :
1913
+ raise ValueError ("Cannot specify both `reset` and `init`" )
1914
+ warnings .warn ("`reset=` is deprecated, use `init=` instead" ,
1915
+ DeprecationWarning , stacklevel = 2 )
1916
+ init = reset
1890
1917
if isinstance (other , ValueCastable ):
1891
1918
shape = other .shape ()
1892
1919
else :
1893
1920
shape = Value .cast (other ).shape ()
1894
1921
kw = dict (shape = shape , name = new_name )
1895
1922
if isinstance (other , Signal ):
1896
- kw .update (reset = other .reset , reset_less = other .reset_less ,
1923
+ kw .update (init = other .init , reset_less = other .reset_less ,
1897
1924
attrs = other .attrs , decoder = other .decoder )
1898
1925
kw .update (kwargs )
1926
+ if init is not None :
1927
+ kw ["init" ] = init
1899
1928
return cls (** kw , src_loc_at = 1 + src_loc_at )
1900
1929
1901
1930
def shape (self ):
0 commit comments