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"]
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:
+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([
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),