Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better diagnostics for undefined domain usage #389

matthuszagh opened this issue May 22, 2020 · 1 comment

Better diagnostics for undefined domain usage #389

matthuszagh opened this issue May 22, 2020 · 1 comment


Copy link

matthuszagh commented May 22, 2020

When an undefined domain is used, nmigen issues an appropriate error, but does not specify the source line that triggered the error. Take the following example:

#!/usr/bin/env python

from nmigen.vendor.xilinx_7series import Xilinx7SeriesPlatform
from nmigen import Elaboratable, Signal, Module
from import Resource, Pins, Clock, Attrs

class Plat(Xilinx7SeriesPlatform):
    device = "XC7A15T"
    package = "FTG256"
    speed = "1"
    resources = [
            Pins("N11", dir="i"),
    connectors = []
    default_clk = "clk40"

class Demo(Elaboratable):
    def elaborate(self, platform):
        m = Module()
        a = Signal()
        m.d.clk += a.eq(1)
        return m

if __name__ == "__main__":
    platform = Plat()

On my system, this gives the error:

Traceback (most recent call last):
  File "./", line 35, in <module>
  File "/nix/store/f29xvgxh94qcv0v1sd438928yix5hfwm-python3-3.7.7-env/lib/python3.7/site-packages/nmigen/build/", line 78, in build
    plan = self.prepare(elaboratable, name, **kwargs)
  File "/nix/store/f29xvgxh94qcv0v1sd438928yix5hfwm-python3-3.7.7-env/lib/python3.7/site-packages/nmigen/build/", line 120, in prepare
    fragment._propagate_domains(self.create_missing_domain, platform=self)
  File "/nix/store/f29xvgxh94qcv0v1sd438928yix5hfwm-python3-3.7.7-env/lib/python3.7/site-packages/nmigen/hdl/", line 380, in _propagate_domains
    new_domains = self._create_missing_domains(missing_domain, platform=platform)
  File "/nix/store/f29xvgxh94qcv0v1sd438928yix5hfwm-python3-3.7.7-env/lib/python3.7/site-packages/nmigen/hdl/", line 358, in _create_missing_domains
    raise DomainError("Domain '{}' is used but not defined".format(domain_name)) Domain 'clk' is used but not defined

It might be nice if the error included a message stating that line 29 (m.d.clk += a.eq(1)) was the offender.

Copy link

whitequark commented May 22, 2020

This isn't currently very easy to implement, but a good thing to keep in mind for the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

2 participants