Add a --exclude parameter to the check command.

Also, remove the expand command; when a group of checks is selected by
the 'check' command, its members are immediately added to the session.
main
Jean-François Nguyen 2 years ago
parent 7b7aa6cc9b
commit c16e678c49

@ -1,7 +1,7 @@
check unique --depth=15 --skip=12 check unique --depth=15 --skip=12
check cia --depth=15 check cia --depth=15
check gpr --depth=15 check gpr --depth=15
check insn --depth=15 check insn --depth=15 --exclude=brh,brw,setbc,setbcr,setnbc,setnbcr


check microwatt:storage:data --depth=15 check microwatt:storage:data --depth=15



@ -23,13 +23,14 @@ class PowerFVCheckMeta(ABCMeta):
return cls return cls


@classmethod @classmethod
def find(cls, *name): def find(cls, name, *, sep=":"):
name = tuple(name.split(sep))
for check_name, check_cls in cls.all_checks.items(): for check_name, check_cls in cls.all_checks.items():
assert isinstance(check_name, tuple) assert isinstance(check_name, tuple)
if len(name) > len(check_name): if len(name) > len(check_name):
continue continue
if name == check_name[:len(name)]: if name == check_name[:len(name)]:
yield check_name, check_cls yield sep.join(check_name), check_cls




class PowerFVCheck(metaclass=PowerFVCheckMeta): class PowerFVCheck(metaclass=PowerFVCheckMeta):

@ -8,8 +8,6 @@ from .trap import *
from .logical import * from .logical import *
from .rotate import * from .rotate import *
from .bcd import * from .bcd import *
from .byterev import *
from .msr import * from .msr import *
from .spr import * from .spr import *

# TODO: add a --exclude= argument to the 'check' command
# from .byterev import *

@ -6,7 +6,7 @@ from power_fv.check.insn import InsnCheck
__all__ = [ __all__ = [
"CRAND", "CROR", "CRNAND", "CRXOR", "CRNOR", "CRANDC", "CREQV", "CRORC", "CRAND", "CROR", "CRNAND", "CRXOR", "CRNOR", "CRANDC", "CREQV", "CRORC",
"MCRF", "MCRXRX", "MTCRF", "MFOCRF", "MFCR", "MCRF", "MCRXRX", "MTCRF", "MFOCRF", "MFCR",
"SETB", #"SETBC", "SETBCR", "SETNBC", "SETNBCR", "SETB", "SETBC", "SETBCR", "SETNBC", "SETNBCR",
] ]




@ -27,9 +27,7 @@ class MFOCRF (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.MFOCRF): pass
class MFCR (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.MFCR ): pass class MFCR (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.MFCR ): pass


class SETB (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETB ): pass class SETB (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETB ): pass

class SETBC (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETBC ): pass
# TODO: add a --exclude= argument to the 'check' command class SETBCR (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETBCR ): pass
# class SETBC (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETBC ): pass class SETNBC (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETNBC ): pass
# class SETBCR (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETBCR ): pass class SETNBCR(InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETNBCR): pass
# class SETNBC (InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETNBC ): pass
# class SETNBCR(InsnCheck, spec_cls=CRMoveSpec, insn_cls=const.SETNBCR): pass

@ -40,12 +40,11 @@ class PowerFVSession:
def __init__(self, prog=None): def __init__(self, prog=None):
self.parser = _ArgumentParser(prog=prog, add_help=False) self.parser = _ArgumentParser(prog=prog, add_help=False)
self.subparsers = self.parser.add_subparsers(help="commands") self.subparsers = self.parser.add_subparsers(help="commands")
self.namespace = dict() self._checks = dict()


self.add_help_subparser() self.add_help_subparser()
self.add_check_subparser() self.add_check_subparser()
self.add_dump_subparser() self.add_dump_subparser()
self.add_expand_subparser()
self.add_build_subparser() self.add_build_subparser()
self.add_exit_subparser() self.add_exit_subparser()


@ -102,14 +101,14 @@ class PowerFVSession:
PowerFVCheck .add_check_arguments(parser) PowerFVCheck .add_check_arguments(parser)
self.core_cls.add_check_arguments(parser) self.core_cls.add_check_arguments(parser)


parser.add_argument(
"--exclude", type=str, default="",
help="exclude a comma-separated list of checks from the selection")

def add_dump_subparser(self): def add_dump_subparser(self):
parser = self.subparsers.add_parser("dump", help="inspect check parameters") parser = self.subparsers.add_parser("dump", help="inspect check parameters")
parser.set_defaults(_cmd=self.dump) parser.set_defaults(_cmd=self.dump)


def add_expand_subparser(self):
parser = self.subparsers.add_parser("expand", help="expand check parameters")
parser.set_defaults(_cmd=self.expand)

def add_build_subparser(self): def add_build_subparser(self):
parser = self.subparsers.add_parser("build", help="execute the build plan") parser = self.subparsers.add_parser("build", help="execute the build plan")
parser.set_defaults(_cmd=self.build) parser.set_defaults(_cmd=self.build)
@ -130,23 +129,20 @@ class PowerFVSession:
def help(self, **kwargs): def help(self, **kwargs):
self.parser.print_help() self.parser.print_help()


def check(self, *, name, **kwargs): def check(self, *, name, exclude, **kwargs):
self.namespace[name] = dict(**kwargs) exclude = [f"{name}:{subname}" for subname in exclude.split(",")]

matches = list(PowerFVCheck.find(name))
def dump(self, **kwargs): new_checks = dict()
pprint(self.namespace, sort_dicts=False)


def expand(self, **kwargs): for check_name, check_cls in matches:
new_namespace = dict() if check_name in exclude:
continue
new_checks[check_name] = dict(**kwargs)


for check_name, check_args in self.namespace.items(): self._checks.update(new_checks)
matches = list(PowerFVCheck.find(*check_name.split(":")))
if not matches:
raise NameError("Unknown check {!r}".format(check_name))
for match_name, match_cls in matches:
new_namespace[":".join(match_name)] = check_args


self.namespace = new_namespace def dump(self, **kwargs):
pprint(self._checks, sort_dicts=False)


@staticmethod @staticmethod
def _build_check(core_cls, check_name, check_args, build_args): def _build_check(core_cls, check_name, check_args, build_args):
@ -156,12 +152,10 @@ class PowerFVSession:
check.build(**build_args) check.build(**build_args)


def build(self, *, jobs, **kwargs): def build(self, *, jobs, **kwargs):
self.expand()

map_func = PowerFVSession._build_check map_func = PowerFVSession._build_check
map_args = [] map_args = []


for check_name, check_args in self.namespace.items(): for check_name, check_args in self._checks.items():
map_args.append((self.core_cls, check_name, check_args, kwargs)) map_args.append((self.core_cls, check_name, check_args, kwargs))


with multiprocessing.Pool(jobs) as pool: with multiprocessing.Pool(jobs) as pool:

Loading…
Cancel
Save