hdl.rec: improve repr() for Layout.

Fixes #326.
This commit is contained in:
whitequark 2020-04-12 04:47:40 +00:00
parent e9c75f7ca1
commit 7a08901117
2 changed files with 16 additions and 0 deletions

View file

@ -74,6 +74,15 @@ class Layout:
def __eq__(self, other):
return self.fields == other.fields
def __repr__(self):
field_reprs = []
for name, shape, dir in self:
if dir == DIR_NONE:
field_reprs.append("({!r}, {!r})".format(name, shape))
else:
field_reprs.append("({!r}, {!r}, Direction.{})".format(name, shape, dir.name))
return "Layout([{}])".format(", ".join(field_reprs))
# Unlike most Values, Record *can* be subclassed.
class Record(Value):