コード例 #1
0
def translate(hts, config, formulae=None):
    Logger.log("\nWriting system to \"%s\"" % (config.translate), 0)
    printer = HTSPrintersFactory.printer_by_name(config.printer)
    props = []
    if formulae is not None:
        props = [(f.serialize(threshold=100), f, None) for f in formulae
                 if f is not None]
    with open(config.translate, "w") as f:
        f.write(printer.print_hts(hts, props))
コード例 #2
0
def translate(hts, config, formulae=None):
    # TODO: Fix this for the formulae which are not pysmt nodes at this point
    #       accessing the problem copy of it which is still a string
    Logger.log("\nWriting system to \"%s\""%(config.translate), 0)
    printer = HTSPrintersFactory.printer_by_name(config.printer)
    props = []
    if formulae is not None:
        for f in formulae:
            if f is None:
                continue
            assert isinstance(f, FNode), "Expecting parsed properties"
            props.append(f)

    with open(config.translate, "w") as f:
        f.write(printer.print_hts(hts, props))
コード例 #3
0
ファイル: dispatcher.py プロジェクト: Zheng-Tong/CoSA
    def _to_cache(self, cachedir, filename, hts, inv, ltl, model_info):
        if not os.path.isdir(cachedir):
            os.makedirs(cachedir)

        hts_file = "%s/%s.ssts" % (cachedir, filename)
        mi_file = "%s/%s.mi" % (cachedir, filename)
        inv_file = "%s/%s.inv" % (cachedir, filename)
        ltl_file = "%s/%s.ltl" % (cachedir, filename)

        printer = HTSPrintersFactory.printer_by_name(
            STSHTSPrinter().get_name())
        with open(hts_file, "w") as f:
            f.write(printer.print_hts(hts, properties=[], ftrans=True))

        with open(mi_file, 'wb') as f:
            pickle.dump(model_info, f)

        with open(inv_file, 'wb') as f:
            pickle.dump(inv, f)

        with open(ltl_file, 'wb') as f:
            pickle.dump(ltl, f)
コード例 #4
0
ファイル: custom.py プロジェクト: yuex1994/CoSA
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)
コード例 #5
0
    required=False,
    help='write the counterexamples with a specified location prefix.')

# General translation parameters
general_trans_params = cosa_option_manager.add_general_group('translation')

general_trans_params.set_defaults(translate=None)
general_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()
general_trans_params.set_defaults(printer=printer_default)
general_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)))

# Problem-specific translation parameters

trans_params = cosa_option_manager.add_problem_group('translation')
コード例 #6
0
    def __init__(self):
        HTSPrintersFactory.init_printers()

        self.printer = HTSPrintersFactory.get_default().get_name()
        self.strategy = MCConfig.get_strategies()[0][0]
コード例 #7
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)
コード例 #8
0
ファイル: options.py プロジェクト: yuex1994/CoSA
problem_print_params.set_defaults(trace_values_base=trace_values_base_default)
problem_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)

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

# General translation parameters
general_trans_params = cosa_option_manager.add_general_group('translation')

general_trans_params.set_defaults(translate=None)
general_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()
general_trans_params.set_defaults(printer=printer_default)
general_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)))

# Problem-specific translation parameters

trans_params = cosa_option_manager.add_problem_group('translation')

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
コード例 #9
0
ファイル: coi.py プロジェクト: yuex1994/CoSA
    def compute(self, hts, prop):
        Logger.log("Building COI", 1)

        self._build_var_deps(hts)

        coi_vars = set(self._free_variables(prop))

        if (len(coi_vars) < 1) or (self.var_deps == {}):
            return hts

        if hts.assumptions is not None:
            for assumption in hts.assumptions:
                for v in self._free_variables(assumption):
                    coi_vars.add(v)

        if hts.lemmas is not None:
            for lemma in hts.lemmas:
                for v in self._free_variables(lemma):
                    coi_vars.add(v)

        coits = TS("COI")

        coi_vars = list(coi_vars)
        i = 0
        visited = set([])
        while i < len(coi_vars):
            var = coi_vars[i]
            if (var in visited) or (var not in self.var_deps):
                i += 1
                continue

            coi_vars = coi_vars[:i + 1] + list(
                self.var_deps[var]) + coi_vars[i + 1:]

            visited.add(var)
            i += 1

        coi_vars = frozenset(coi_vars)

        trans = list(
            conjunctive_partition(hts.single_trans(include_ftrans=True)))
        invar = list(
            conjunctive_partition(hts.single_invar(include_ftrans=True)))
        init = list(conjunctive_partition(hts.single_init()))

        coits.trans = [
            f for f in trans
            if self._intersect(coi_vars, self._free_variables(f))
        ]
        coits.invar = [
            f for f in invar
            if self._intersect(coi_vars, self._free_variables(f))
        ]
        coits.init = [
            f for f in init
            if self._intersect(coi_vars, self._free_variables(f))
        ]

        Logger.log("COI statistics:", 1)
        Logger.log("  Vars:  %s -> %s" % (len(hts.vars), len(coi_vars)), 1)
        Logger.log("  Init:  %s -> %s" % (len(init), len(coits.init)), 1)
        Logger.log("  Invar: %s -> %s" % (len(invar), len(coits.invar)), 1)
        Logger.log("  Trans: %s -> %s" % (len(trans), len(coits.trans)), 1)

        coits.trans = And(coits.trans)
        coits.invar = And(coits.invar)
        coits.init = And(coits.init)

        coits.vars = set([])
        for bf in [init, invar, trans]:
            for f in bf:
                for v in self._free_variables(f):
                    coits.vars.add(v)

        coits.input_vars = set([v for v in coi_vars if v in hts.input_vars])
        coits.output_vars = set([v for v in coi_vars if v in hts.output_vars])
        coits.state_vars = set([v for v in coi_vars if v in hts.state_vars])

        new_hts = HTS("COI")
        new_hts.add_ts(coits)

        if self.save_model:
            printer = HTSPrintersFactory.printer_by_name("STS")
            with open("/tmp/coi_model.ssts", "w") as f:
                f.write(printer.print_hts(new_hts, []))

        return new_hts