hdl.ir: detect elaboratables that are created but not used.

Requres every elaboratable to inherit from Elaboratable, but still
accepts ones that do not, with a warning.

Fixes #3.
This commit is contained in:
whitequark 2019-04-21 08:52:57 +00:00
parent 85ae99c1b4
commit 44711b7d08
22 changed files with 79 additions and 45 deletions

View file

@ -0,0 +1,6 @@
from ..hdl.ir import Elaboratable
# The nMigen testsuite creates a lot of elaboratables that are intentionally unused.
# Disable the unused elaboratable check, as in our case it provides nothing but noise.
del Elaboratable.__del__

View file

@ -488,7 +488,7 @@ class CEInserterTestCase(FHDLTestCase):
""")
class _MockElaboratable:
class _MockElaboratable(Elaboratable):
def __init__(self):
self.s1 = Signal()

View file

@ -1,6 +1,7 @@
from .tools import *
from ..hdl.ast import *
from ..hdl.dsl import *
from ..hdl.ir import *
from ..back.pysim import *
from ..lib.coding import *
@ -82,7 +83,7 @@ class DecoderTestCase(FHDLTestCase):
sim.run()
class ReversibleSpec:
class ReversibleSpec(Elaboratable):
def __init__(self, encoder_cls, decoder_cls, args):
self.encoder_cls = encoder_cls
self.decoder_cls = decoder_cls
@ -99,7 +100,7 @@ class ReversibleSpec:
return m
class HammingDistanceSpec:
class HammingDistanceSpec(Elaboratable):
def __init__(self, distance, encoder_cls, args):
self.distance = distance
self.encoder_cls = encoder_cls

View file

@ -45,7 +45,7 @@ class FIFOSmokeTestCase(FHDLTestCase):
self.assertAsyncFIFOWorks(AsyncFIFOBuffered(width=8, depth=3))
class FIFOModel(FIFOInterface):
class FIFOModel(Elaboratable, FIFOInterface):
"""
Non-synthesizable first-in first-out queue, implemented naively as a chain of registers.
"""
@ -104,7 +104,7 @@ class FIFOModel(FIFOInterface):
return m
class FIFOModelEquivalenceSpec:
class FIFOModelEquivalenceSpec(Elaboratable):
"""
The first-in first-out queue model equivalence specification: for any inputs and control
signals, the behavior of the implementation under test exactly matches the ideal model,
@ -148,7 +148,7 @@ class FIFOModelEquivalenceSpec:
return m
class FIFOContractSpec:
class FIFOContractSpec(Elaboratable):
"""
The first-in first-out queue contract specification: if two elements are written to the queue
consecutively, they must be read out consecutively at some later point, no matter all other