Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/nmigen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 13650acbbcb6
Choose a base ref
...
head repository: m-labs/nmigen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 722b3879f439
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Oct 13, 2019

  1. hdl.ir: cast instance port connections to Values.

    Fixes #249.
    whitequark committed Oct 13, 2019
    Copy the full SHA
    722b387 View commit details
Showing with 20 additions and 4 deletions.
  1. +4 −4 nmigen/hdl/ir.py
  2. +16 −0 nmigen/test/test_hdl_ir.py
8 changes: 4 additions & 4 deletions nmigen/hdl/ir.py
Original file line number Diff line number Diff line change
@@ -563,7 +563,7 @@ def __init__(self, type, *args, **kwargs):
elif kind == "p":
self.parameters[name] = value
elif kind in ("i", "o", "io"):
self.named_ports[name] = (value, kind)
self.named_ports[name] = (Value.cast(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\""
@@ -575,11 +575,11 @@ def __init__(self, type, *args, **kwargs):
elif kw.startswith("p_"):
self.parameters[kw[2:]] = arg
elif kw.startswith("i_"):
self.named_ports[kw[2:]] = (arg, "i")
self.named_ports[kw[2:]] = (Value.cast(arg), "i")
elif kw.startswith("o_"):
self.named_ports[kw[2:]] = (arg, "o")
self.named_ports[kw[2:]] = (Value.cast(arg), "o")
elif kw.startswith("io_"):
self.named_ports[kw[3:]] = (arg, "io")
self.named_ports[kw[3:]] = (Value.cast(arg), "io")
else:
raise NameError("Instance keyword argument {}={!r} does not start with one of "
"\"p_\", \"i_\", \"o_\", or \"io_\""
16 changes: 16 additions & 0 deletions nmigen/test/test_hdl_ir.py
Original file line number Diff line number Diff line change
@@ -667,6 +667,22 @@ def test_construct(self):
("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):
s = Signal()
with self.assertRaises(NameError,