Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6414c80b82c9
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4c582ef609bc
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 22, 2019

  1. hdl.rec: allow using Enum subclass as shape.

    Fixes #223.
    whitequark committed Sep 22, 2019
    Copy the full SHA
    4c582ef View commit details
Showing with 17 additions and 0 deletions.
  1. +3 −0 nmigen/hdl/rec.py
  2. +14 −0 nmigen/test/test_hdl_rec.py
3 changes: 3 additions & 0 deletions nmigen/hdl/rec.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
from .. import tracer
from ..tools import union
from .ast import *
from .ast import _enum_shape


__all__ = ["Direction", "DIR_NONE", "DIR_FANOUT", "DIR_FANIN", "Layout", "Record"]
@@ -34,6 +35,8 @@ def __init__(self, fields):
if len(field) == 2:
name, shape = field
direction = DIR_NONE
if isinstance(shape, type) and issubclass(shape, Enum):
shape = _enum_shape(shape)
if isinstance(shape, list):
shape = Layout.wrap(shape)
else:
14 changes: 14 additions & 0 deletions nmigen/test/test_hdl_rec.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from enum import Enum

from ..hdl.ast import *
from ..hdl.rec import *
from .tools import *


class UnsignedEnum(Enum):
FOO = 1
BAR = 2
BAZ = 3


class LayoutTestCase(FHDLTestCase):
def test_fields(self):
layout = Layout.wrap([
@@ -25,6 +33,12 @@ def test_fields(self):
self.assertEqual(sublayout["a"], ((1, False), DIR_NONE))
self.assertEqual(sublayout["b"], ((1, False), DIR_NONE))

def test_enum_field(self):
layout = Layout.wrap([
("enum", UnsignedEnum),
])
self.assertEqual(layout["enum"], ((2, False), DIR_NONE))

def test_slice_tuple(self):
layout = Layout.wrap([
("a", 1),