You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.4 KiB

from abc import ABCMeta, abstractmethod
from pathlib import Path
from import sby
__all__ = ["PowerFVCheck"]
class PowerFVCheckMeta(ABCMeta):
all_checks = {}
def __new__(metacls, clsname, bases, namespace, name=None, **kwargs):
if name is not None:
if name in metacls.all_checks:
raise NameError("Check {!r} already exists".format(name))
namespace["name"] = name
cls = ABCMeta.__new__(metacls, clsname, bases, namespace, **kwargs)
if name is not None:
metacls.all_checks[name] = cls = name
return cls
def find(cls, name, *, sep=":"):
name = tuple(name.split(sep))
for check_name, check_cls in cls.all_checks.items():
assert isinstance(check_name, tuple)
if len(name) > len(check_name):
if name == check_name[:len(name)]:
yield sep.join(check_name), check_cls
class PowerFVCheck(metaclass=PowerFVCheckMeta):
def add_check_arguments(cls, parser):
"name", metavar="NAME", type=str, help="name of the check")
"--depth", type=int, default=15,
help="depth of the BMC, in clock cycles (default: %(default)s)")
"--skip", type=int, default=None,
help="skip the specified number of clock cycles (default: DEPTH-1))")
"--cover", action="store_true",
help="generate the shortest trace to reach every Cover() statement")
def __init__(self, *, depth, skip, cover, core, **kwargs):
self.depth = depth
self.skip = skip if skip is not None else depth - 1
self.cover = bool(cover)
self.core = core
self.dut = core.wrapper(**kwargs)
def testbench(self):
raise NotImplementedError
def build(self, *, do_build=True, **kwargs):
platform = sby.SymbiYosysPlatform()
self.core.add_files(platform, self.dut, **kwargs)
top = self.testbench()
overrides = {key: str(value) for key, value in kwargs.items()}
overrides["depth"] = str(self.depth)
overrides["skip"] = str(self.skip)
overrides["mode"] = "cover" if self.cover else "bmc"
return,, do_build=do_build, **overrides)