hdl.ir: accept expanded (kind, name, value) tuples in Instance.
This is useful for e.g. programmatically generating parameters without having to mess with kwargs dicts.
This commit is contained in:
parent
fb01854372
commit
b64a31255c
2 changed files with 58 additions and 3 deletions
|
|
@ -517,13 +517,23 @@ class Fragment:
|
|||
|
||||
|
||||
class Instance(Fragment):
|
||||
def __init__(self, type, **kwargs):
|
||||
def __init__(self, type, *args, **kwargs):
|
||||
super().__init__()
|
||||
|
||||
self.type = type
|
||||
self.parameters = OrderedDict()
|
||||
self.named_ports = OrderedDict()
|
||||
|
||||
for (kind, name, value) in args:
|
||||
if kind == "p":
|
||||
self.parameters[name] = value
|
||||
elif kind in ("i", "o", "io"):
|
||||
self.named_ports[name] = (value, kind)
|
||||
else:
|
||||
raise NameError("Instance argument {!r} should be a tuple (kind, name, value) "
|
||||
"where kind is one of \"p\", \"i\", \"o\", or \"io\""
|
||||
.format((kind, name, value)))
|
||||
|
||||
for kw, arg in kwargs.items():
|
||||
if kw.startswith("p_"):
|
||||
self.parameters[kw[2:]] = arg
|
||||
|
|
@ -534,5 +544,6 @@ class Instance(Fragment):
|
|||
elif kw.startswith("io_"):
|
||||
self.named_ports[kw[3:]] = (arg, "io")
|
||||
else:
|
||||
raise NameError("Instance argument '{}' does not start with p_, i_, o_, or io_"
|
||||
.format(arg))
|
||||
raise NameError("Instance keyword argument {}={!r} does not start with one of "
|
||||
"\"p_\", \"i_\", \"o_\", or \"io_\""
|
||||
.format(kw, arg))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue