From 14ed5c1acc603d506cfdc56f00e1eafb81404df3 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 27 Jul 2013 22:18:06 +0200 Subject: [PATCH] genlib/record: support abstract signal width --- migen/genlib/record.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/migen/genlib/record.py b/migen/genlib/record.py index d2d355ce..10e3a43c 100644 --- a/migen/genlib/record.py +++ b/migen/genlib/record.py @@ -11,19 +11,21 @@ from migen.genlib.misc import optree # size can be an int, or a (int, bool) tuple for signed numbers # sublayout must be a list -def layout_len(layout): +def layout_len(layout, **layout_dict): r = 0 for f in layout: - if isinstance(f[1], (int, tuple)): # cases 1/2 + if isinstance(f[1], (int, tuple, str)): # cases 1/2 if(len(f) == 3): fname, fsize, fdirection = f else: fname, fsize = f elif isinstance(f[1], list): # case 3 fname, fsublayout = f - fsize = layout_len(fsublayout) + fsize = layout_len(fsublayout, **layout_dict) else: raise TypeError + if isinstance(fsize, str): + fsize = layout_dict[fsize] if isinstance(fsize, tuple): r += fsize[0] else: @@ -55,20 +57,23 @@ def layout_partial(layout, *elements): return r class Record: - def __init__(self, layout, name=None): + def __init__(self, layout, name=None, **layout_dict): self.name = get_obj_var_name(name, "") self.layout = layout + self.layout_dict = layout_dict if self.name: prefix = self.name + "_" else: prefix = "" for f in self.layout: - if isinstance(f[1], (int, tuple)): # cases 1/2 + if isinstance(f[1], (int, tuple, str)): # cases 1/2 if(len(f) == 3): fname, fsize, fdirection = f else: fname, fsize = f + if isinstance(fsize, str): + fsize = layout_dict[fsize] finst = Signal(fsize, name=prefix + fname) elif isinstance(f[1], list): # case 3 fname, fsublayout = f @@ -139,7 +144,7 @@ class Record: return r def __len__(self): - return layout_len(self.layout) + return layout_len(self.layout, **self.layout_dict) def __repr__(self): return "" -- 2.30.2