parent
995e4adb8c
commit
29fee01f86
|
@ -52,10 +52,12 @@ class DriverConflict(UserWarning):
|
||||||
class Fragment:
|
class Fragment:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(obj, platform):
|
def get(obj, platform):
|
||||||
|
code = None
|
||||||
while True:
|
while True:
|
||||||
if isinstance(obj, Fragment):
|
if isinstance(obj, Fragment):
|
||||||
return obj
|
return obj
|
||||||
elif isinstance(obj, Elaboratable):
|
elif isinstance(obj, Elaboratable):
|
||||||
|
code = obj.elaborate.__code__
|
||||||
obj._Elaboratable__used = True
|
obj._Elaboratable__used = True
|
||||||
obj = obj.elaborate(platform)
|
obj = obj.elaborate(platform)
|
||||||
elif hasattr(obj, "elaborate"):
|
elif hasattr(obj, "elaborate"):
|
||||||
|
@ -65,9 +67,16 @@ class Fragment:
|
||||||
.format(type(obj)),
|
.format(type(obj)),
|
||||||
category=RuntimeWarning,
|
category=RuntimeWarning,
|
||||||
stacklevel=2)
|
stacklevel=2)
|
||||||
|
code = obj.elaborate.__code__
|
||||||
obj = obj.elaborate(platform)
|
obj = obj.elaborate(platform)
|
||||||
else:
|
else:
|
||||||
raise AttributeError("Object '{!r}' cannot be elaborated".format(obj))
|
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):
|
def __init__(self):
|
||||||
self.ports = SignalDict()
|
self.ports = SignalDict()
|
||||||
|
|
|
@ -7,12 +7,21 @@ from ..hdl.mem import *
|
||||||
from .tools import *
|
from .tools import *
|
||||||
|
|
||||||
|
|
||||||
|
class BadElaboratable(Elaboratable):
|
||||||
|
def elaborate(self, platform):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class FragmentGetTestCase(FHDLTestCase):
|
class FragmentGetTestCase(FHDLTestCase):
|
||||||
def test_get_wrong(self):
|
def test_get_wrong(self):
|
||||||
with self.assertRaises(AttributeError,
|
with self.assertRaises(AttributeError,
|
||||||
msg="Object 'None' cannot be elaborated"):
|
msg="Object 'None' cannot be elaborated"):
|
||||||
Fragment.get(None, platform=None)
|
Fragment.get(None, platform=None)
|
||||||
|
|
||||||
|
with self.assertRaises(AttributeError,
|
||||||
|
msg="Object 'None' cannot be elaborated"):
|
||||||
|
Fragment.get(BadElaboratable(), platform=None)
|
||||||
|
|
||||||
|
|
||||||
class FragmentGeneratedTestCase(FHDLTestCase):
|
class FragmentGeneratedTestCase(FHDLTestCase):
|
||||||
def test_find_subfragment(self):
|
def test_find_subfragment(self):
|
||||||
|
|
Loading…
Reference in a new issue