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: 995e4adb8c98
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: 29fee01f8629
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Aug 3, 2019

  1. hdl.ir: warn if .elaborate() returns None.

    Fixes #164.
    whitequark committed Aug 3, 2019
    Copy the full SHA
    29fee01 View commit details
Showing with 18 additions and 0 deletions.
  1. +9 −0 nmigen/hdl/ir.py
  2. +9 −0 nmigen/test/test_hdl_ir.py
9 changes: 9 additions & 0 deletions nmigen/hdl/ir.py
Original file line number Diff line number Diff line change
@@ -52,10 +52,12 @@ class DriverConflict(UserWarning):
class Fragment:
@staticmethod
def get(obj, platform):
code = None
while True:
if isinstance(obj, Fragment):
return obj
elif isinstance(obj, Elaboratable):
code = obj.elaborate.__code__
obj._Elaboratable__used = True
obj = obj.elaborate(platform)
elif hasattr(obj, "elaborate"):
@@ -65,9 +67,16 @@ def get(obj, platform):
.format(type(obj)),
category=RuntimeWarning,
stacklevel=2)
code = obj.elaborate.__code__
obj = obj.elaborate(platform)
else:
raise AttributeError("Object '{!r}' cannot be elaborated".format(obj))
if obj is None and code is not None:
warnings.warn_explicit(
message=".elaborate() returned None; missing return statement?",
category=UserWarning,
filename=code.co_filename,
lineno=code.co_firstlineno)

def __init__(self):
self.ports = SignalDict()
9 changes: 9 additions & 0 deletions nmigen/test/test_hdl_ir.py
Original file line number Diff line number Diff line change
@@ -7,12 +7,21 @@
from .tools import *


class BadElaboratable(Elaboratable):
def elaborate(self, platform):
return


class FragmentGetTestCase(FHDLTestCase):
def test_get_wrong(self):
with self.assertRaises(AttributeError,
msg="Object 'None' cannot be elaborated"):
Fragment.get(None, platform=None)

with self.assertRaises(AttributeError,
msg="Object 'None' cannot be elaborated"):
Fragment.get(BadElaboratable(), platform=None)


class FragmentGeneratedTestCase(FHDLTestCase):
def test_find_subfragment(self):