Skip to content

Commit

Permalink
back.rtlil: translate enum decoders to Yosys enum attributes.
Browse files Browse the repository at this point in the history
Fixes m-labs#254.
  • Loading branch information
whitequark committed Apr 15, 2020
1 parent 3346f2c commit b4af217
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions nmigen/back/rtlil.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,15 @@ def resolve(self, signal, prefix=None):
else:
wire_name = signal.name

attrs = dict(signal.attrs)
if signal._enum_class is not None:
attrs["enum_base_type"] = signal._enum_class.__name__
for value in signal._enum_class:
attrs["enum_value_{:0{}b}".format(value.value, signal.width)] = value.name

wire_curr = self.rtlil.wire(width=signal.width, name=wire_name,
port_id=port_id, port_kind=port_kind,
attrs=signal.attrs,
src=src(signal.src_loc))
attrs=attrs, src=src(signal.src_loc))
if signal in self.driven and self.driven[signal]:
wire_next = self.rtlil.wire(width=signal.width, name=wire_curr + "$next",
src=src(signal.src_loc))
Expand Down
6 changes: 4 additions & 2 deletions nmigen/hdl/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def matches(self, *patterns):

def rotate_left(self, offset):
"""Rotate left by constant modulo 2**len(self).
Parameters
----------
offset : int
Expand All @@ -443,7 +443,7 @@ def rotate_left(self, offset):

def rotate_right(self, offset):
"""Rotate right by constant modulo 2**len(self).
Parameters
----------
offset : int
Expand Down Expand Up @@ -922,8 +922,10 @@ def enum_decoder(value):
except ValueError:
return str(value)
self.decoder = enum_decoder
self._enum_class = decoder
else:
self.decoder = decoder
self._enum_class = None

# Not a @classmethod because nmigen.compat requires it.
@staticmethod
Expand Down

0 comments on commit b4af217

Please sign in to comment.