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

Open
matthuszagh opened this issue May 22, 2020 · 1 comment
Open

Better diagnostics for undefined domain usage #389

matthuszagh opened this issue May 22, 2020 · 1 comment

Comments

@matthuszagh
Copy link

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 nmigen.build import Resource, Pins, Clock, Attrs


class Plat(Xilinx7SeriesPlatform):
    device = "XC7A15T"
    package = "FTG256"
    speed = "1"
    resources = [
        Resource(
            "clk40",
            0,
            Pins("N11", dir="i"),
            Clock(40e6),
            Attrs(IOSTANDARD="LVCMOS33"),
        ),
    ]
    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()
    platform.build(Demo())

On my system, this gives the error:

Traceback (most recent call last):
  File "./file.py", line 35, in <module>
    platform.build(Demo())
  File "/nix/store/f29xvgxh94qcv0v1sd438928yix5hfwm-python3-3.7.7-env/lib/python3.7/site-packages/nmigen/build/plat.py", 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/plat.py", 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/ir.py", 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/ir.py", line 358, in _create_missing_domains
    raise DomainError("Domain '{}' is used but not defined".format(domain_name))
nmigen.hdl.cd.DomainError: 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.

@whitequark
Copy link
Member

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
Development

No branches or pull requests

2 participants