Пример #1
0
    def __init__(self):
        self.sparser = None
        self.lparser = None
        self.coi = None
        self.model_info = ModelInformation()

        GeneratorsFactory.init_generators()
        ClockBehaviorsFactory.init_clockbehaviors()
Пример #2
0
    def __init__(self):
        self.sparser = None
        self.lparser = None
        self.coi = None
        self.model_info = ModelInformation()
        self.properties = []  # contains the parsed properties -- PySMT objects

        GeneratorsFactory.init_generators()
        ClockBehaviorsFactory.init_clockbehaviors()
Пример #3
0
def test():
    parser = CosaArgParser()

    wrapper = TextWrapper(initial_indent=" - ")
    extra_info = []

    devel = False
    if DEVEL_OPT in sys.argv:
        sys.argv = [a for a in sys.argv if a != DEVEL_OPT]
        devel = True

    extra_info.append(bold_text("\nADDITIONAL INFORMATION:"))

    clock_behaviors = []
    for x in ClockBehaviorsFactory.get_clockbehaviors():
        wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
        clock_behaviors.append("\n".join(
            wrapper.wrap("\"%s\": %s, parameters (%s)" %
                         (x.get_name(), x.get_desc(), x.get_interface()))))

    extra_info.append('\nClock behaviors:\n%s' % ("\n".join(clock_behaviors)))

    sugars = []
    for x in SyntacticSugarFactory.get_sugars():
        wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
        sugars.append("\n".join(
            wrapper.wrap("\"%s\": %s, parameters (%s)" %
                         (x.get_name(), x.get_desc(), x.get_interface()))))

    extra_info.append('\nSpecial operators:\n%s' % ("\n".join(sugars)))

    generators = []
    for x in GeneratorsFactory.get_generators():
        wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
        generators.append("\n".join(
            wrapper.wrap("\"%s\": %s, parameters (%s) values (%s)" %
                         (x.get_name(), x.get_desc(), x.get_interface(),
                          x.get_values()))))

    extra_info.append('\nModule generators:\n%s' % ("\n".join(generators)))

    modifiers = []
    modifiers.append(" - \"None\": No extension")
    for x in ModelModifiersFactory.get_modifiers():
        wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
        modifiers.append("\n".join(
            wrapper.wrap("\"%s\": %s" % (x.get_name(), x.get_desc()))))

    extra_info.append('\nModel modifiers:\n%s' % ("\n".join(modifiers)))

    parser = CosaArgParser(description=bold_text(
        'CoSA: CoreIR Symbolic Analyzer\n..an SMT-based Symbolic Model Checker for Hardware Design'
    ),
                           formatter_class=RawTextHelpFormatter,
                           epilog="\n".join(extra_info))

    # Main inputs

    # Options in the general group are options that must stay constant for all problems
    # in a problem file

    # in our architecture, the input files are compiled into a single transition system which
    # is then used to verify mutliple properties (problems)
    # thus any option regarding the encoding of said transition system must be a general option

    in_options = parser.add_general_group('input options')

    av_input_types = [" - \"%s\": %s"%(x.name, ", ".join(["*.%s"%e for e in x.extensions])) \
                      for x in ModelParsersFactory.get_parsers() if x.is_available()]

    ua_input_types = [" - \"%s\": %s"%(x.name, ", ".join(["*.%s"%e for e in x.extensions])) \
                      for x in ModelParsersFactory.get_parsers() if not x.is_available()]

    in_options.set_defaults(model_files=None)
    in_options.add_argument('-i', '--model_files', metavar='<model files>', type=str, required=False,
                            help='comma separated list of input files.\nSupported types:\n%s%s'%\
                            ("\n".join(av_input_types), "\nNot enabled:\n%s"%("\n".join(ua_input_types)) \
                             if len(ua_input_types) > 0 else ""))

    in_options.set_defaults(problems=None)
    in_options.add_argument(
        '--problems',
        metavar='<problems file>',
        type=str,
        required=False,
        help='problems file describing the verifications to be performed.',
        is_config_file=True)

    general_encoding_options = parser.add_general_group('encoding')

    general_encoding_options.set_defaults(abstract_clock=False)
    general_encoding_options.add_argument(
        '--abstract-clock',
        dest='abstract_clock',
        action='store_true',
        help="abstracts the clock behavior. (Default is \"%s\")" % False)

    general_encoding_options.set_defaults(add_clock=False)
    general_encoding_options.add_argument(
        '--add-clock',
        dest='add_clock',
        action='store_true',
        help="adds clock behavior. (Default is \"%s\")" % False)

    general_encoding_options.set_defaults(cache_files=False)
    general_encoding_options.add_argument(
        '-c',
        '--cache-files',
        dest='cache_files',
        action='store_true',
        help="caches encoded files to speed-up parsing. (Default is \"%s\")" %
        False)

    general_encoding_options.set_defaults(clean_cache=False)
    general_encoding_options.add_argument(
        '--clean-cache',
        dest='clean_cache',
        action='store_true',
        help="deletes the stored cache. (Default is \"%s\")" % False)

    general_encoding_options.set_defaults(boolean=False)
    general_encoding_options.add_argument(
        '--boolean',
        dest='boolean',
        action='store_true',
        help=
        'interprets single bits as Booleans instead of 1-bit Bitvector. (Default is \"%s\")'
        % False)

    general_encoding_options.set_defaults(run_coreir_passes=True)
    general_encoding_options.add_argument(
        '--no-run-coreir-passes',
        dest='run_coreir_passes',
        action='store_false',
        help='does not run CoreIR passes. (Default is \"%s\")' % True)

    general_encoding_options.set_defaults(model_extension=False)
    general_encoding_options.add_argument(
        '--model-extension',
        metavar='model_extension',
        type=str,
        nargs='?',
        help='select the model modifier. (Default is \"%s\")' % (False))

    general_encoding_options.set_defaults(opt_circuit=False)
    general_encoding_options.add_argument(
        '--opt-circuit',
        action='store_true',
        help='Use Yosys to optimize the circuit -- can remove signals.')

    general_encoding_options.set_defaults(no_arrays=False)
    general_encoding_options.add_argument(
        '--no-arrays',
        action='store_true',
        help=
        'For Yosys frontend, blast memories to registers instead of using arrays.\n'
        'Note: This can fail -- particularly for dualport memories.')

    general_encoding_options.set_defaults(symbolic_init=False)
    general_encoding_options.add_argument(
        '--symbolic-init',
        dest='symbolic_init',
        action='store_true',
        help='removes constraints on the initial state. (Default is \"%s\")' %
        False)

    general_encoding_options.set_defaults(zero_init=False)
    general_encoding_options.add_argument(
        '--zero-init',
        dest='zero_init',
        action='store_true',
        help='sets initial state to zero. (Default is \"%s\")' % False)

    general_encoding_options.set_defaults(vcd=False)
    general_encoding_options.add_argument(
        '--vcd',
        dest='vcd',
        action='store_true',
        help="generate traces also in vcd format. (Default is \"%s\")" % False)

    general_encoding_options.add_argument(
        '--clock-behaviors',
        metavar='clock_behaviors',
        type=str,
        nargs='?',
        help='semi column separated list of clock behaviors instantiation.')

    # Verification Options

    ver_options = parser.add_problem_group('analysis')

    ver_options.set_defaults(safety=False)
    ver_options.add_argument('--safety',
                             dest='safety',
                             action='store_true',
                             help='safety verification using BMC.')

    ver_options.set_defaults(ltl=False)
    ver_options.add_argument('--ltl',
                             dest='ltl',
                             action='store_true',
                             help='ltl verification using BMC.')

    ver_options.set_defaults(simulate=False)
    ver_options.add_argument('--simulate',
                             dest='simulate',
                             action='store_true',
                             help='simulate system using BMC.')

    ver_options.set_defaults(equivalence=None)
    ver_options.add_argument('--equivalence',
                             metavar='<input files>',
                             type=str,
                             required=False,
                             help='equivalence checking using BMC.')

    ver_options.set_defaults(fsm_check=False)
    ver_options.add_argument(
        '--fsm-check',
        dest='fsm_check',
        action='store_true',
        help='check if the state machine is deterministic.')

    ver_options.set_defaults(parametric=False)
    ver_options.add_argument('--parametric',
                             dest='parametric',
                             action='store_true',
                             help='parametric analysis using BMC.')

    # Verification parameters

    ver_params = parser.add_problem_group('verification parameters')

    ver_params.set_defaults(properties=None)
    ver_params.add_argument('-p',
                            '--properties',
                            metavar='<invar list>',
                            type=str,
                            required=False,
                            help='comma separated list of properties.')

    ver_params.set_defaults(bmc_length=5)
    ver_params.add_argument(
        '-k',
        '--bmc-length',
        metavar='<BMC length>',
        type=int,
        required=False,
        help="depth of BMC unrolling. (Default is \"%s\")" % 5)

    ver_params.set_defaults(bmc_length_min=0)
    ver_params.add_argument(
        '-km',
        '--bmc-length-min',
        metavar='<BMC length>',
        type=int,
        required=False,
        help="minimum depth of BMC unrolling. (Default is \"%s\")" % 0)

    ver_params.set_defaults(precondition=None)
    ver_params.add_argument('-r',
                            '--precondition',
                            metavar='<invar>',
                            type=str,
                            required=False,
                            help='invariant properties precondition.')

    ver_params.set_defaults(lemmas=None)
    ver_params.add_argument('-l',
                            '--lemmas',
                            metavar='<invar list>',
                            type=str,
                            required=False,
                            help='comma separated list of lemmas.')

    ver_params.set_defaults(assumptions=None)
    ver_params.add_argument(
        '-a',
        '--assumptions',
        metavar='<invar assumptions list>',
        type=str,
        required=False,
        help='semi column separated list of invariant assumptions.')

    ver_params.add_argument(
        '--generators',
        metavar='generators',
        type=str,
        nargs='?',
        help='semi column separated list of generators instantiation.')

    ver_params.set_defaults(prove=False)
    ver_params.add_argument(
        '--prove',
        dest='prove',
        action='store_true',
        help=
        "use indution to prove the satisfiability of the property. (Default is \"%s\")"
        % False)

    ver_params.set_defaults(assume_if_true=False)
    ver_params.add_argument(
        '--assume-if-true',
        dest='assume_if_true',
        action='store_true',
        help="add true properties as assumptions. (Default is \"%s\")" % False)

    ver_params.set_defaults(coi=False)
    ver_params.add_argument(
        '--coi',
        dest='coi',
        action='store_true',
        help="enables Cone of Influence. (Default is \"%s\")" % False)

    ver_params.set_defaults(cardinality=5)
    ver_params.add_argument(
        '--cardinality',
        dest='cardinality',
        type=int,
        required=False,
        help=
        "bounds number of active parameters. -1 is unbounded. (Default is \"%s\")"
        % 5)

    strategies = [
        " - \"%s\": %s" % (x[0], x[1]) for x in MCConfig.get_strategies()
    ]
    defstrategy = MCConfig.get_strategies()[0][0]
    ver_params.set_defaults(strategy=defstrategy)
    ver_params.add_argument(
        '--strategy',
        metavar='strategy',
        type=str,
        nargs='?',
        help='select the BMC strategy between (Default is \"%s\"):\n%s' %
        (defstrategy, "\n".join(strategies)))

    ver_params.set_defaults(processes=int(multiprocessing.cpu_count() / 2))
    ver_params.add_argument(
        '-j',
        dest='processes',
        metavar="<integer level>",
        type=int,
        help="number of multi-processes for MULTI strategy. (Default is \"%s\")"
        % int(multiprocessing.cpu_count() / 2))

    ver_params.set_defaults(ninc=False)
    ver_params.add_argument(
        '--ninc',
        dest='ninc',
        action='store_true',
        help="disables incrementality. (Default is \"%s\")" % True)

    ver_params.set_defaults(solver_name='msat')
    ver_params.add_argument(
        '--solver-name',
        metavar='<Solver Name>',
        type=str,
        required=False,
        help="name of SMT solver to be use. (Default is \"%s\")" % 'msat')

    # Printing parameters

    print_params = parser.add_problem_group('trace printing')

    print_params.set_defaults(trace_vars_change=False)
    print_params.add_argument(
        '--trace-vars-change',
        dest='trace_vars_change',
        action='store_true',
        help=
        "show variable assignments in the counterexamples even when unchanged. (Default is \"%s\")"
        % False)

    print_params.set_defaults(trace_all_vars=False)
    print_params.add_argument(
        '--trace-all-vars',
        dest='trace_all_vars',
        action='store_true',
        help="show all variables in the counterexamples. (Default is \"%s\")" %
        False)

    print_params.set_defaults(full_trace=False)
    print_params.add_argument(
        '--full-trace',
        dest='full_trace',
        action='store_true',
        help=
        "sets trace-vars-unchanged and trace-all-vars to True. (Default is \"%s\")"
        % False)

    trace_values_base_default = TraceValuesBase.get_all()[0]
    print_params.set_defaults(trace_values_base=trace_values_base_default)
    print_params.add_argument(
        '--trace-values-base',
        metavar='trace_values_base',
        type=str,
        nargs='?',
        help="sets the style of Bit-Vector values printing. (Default is \"%s\")"
        % trace_values_base_default)

    print_params.set_defaults(prefix=None)
    print_params.add_argument(
        '--prefix',
        metavar='<prefix location>',
        type=str,
        required=False,
        help='write the counterexamples with a specified location prefix.')

    # Translation parameters

    trans_params = parser.add_problem_group('translation')

    trans_params.set_defaults(translate=None)
    trans_params.add_argument('--translate',
                              metavar='<output file>',
                              type=str,
                              required=False,
                              help='translate input file.')

    printers = [
        " - \"%s\": %s" % (x.get_name(), x.get_desc()) for x in
        HTSPrintersFactory.get_printers_by_type(HTSPrinterType.TRANSSYS)
    ]

    printer_default = HTSPrintersFactory.get_default().get_name()
    trans_params.set_defaults(printer=printer_default)
    trans_params.add_argument(
        '--printer',
        metavar='printer',
        type=str,
        nargs='?',
        help='select the printer between (Default is \"%s\"):\n%s' %
        (printer_default, "\n".join(printers)))

    trans_params.set_defaults(skip_solving=False)
    trans_params.add_argument(
        '--skip-solving',
        dest='skip_solving',
        action='store_true',
        help="does not call the solver. (Default is \"%s\")" % False)

    # Debugging

    deb_params = parser.add_general_group('verbosity')

    deb_params.set_defaults(verbosity=1)
    deb_params.add_argument('-v',
                            dest='verbosity',
                            metavar="<integer level>",
                            type=int,
                            help="verbosity level. (Default is \"%s\")" % 1)

    deb_params.set_defaults(time=False)
    deb_params.add_argument(
        '--time',
        dest='time',
        action='store_true',
        help="prints time for every verification. (Default is \"%s\")" % False)

    deb_params.set_defaults(devel=False)
    deb_params.add_argument(
        '--devel',
        dest='devel',
        action='store_true',
        help="enables developer mode. (Default is \"%s\")" % False)

    problems = parser.parse_args()

    for problem in problems._problems:
        print(problem)
Пример #4
0
#
########################################################################################

############################### general set up #########################################
wrapper = TextWrapper(initial_indent=" - ")
extra_info = []

devel = False
if DEVEL_OPT in sys.argv:
    sys.argv = [a for a in sys.argv if a != DEVEL_OPT]
    devel = True

extra_info.append(bold_text("\nADDITIONAL INFORMATION:"))

clock_behaviors = []
for x in ClockBehaviorsFactory.get_clockbehaviors():
    wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
    clock_behaviors.append("\n".join(
        wrapper.wrap("\"%s\": %s, parameters (%s)" %
                     (x.get_name(), x.get_desc(), x.get_interface()))))

extra_info.append('\nClock behaviors:\n%s' % ("\n".join(clock_behaviors)))

sugars = []
for x in SyntacticSugarFactory.get_sugars():
    wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
    sugars.append("\n".join(
        wrapper.wrap("\"%s\": %s, parameters (%s)" %
                     (x.get_name(), x.get_desc(), x.get_interface()))))

extra_info.append('\nSpecial operators:\n%s' % ("\n".join(sugars)))
Пример #5
0
def main():
    wrapper = TextWrapper(initial_indent=" - ")
    extra_info = []

    devel = False
    if DEVEL_OPT in sys.argv:
        sys.argv = [a for a in sys.argv if a != DEVEL_OPT]
        devel = True

    extra_info.append(bold_text("\nADDITIONAL INFORMATION:"))

    clock_behaviors = []
    for x in ClockBehaviorsFactory.get_clockbehaviors():
        wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
        clock_behaviors.append("\n".join(
            wrapper.wrap("\"%s\": %s, parameters (%s)" %
                         (x.get_name(), x.get_desc(), x.get_interface()))))

    extra_info.append('\nClock behaviors:\n%s' % ("\n".join(clock_behaviors)))

    sugars = []
    for x in SyntacticSugarFactory.get_sugars():
        wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
        sugars.append("\n".join(
            wrapper.wrap("\"%s\": %s, parameters (%s)" %
                         (x.get_name(), x.get_desc(), x.get_interface()))))

    extra_info.append('\nSpecial operators:\n%s' % ("\n".join(sugars)))

    generators = []
    for x in GeneratorsFactory.get_generators():
        wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
        generators.append("\n".join(
            wrapper.wrap("\"%s\": %s, parameters (%s)" %
                         (x.get_name(), x.get_desc(), x.get_interface()))))

    extra_info.append('\nModule generators:\n%s' % ("\n".join(generators)))

    modifiers = []
    modifiers.append(" - \"None\": No extension")
    for x in ModelModifiersFactory.get_modifiers():
        wrapper.subsequent_indent = " " * (len(" - \"\": " + x.get_name()))
        modifiers.append("\n".join(
            wrapper.wrap("\"%s\": %s" % (x.get_name(), x.get_desc()))))

    extra_info.append('\nModel modifiers:\n%s' % ("\n".join(modifiers)))

    parser = argparse.ArgumentParser(description=bold_text('CoSA: CoreIR Symbolic Analyzer\n..an SMT-based Symbolic Model Checker for Hardware Design'), \
                                     #usage='%(prog)s [options]', \
                                     formatter_class=RawTextHelpFormatter, \
                                     epilog="\n".join(extra_info))

    config = Config()

    # Main inputs

    in_options = parser.add_argument_group('input options')

    av_input_types = [" - \"%s\": %s"%(x.name, ", ".join(["*.%s"%e for e in x.extensions])) \
                      for x in ModelParsersFactory.get_parsers() if x.is_available()]

    ua_input_types = [" - \"%s\": %s"%(x.name, ", ".join(["*.%s"%e for e in x.extensions])) \
                      for x in ModelParsersFactory.get_parsers() if not x.is_available()]

    in_options.set_defaults(input_files=None)
    in_options.add_argument('-i', '--input_files', metavar='<input files>', type=str, required=False,
                            help='comma separated list of input files.\nSupported types:\n%s%s'%\
                            ("\n".join(av_input_types), "\nNot enabled:\n%s"%("\n".join(ua_input_types)) \
                             if len(ua_input_types) > 0 else ""))

    in_options.set_defaults(problems=None)
    in_options.add_argument(
        '--problems',
        metavar='<problems file>',
        type=str,
        required=False,
        help='problems file describing the verifications to be performed.')

    # Verification Options

    ver_options = parser.add_argument_group('analysis')

    ver_options.set_defaults(safety=False)
    ver_options.add_argument('--safety',
                             dest='safety',
                             action='store_true',
                             help='safety verification using BMC.')

    ver_options.set_defaults(ltl=False)
    ver_options.add_argument('--ltl',
                             dest='ltl',
                             action='store_true',
                             help='ltl verification using BMC.')

    ver_options.set_defaults(simulate=False)
    ver_options.add_argument('--simulate',
                             dest='simulate',
                             action='store_true',
                             help='simulate system using BMC.')

    ver_options.set_defaults(equivalence=None)
    ver_options.add_argument('--equivalence',
                             metavar='<input files>',
                             type=str,
                             required=False,
                             help='equivalence checking using BMC.')

    ver_options.set_defaults(fsm_check=False)
    ver_options.add_argument(
        '--fsm-check',
        dest='fsm_check',
        action='store_true',
        help='check if the state machine is deterministic.')

    ver_options.set_defaults(parametric=False)
    ver_options.add_argument('--parametric',
                             dest='parametric',
                             action='store_true',
                             help='parametric analysis using BMC.')

    # Verification parameters

    ver_params = parser.add_argument_group('verification parameters')

    ver_params.set_defaults(properties=None)
    ver_params.add_argument('-p',
                            '--properties',
                            metavar='<invar list>',
                            type=str,
                            required=False,
                            help='comma separated list of properties.')

    ver_params.set_defaults(bmc_length=config.bmc_length)
    ver_params.add_argument(
        '-k',
        '--bmc-length',
        metavar='<BMC length>',
        type=int,
        required=False,
        help="depth of BMC unrolling. (Default is \"%s\")" % config.bmc_length)

    ver_params.set_defaults(bmc_length_min=config.bmc_length_min)
    ver_params.add_argument(
        '-km',
        '--bmc-length-min',
        metavar='<BMC length>',
        type=int,
        required=False,
        help="minimum depth of BMC unrolling. (Default is \"%s\")" %
        config.bmc_length_min)

    ver_params.set_defaults(precondition=None)
    ver_params.add_argument('-r',
                            '--precondition',
                            metavar='<invar>',
                            type=str,
                            required=False,
                            help='invariant properties precondition.')

    ver_params.set_defaults(lemmas=None)
    ver_params.add_argument('-l',
                            '--lemmas',
                            metavar='<invar list>',
                            type=str,
                            required=False,
                            help='comma separated list of lemmas.')

    ver_params.set_defaults(assumptions=None)
    ver_params.add_argument(
        '-a',
        '--assumptions',
        metavar='<invar assumptions list>',
        type=str,
        required=False,
        help='semi column separated list of invariant assumptions.')

    ver_params.add_argument(
        '--generators',
        metavar='generators',
        type=str,
        nargs='?',
        help='semi column separated list of generators instantiation.')

    ver_params.add_argument(
        '--clock-behaviors',
        metavar='clock_behaviors',
        type=str,
        nargs='?',
        help='semi column separated list of clock behaviors instantiation.')

    ver_params.set_defaults(prove=False)
    ver_params.add_argument(
        '--prove',
        dest='prove',
        action='store_true',
        help=
        "use indution to prove the satisfiability of the property. (Default is \"%s\")"
        % config.prove)

    ver_params.set_defaults(assume_if_true=False)
    ver_params.add_argument(
        '--assume-if-true',
        dest='assume_if_true',
        action='store_true',
        help="add true properties as assumptions. (Default is \"%s\")" %
        config.assume_if_true)

    ver_params.set_defaults(coi=False)
    ver_params.add_argument(
        '--coi',
        dest='coi',
        action='store_true',
        help="enables Cone of Influence. (Default is \"%s\")" % config.coi)

    ver_params.set_defaults(cardinality=config.cardinality)
    ver_params.add_argument(
        '--cardinality',
        dest='cardinality',
        type=int,
        required=False,
        help=
        "bounds number of active parameters. -1 is unbounded. (Default is \"%s\")"
        % config.cardinality)

    strategies = [
        " - \"%s\": %s" % (x[0], x[1]) for x in MCConfig.get_strategies()
    ]
    defstrategy = MCConfig.get_strategies()[0][0]
    ver_params.set_defaults(strategy=defstrategy)
    ver_params.add_argument(
        '--strategy',
        metavar='strategy',
        type=str,
        nargs='?',
        help='select the BMC strategy between (Default is \"%s\"):\n%s' %
        (defstrategy, "\n".join(strategies)))

    ver_params.set_defaults(processes=config.processes)
    ver_params.add_argument(
        '-j',
        dest='processes',
        metavar="<integer level>",
        type=int,
        help="number of multi-processes for MULTI strategy. (Default is \"%s\")"
        % config.processes)

    ver_params.set_defaults(ninc=False)
    ver_params.add_argument(
        '--ninc',
        dest='ninc',
        action='store_true',
        help="disables incrementality. (Default is \"%s\")" %
        (not config.incremental))

    ver_params.set_defaults(solver_name=config.solver_name)
    ver_params.add_argument(
        '--solver-name',
        metavar='<Solver Name>',
        type=str,
        required=False,
        help="name of SMT solver to be use. (Default is \"%s\")" %
        config.solver_name)

    # Encoding parameters

    enc_params = parser.add_argument_group('encoding')

    enc_params.set_defaults(cache_files=False)
    enc_params.add_argument(
        '-c',
        '--cache-files',
        dest='cache_files',
        action='store_true',
        help="caches encoded files to speed-up parsing. (Default is \"%s\")" %
        config.cache_files)

    enc_params.set_defaults(add_clock=False)
    enc_params.add_argument('--add-clock',
                            dest='add_clock',
                            action='store_true',
                            help="adds clock behavior. (Default is \"%s\")" %
                            config.add_clock)

    enc_params.set_defaults(abstract_clock=False)
    enc_params.add_argument(
        '--abstract-clock',
        dest='abstract_clock',
        action='store_true',
        help="abstracts the clock behavior. (Default is \"%s\")" %
        config.abstract_clock)

    enc_params.set_defaults(symbolic_init=config.symbolic_init)
    enc_params.add_argument(
        '--symbolic-init',
        dest='symbolic_init',
        action='store_true',
        help='removes constraints on the initial state. (Default is \"%s\")' %
        config.symbolic_init)

    enc_params.set_defaults(zero_init=config.zero_init)
    enc_params.add_argument(
        '--zero-init',
        dest='zero_init',
        action='store_true',
        help='sets initial state to zero. (Default is \"%s\")' %
        config.zero_init)

    enc_params.set_defaults(boolean=config.boolean)
    enc_params.add_argument(
        '--boolean',
        dest='boolean',
        action='store_true',
        help=
        'interprets single bits as Booleans instead of 1-bit Bitvector. (Default is \"%s\")'
        % config.boolean)

    enc_params.set_defaults(run_passes=config.run_passes)
    enc_params.add_argument(
        '--no-run-passes',
        dest='run_passes',
        action='store_false',
        help='does not run CoreIR passes. (Default is \"%s\")' %
        config.run_passes)

    enc_params.set_defaults(model_extension=config.model_extension)
    enc_params.add_argument(
        '--model-extension',
        metavar='model_extension',
        type=str,
        nargs='?',
        help='select the model modifier. (Default is \"%s\")' %
        (config.model_extension))

    # Printing parameters

    print_params = parser.add_argument_group('trace printing')

    print_params.set_defaults(trace_vars_change=config.trace_vars_change)
    print_params.add_argument(
        '--trace-vars-change',
        dest='trace_vars_change',
        action='store_true',
        help=
        "show variable assignments in the counterexamples even when unchanged. (Default is \"%s\")"
        % config.trace_vars_change)

    print_params.set_defaults(trace_all_vars=config.trace_all_vars)
    print_params.add_argument(
        '--trace-all-vars',
        dest='trace_all_vars',
        action='store_true',
        help="show all variables in the counterexamples. (Default is \"%s\")" %
        config.trace_all_vars)

    print_params.set_defaults(full_trace=config.full_trace)
    print_params.add_argument(
        '--full-trace',
        dest='full_trace',
        action='store_true',
        help=
        "sets trace-vars-unchanged and trace-all-vars to True. (Default is \"%s\")"
        % config.full_trace)

    print_params.set_defaults(prefix=None)
    print_params.add_argument(
        '--prefix',
        metavar='<prefix location>',
        type=str,
        required=False,
        help='write the counterexamples with a specified location prefix.')

    print_params.set_defaults(vcd=False)
    print_params.add_argument(
        '--vcd',
        dest='vcd',
        action='store_true',
        help="generate traces also in vcd format. (Default is \"%s\")" %
        config.vcd)

    # Translation parameters

    trans_params = parser.add_argument_group('translation')

    trans_params.set_defaults(translate=None)
    trans_params.add_argument('--translate',
                              metavar='<output file>',
                              type=str,
                              required=False,
                              help='translate input file.')

    printers = [
        " - \"%s\": %s" % (x.get_name(), x.get_desc()) for x in
        HTSPrintersFactory.get_printers_by_type(HTSPrinterType.TRANSSYS)
    ]

    trans_params.set_defaults(printer=config.printer)
    trans_params.add_argument(
        '--printer',
        metavar='printer',
        type=str,
        nargs='?',
        help='select the printer between (Default is \"%s\"):\n%s' %
        (config.printer, "\n".join(printers)))

    trans_params.set_defaults(skip_solving=False)
    trans_params.add_argument(
        '--skip-solving',
        dest='skip_solving',
        action='store_true',
        help="does not call the solver. (Default is \"%s\")" %
        config.skip_solving)

    # Debugging

    deb_params = parser.add_argument_group('verbosity')

    deb_params.set_defaults(verbosity=config.verbosity)
    deb_params.add_argument('-v',
                            dest='verbosity',
                            metavar="<integer level>",
                            type=int,
                            help="verbosity level. (Default is \"%s\")" %
                            config.verbosity)

    deb_params.set_defaults(time=False)
    deb_params.add_argument(
        '--time',
        dest='time',
        action='store_true',
        help="prints time for every verification. (Default is \"%s\")" %
        config.time)

    deb_params.set_defaults(devel=False)
    deb_params.add_argument(
        '--devel',
        dest='devel',
        action='store_true',
        help="enables developer mode. (Default is \"%s\")" % config.devel)

    # Developers

    if devel:
        config.devel = True
        devel_params = parser.add_argument_group('developer')

        devel_params.set_defaults(smt2=None)
        devel_params.add_argument(
            '--smt2',
            metavar='<smt-lib2 file>',
            type=str,
            required=False,
            help='generates the smtlib2 tracing file for each solver call.')

    args = parser.parse_args()

    config.strfiles = args.input_files
    config.simulate = args.simulate
    config.safety = args.safety
    config.parametric = args.parametric
    config.ltl = args.ltl
    config.properties = args.properties
    config.lemmas = args.lemmas
    config.precondition = args.precondition
    config.assumptions = args.assumptions
    config.equivalence = args.equivalence
    config.symbolic_init = args.symbolic_init
    config.zero_init = args.zero_init
    config.fsm_check = args.fsm_check
    config.bmc_length = args.bmc_length
    config.bmc_length_min = args.bmc_length_min
    config.full_trace = args.full_trace
    config.trace_vars_change = args.trace_vars_change
    config.trace_all_vars = args.trace_all_vars
    config.prefix = args.prefix
    config.translate = args.translate
    config.strategy = args.strategy
    config.processes = args.processes
    config.skip_solving = args.skip_solving
    config.abstract_clock = args.abstract_clock
    config.boolean = args.boolean
    config.verbosity = args.verbosity
    config.vcd = args.vcd
    config.prove = args.prove
    config.solver_name = args.solver_name
    config.incremental = not args.ninc
    config.time = args.time
    config.add_clock = args.add_clock
    config.generators = args.generators
    config.clock_behaviors = args.clock_behaviors
    config.assume_if_true = args.assume_if_true
    config.coi = args.coi
    config.model_extension = args.model_extension
    config.cardinality = args.cardinality
    config.cache_files = args.cache_files

    if devel:
        config.smt2file = args.smt2

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit(1)

    if args.printer in [
            str(x.get_name()) for x in HTSPrintersFactory.get_printers_by_type(
                HTSPrinterType.TRANSSYS)
    ]:
        config.printer = args.printer
    else:
        Logger.error("Printer \"%s\" not found" % (args.printer))

    if args.problems:
        if config.devel:
            sys.exit(run_problems(args.problems, config))
        else:
            try:
                sys.exit(run_problems(args.problems, config))
            except Exception as e:
                Logger.error(str(e), False)
                sys.exit(1)

    Logger.error_raise_exept = False

    if (args.problems is None) and (args.input_files is None):
        Logger.error("No input files provided")

    if args.strategy not in [s[0] for s in MCConfig.get_strategies()]:
        Logger.error("Strategy \"%s\" not found" % (args.strategy))

    if not(config.simulate or \
           (config.safety) or \
           (config.parametric) or \
           (config.ltl) or \
           (config.equivalence is not None) or\
           (config.translate is not None) or\
           (config.fsm_check)):
        Logger.error("Analysis selection is necessary")

    Logger.error_raise_exept = True

    if config.devel:
        sys.exit(run_verification(config))
    else:
        try:
            sys.exit(run_verification(config))
        except Exception as e:
            Logger.error(str(e), False)
            sys.exit(1)
Пример #6
0
    def apply_to_problem(problem, model_info):
        varsdict = dict([(var.symbol_name(), var) for var in problem.hts.vars])

        if problem.generators is not None:

            for strgenerator in problem.generators.split(MODEL_SP):
                strgenerator = strgenerator.replace(" ", "")
                if strgenerator == "":
                    continue

                eqpos = strgenerator.find("=")
                parstart = strgenerator.find("(")
                if (parstart < eqpos) or (eqpos == -1):
                    Logger.error("Invalid generators")

                instance = strgenerator[:eqpos:]
                mdef = strgenerator[eqpos + 1:]
                mtype = mdef.split("(")[0]
                pars = mdef[mdef.find("(") + 1:-1].split(PAR_SP)
                generator = GeneratorsFactory.generator_by_name(mtype)
                pars = [varsdict[v] if v in varsdict else v for v in pars]
                ts = generator.get_sts(instance, pars)

                problem.hts.add_ts(ts)

        if problem.add_clock and (problem.clock_behaviors is None):
            clk_behs = []

            for (clock, (before, after)) in model_info.abstract_clock_list:
                if (clock not in model_info.clock_list) or (clock in clk_behs):
                    continue
                clock_behavior = ClockBehaviorsFactory.get_default_abstract()
                ts = clock_behavior.get_default([clock, after])
                clk_behs.append(clock)
                problem.hts.add_ts(ts)

            clock_list = [
                c for c in model_info.clock_list if c not in clk_behs
            ]
            for clock in clock_list:
                if len(clock_list) > 1:
                    clock_behavior = ClockBehaviorsFactory.get_default_multi()
                else:
                    clock_behavior = ClockBehaviorsFactory.get_default()
                ts = clock_behavior.get_default([clock])
                clk_behs.append(clock)
                problem.hts.add_ts(ts)

            assert len(clk_behs) == len(set(clk_behs))

        if problem.clock_behaviors is not None:

            for strcb in problem.clock_behaviors.split(MODEL_SP):
                strcb = strcb.replace(" ", "")

                if strcb == "":
                    continue

                parstart = strcb.find("(")
                parend = strcb.find(")")

                if (parstart == -1) or (parend == -1) or (parstart > parend):
                    Logger.error("Invalid Clock Behavior definition")

                cbname = strcb[:parstart]
                pars = strcb[parstart + 1:parend].split(PAR_SP)
                pars = [varsdict[v] if v in varsdict else v for v in pars]

                clock_behavior = ClockBehaviorsFactory.clockbehavior_by_name(
                    cbname)
                ts = clock_behavior.get_sts(pars)

                problem.hts.add_ts(ts)