@@ -1972,9 +1972,11 @@ def __init__(self, shape=None, *, name=None, init=None, reset=None, reset_less=F
19721972
19731973 if decoder is not None :
19741974 # The value representation is specified explicitly. Since we do not expose `hdl._repr`,
1975- # this is the only way to add a custom filter to the signal right now. The setter sets
1976- # `self._value_repr` as well as the compatibility `self.decoder`.
1977- pass
1975+ # this is the only way to add a custom filter to the signal right now.
1976+ if isinstance (decoder , type ) and issubclass (decoder , Enum ):
1977+ self ._value_repr = (_repr .Repr (_repr .FormatEnum (decoder ), self ),)
1978+ else :
1979+ self ._value_repr = (_repr .Repr (_repr .FormatCustom (decoder ), self ),)
19781980 else :
19791981 # If it's an enum, expose it via `self.decoder` for compatibility, whether it's a Python
19801982 # enum or an Amaranth enum. This also sets the value representation, even for custom
@@ -1995,20 +1997,16 @@ def __init__(self, shape=None, *, name=None, init=None, reset=None, reset_less=F
19951997 self ._value_repr = (_repr .Repr (_repr .FormatInt (), self ),)
19961998
19971999 # Compute the value representation that will be used by Amaranth.
1998- if decoder is None :
1999- self ._value_repr = (_repr .Repr (_repr .FormatInt (), self ),)
2000- self ._decoder = None
2001- elif not (isinstance (decoder , type ) and issubclass (decoder , Enum )):
2002- self ._value_repr = (_repr .Repr (_repr .FormatCustom (decoder ), self ),)
2003- self ._decoder = decoder
2004- else : # Violence. In the name of backwards compatibility!
2005- self ._value_repr = (_repr .Repr (_repr .FormatEnum (decoder ), self ),)
2000+ if isinstance (decoder , type ) and issubclass (decoder , Enum ):
2001+ # Violence. In the name of backwards compatibility!
20062002 def enum_decoder (value ):
20072003 try :
20082004 return "{0.name:}/{0.value:}" .format (decoder (value ))
20092005 except ValueError :
20102006 return str (value )
20112007 self ._decoder = enum_decoder
2008+ else :
2009+ self ._decoder = decoder
20122010
20132011 @property
20142012 def width (self ):
0 commit comments