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: amaranth-lang/amaranth
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 31cd72c0b625
Choose a base ref
...
head repository: amaranth-lang/amaranth
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3df429703c40
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Feb 6, 2020

  1. Copy the full SHA
    86b57fe View commit details
  2. hdl.dsl: reject name mismatch in m.domains.<name> +=.

    This would violate invariants later in the elaboration process.
    
    Fixes #282.
    whitequark committed Feb 6, 2020
    Copy the full SHA
    3df4297 View commit details
Showing with 26 additions and 0 deletions.
  1. +11 −0 nmigen/hdl/dsl.py
  2. +15 −0 nmigen/test/test_hdl_dsl.py
11 changes: 11 additions & 0 deletions nmigen/hdl/dsl.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
from .. import tracer
from .ast import *
from .ir import *
from .cd import *
from .xfrm import *


@@ -107,10 +108,20 @@ def __init__(self, builder):

def __iadd__(self, domains):
for domain in flatten([domains]):
if not isinstance(domain, ClockDomain):
raise TypeError("Only clock domains may be added to `m.domains`, not {!r}"
.format(domain))
self._builder._add_domain(domain)
return self

def __setattr__(self, name, domain):
if not isinstance(domain, ClockDomain):
raise TypeError("Only clock domains may be added to `m.domains`, not {!r}"
.format(domain))
if domain.name != name:
raise NameError("Clock domain name {!r} must match name in `m.domains.{} += ...` "
"syntax"
.format(domain.name, name))
self._builder._add_domain(domain)


15 changes: 15 additions & 0 deletions nmigen/test/test_hdl_dsl.py
Original file line number Diff line number Diff line change
@@ -707,6 +707,21 @@ def test_domain_named_explicit(self):
self.assertEqual(len(m._domains), 1)
self.assertEqual(m._domains[0].name, "foo")

def test_domain_add_wrong(self):
m = Module()
with self.assertRaises(TypeError,
msg="Only clock domains may be added to `m.domains`, not 1"):
m.domains.foo = 1
with self.assertRaises(TypeError,
msg="Only clock domains may be added to `m.domains`, not 1"):
m.domains += 1

def test_domain_add_wrong_name(self):
m = Module()
with self.assertRaises(NameError,
msg="Clock domain name 'bar' must match name in `m.domains.foo += ...` syntax"):
m.domains.foo = ClockDomain("bar")

def test_lower(self):
m1 = Module()
m1.d.comb += self.c1.eq(self.s1)