parent
13650acbbc
commit
722b3879f4
|
@ -563,7 +563,7 @@ class Instance(Fragment):
|
||||||
elif kind == "p":
|
elif kind == "p":
|
||||||
self.parameters[name] = value
|
self.parameters[name] = value
|
||||||
elif kind in ("i", "o", "io"):
|
elif kind in ("i", "o", "io"):
|
||||||
self.named_ports[name] = (value, kind)
|
self.named_ports[name] = (Value.cast(value), kind)
|
||||||
else:
|
else:
|
||||||
raise NameError("Instance argument {!r} should be a tuple (kind, name, value) "
|
raise NameError("Instance argument {!r} should be a tuple (kind, name, value) "
|
||||||
"where kind is one of \"p\", \"i\", \"o\", or \"io\""
|
"where kind is one of \"p\", \"i\", \"o\", or \"io\""
|
||||||
|
@ -575,11 +575,11 @@ class Instance(Fragment):
|
||||||
elif kw.startswith("p_"):
|
elif kw.startswith("p_"):
|
||||||
self.parameters[kw[2:]] = arg
|
self.parameters[kw[2:]] = arg
|
||||||
elif kw.startswith("i_"):
|
elif kw.startswith("i_"):
|
||||||
self.named_ports[kw[2:]] = (arg, "i")
|
self.named_ports[kw[2:]] = (Value.cast(arg), "i")
|
||||||
elif kw.startswith("o_"):
|
elif kw.startswith("o_"):
|
||||||
self.named_ports[kw[2:]] = (arg, "o")
|
self.named_ports[kw[2:]] = (Value.cast(arg), "o")
|
||||||
elif kw.startswith("io_"):
|
elif kw.startswith("io_"):
|
||||||
self.named_ports[kw[3:]] = (arg, "io")
|
self.named_ports[kw[3:]] = (Value.cast(arg), "io")
|
||||||
else:
|
else:
|
||||||
raise NameError("Instance keyword argument {}={!r} does not start with one of "
|
raise NameError("Instance keyword argument {}={!r} does not start with one of "
|
||||||
"\"p_\", \"i_\", \"o_\", or \"io_\""
|
"\"p_\", \"i_\", \"o_\", or \"io_\""
|
||||||
|
|
|
@ -667,6 +667,22 @@ class InstanceTestCase(FHDLTestCase):
|
||||||
("s6", (s6, "io")),
|
("s6", (s6, "io")),
|
||||||
]))
|
]))
|
||||||
|
|
||||||
|
def test_cast_ports(self):
|
||||||
|
inst = Instance("foo",
|
||||||
|
("i", "s1", 1),
|
||||||
|
("o", "s2", 2),
|
||||||
|
("io", "s3", 3),
|
||||||
|
i_s4=4,
|
||||||
|
o_s5=5,
|
||||||
|
io_s6=6,
|
||||||
|
)
|
||||||
|
self.assertRepr(inst.named_ports["s1"][0], "(const 1'd1)")
|
||||||
|
self.assertRepr(inst.named_ports["s2"][0], "(const 2'd2)")
|
||||||
|
self.assertRepr(inst.named_ports["s3"][0], "(const 2'd3)")
|
||||||
|
self.assertRepr(inst.named_ports["s4"][0], "(const 3'd4)")
|
||||||
|
self.assertRepr(inst.named_ports["s5"][0], "(const 3'd5)")
|
||||||
|
self.assertRepr(inst.named_ports["s6"][0], "(const 3'd6)")
|
||||||
|
|
||||||
def test_wrong_construct_arg(self):
|
def test_wrong_construct_arg(self):
|
||||||
s = Signal()
|
s = Signal()
|
||||||
with self.assertRaises(NameError,
|
with self.assertRaises(NameError,
|
||||||
|
|
Loading…
Reference in a new issue