Beispiel #1
0
def proof_command_wrapper(prooffunc, category_name, command_name, change):

    def wrapper(argv):
        
        usage = "usage: %prog [options] <aig_file>"
    
        parser = optparse.OptionParser(usage, prog=command_name)
    
        parser.add_option("-n", "--no_redirect", dest="noisy", action="store_true", default=False, help="don't redirect output")
        parser.add_option("-d", "--current_dir", dest="current_dir", action="store_true", default=False, help="stay in current directory")

        options, args = parser.parse_args(argv)
        
        if len(args) != 2:
            print args
            parser.print_usage()
            return 0
            
        aig_filename = os.path.abspath(args[1])

        if not options.noisy:
            pyabc.run_command('/pushredirect')
            
        if not options.current_dir:
            pyabc.run_command('/pushdtemp')
            
        try:
            for d in os.environ['PATH'].split(':'):
                bip = os.path.join(d, 'bip')
                if os.path.exists(bip):
                    pyabc.run_command("load_plugin %s Bip"%bip)
                    break

            basename = os.path.basename( aig_filename )
            shutil.copyfile(aig_filename, basename)
            aig_filename = basename

            par.read_file_quiet(aig_filename)
            result = prooffunc()
            
            par.cex_list = []
        except:
            result = None

        if not options.current_dir:
            pyabc.run_command('/popdtemp')

        if not options.noisy:
            pyabc.run_command('/popredirect')
                
        if result=="SAT":
            print 1
        elif result=="UNSAT":
            print 0
        else:
            print 2

        return 0
    
    pyabc.add_abc_command(wrapper, category_name, command_name, change)
#   The first argument is always the name of the command
#   It MUST return an integer. -1: user quits, -2: error. Return 0 for success.

# a command that calls prove(1) and returns success
def prove_cmd(args):
    result = abc_common.prove(1)
    print result
    return 0

# registers the command:
#   The first argument is the function
#   The second argument is the category (mainly for the ABC help command)
#   The third argument is the new command name
#   Keep the fourth argument 0, or consult with Alan

pyabc.add_abc_command(prove_cmd, "ZPython", "/prove", 0)

def read_cmd(args):
    if len(args)==2:
        abc_common.read_file_quiet(args[1])
    else:
        abc_common.read_file()
    return 0

pyabc.add_abc_command(read_cmd, "ZPython", "/rf", 0)

def chdir_cmd(args):
    os.chdir( args[1] )
    return 0

pyabc.add_abc_command(chdir_cmd, "ZPython", "/cd", 0)
Beispiel #3
0
def proof_command_wrapper_internal(prooffunc,
                                   category_name,
                                   command_name,
                                   change,
                                   multi=False):
    def wrapper(argv):

        usage = "usage: %prog [options] <aig_file>"

        parser = optparse.OptionParser(usage, prog=command_name)

        parser.add_option("-n",
                          "--no_redirect",
                          dest="noisy",
                          action="store_true",
                          default=False,
                          help="don't redirect output")
        parser.add_option("-d",
                          "--current_dir",
                          dest="current_dir",
                          action="store_true",
                          default=False,
                          help="stay in current directory")

        options, args = parser.parse_args(argv)

        if len(args) != 2:
            parser.print_usage()
            return 0

        aig_filename = os.path.abspath(args[1])

        with replace_report_result(multi):

            if not options.noisy:
                pyabc.run_command('/pushredirect')

            if not options.current_dir:
                pyabc.run_command('/pushdtemp')

            try:
                for d in os.environ['PATH'].split(':'):
                    bip = os.path.join(d, 'bip')
                    if os.path.exists(bip):
                        pyabc.run_command("load_plugin %s Bip" % bip)
                        break

                basename = os.path.basename(aig_filename)
                shutil.copyfile(aig_filename, basename)
                aig_filename = basename

                result = prooffunc(aig_filename)

                par.cex_list = []
            except:
                result = None

            if not multi:

                if result == "SAT":
                    par.report_result(0, 1)
                elif result == "UNSAT":
                    par.report_result(0, 0)
                elif type(result
                          ) == list and len(result) > 0 and result[0] == "SAT":
                    par.report_result(0, 1)
                elif type(result) == list and len(
                        result) > 0 and result[0] == "UNSAT":
                    par.report_result(0, 0)
                else:
                    par.report_result(0, 2)

            if not options.current_dir:
                pyabc.run_command('/popdtemp')

            if not options.noisy:
                pyabc.run_command('/popredirect')

        return 0

    pyabc.add_abc_command(wrapper, category_name, command_name, change)
Beispiel #4
0
import shutil
import redirect
import optparse

from contextlib import contextmanager


def read_cmd(args):
    if len(args) == 2:
        par.read_file_quiet(args[1])
    else:
        par.read_file()
    return 0


pyabc.add_abc_command(read_cmd, "ZPython", "/rf", 0)


def chdir_cmd(args):
    os.chdir(args[1])
    return 0


pyabc.add_abc_command(chdir_cmd, "ZPython", "/cd", 0)


def pwd_cmd(args):
    print os.getcwd()
    return 0

Beispiel #5
0
        rc = wait_with_timeout(p,timeout)
        
        if rc != 0:
            # jabc failed or stopped. Write a status file to update the status to unknown
            with open(tmplog_name, "w") as f:
                f.write('snl_UNK -1 unknown\n')
                f.write('NULL\n')
                f.write('NULL\n')
            
        pyabc.run_command("read_status %s"%tmplog_name)
        
        return rc

def reachx_cmd(argv):
    usage = "usage: %prog [options]"
    
    parser = optparse.OptionParser(usage)
    
    parser.add_option("-e", "--effort", dest="effort", type=int, default=0, help="effort level. [default=0, means unlimited]")
    parser.add_option("-t", "--timeout", dest="timeout", type=int, default=0, help="timeout in seconds [default=0, unlimited]")

    with replace_sys_argv(argv):
        options, args = parser.parse_args()

    rc = run_reachx_cmd(options.effort, options.timeout)
    print "%s command: jabc returned: %d"%(argv[0], rc)
    
    return 0

pyabc.add_abc_command(reachx_cmd, "Verification", "reachx", 0)
# A new command is just a function that accepts a list of string arguments
#   The first argument is always the name of the command
#   It MUST return an integer. -1: user quits, -2: error. Return 0 for success.

# a simple command that just prints its arguments and returns success
def pytest1_cmd(args):
    print args
    return 0

# registers the command:
#   The first argument is the function
#   The second argument is the category (mainly for the ABC help command)
#   The third argument is the new command name
#   Keet the fourth argument 0, or consult with Alan
pyabc.add_abc_command(pytest1_cmd, "Python-Test", "pytest1", 0)

# a simple command that just prints its arguments and runs the command 'scorr -h'
def pytest2_cmd(args):
    print args
    pyabc.run_command('scorr -h')
    return 0

pyabc.add_abc_command(pytest2_cmd, "Python-Test", "pytest2", 0)

# Now a more complicated command with argument parsing
# This command gets two command line arguments -c and -v. -c cmd runs the command 'cmd -h' and -v prints the python version
# for more details see the optparse module: http://docs.python.org/library/optparse.html

import optparse
def proof_command_wrapper_internal(prooffunc, category_name, command_name, change, multi=False):
    def wrapper(argv):

        usage = "usage: %prog [options] <aig_file>"

        parser = optparse.OptionParser(usage, prog=command_name)

        parser.add_option(
            "-n", "--no_redirect", dest="noisy", action="store_true", default=False, help="don't redirect output"
        )
        parser.add_option(
            "-d",
            "--current_dir",
            dest="current_dir",
            action="store_true",
            default=False,
            help="stay in current directory",
        )

        options, args = parser.parse_args(argv)

        if len(args) != 2:
            parser.print_usage()
            return 0

        aig_filename = os.path.abspath(args[1])

        with replace_report_result(multi):

            if not options.noisy:
                pyabc.run_command("/pushredirect")

            if not options.current_dir:
                pyabc.run_command("/pushdtemp")

            try:
                for d in os.environ["PATH"].split(":"):
                    bip = os.path.join(d, "bip")
                    if os.path.exists(bip):
                        pyabc.run_command("load_plugin %s Bip" % bip)
                        break

                basename = os.path.basename(aig_filename)
                shutil.copyfile(aig_filename, basename)
                aig_filename = basename

                result = prooffunc(aig_filename)

                par.cex_list = []
            except:
                result = None

            if not multi:

                if result == "SAT":
                    par.report_result(0, 1)
                elif result == "UNSAT":
                    par.report_result(0, 0)
                elif type(result) == list and len(result) > 0 and result[0] == "SAT":
                    par.report_result(0, 1)
                elif type(result) == list and len(result) > 0 and result[0] == "UNSAT":
                    par.report_result(0, 0)
                else:
                    par.report_result(0, 2)

            if not options.current_dir:
                pyabc.run_command("/popdtemp")

            if not options.noisy:
                pyabc.run_command("/popredirect")

        return 0

    pyabc.add_abc_command(wrapper, category_name, command_name, change)
Beispiel #8
0
        return rc


def reachx_cmd(argv):
    usage = "usage: %prog [options]"

    parser = optparse.OptionParser(usage, prog="reachx")

    parser.add_option("-e",
                      "--effort",
                      dest="effort",
                      type=int,
                      default=0,
                      help="effort level. [default=0, means unlimited]")
    parser.add_option("-t",
                      "--timeout",
                      dest="timeout",
                      type=int,
                      default=0,
                      help="timeout in seconds [default=0, unlimited]")

    options, args = parser.parse_args(argv)

    rc = run_reachx_cmd(options.effort, options.timeout)
    print "%s command: jabc returned: %d" % (argv[0], rc)

    return 0


pyabc.add_abc_command(reachx_cmd, "Verification", "reachx", 0)
Beispiel #9
0
# A new command is just a function that accepts a list of string arguments
#   The first argument is always the name of the command
#   It MUST return an integer. -1: user quits, -2: error. Return 0 for success.

# a simple command that just prints its arguments and returns success
def pytest1_cmd(args):
    print args
    return 0

# registers the command:
#   The first argument is the function
#   The second argument is the category (mainly for the ABC help command)
#   The third argument is the new command name
#   Keet the fourth argument 0, or consult with Alan
pyabc.add_abc_command(pytest1_cmd, "Python-Test", "pytest1", 0)

# a simple command that just prints its arguments and runs the command 'scorr -h'
def pytest2_cmd(args):
    print args
    pyabc.run_command('scorr -h')
    return 0

pyabc.add_abc_command(pytest2_cmd, "Python-Test", "pytest2", 0)

# Now a more complicated command with argument parsing
# This command gets two command line arguments -c and -v. -c cmd runs the command 'cmd -h' and -v prints the python version
# for more details see the optparse module: http://docs.python.org/library/optparse.html

import optparse
Beispiel #10
0
def proof_command_wrapper_internal(prooffunc,
                                   category_name,
                                   command_name,
                                   change,
                                   multi=False,
                                   write_cex=False,
                                   bmc_depth=False,
                                   do_reporting=True):
    def wrapper(argv):

        usage = "usage: %prog [options] <aig_file>"

        parser = optparse.OptionParser(usage, prog=command_name)

        parser.add_option("-n",
                          "--no_redirect",
                          dest="noisy",
                          action="store_true",
                          default=False,
                          help="don't redirect output")
        parser.add_option("-r",
                          "--redirect",
                          dest="redirect",
                          default=None,
                          help="redirect output to file")
        parser.add_option("-d",
                          "--current_dir",
                          dest="current_dir",
                          action="store_true",
                          default=False,
                          help="stay in current directory")

        options, args = parser.parse_args(argv)

        if len(args) != 2:
            parser.print_usage()
            return 0

        if options.noisy and options.redirect:
            print 'error: options -n/--no_redirect and -r/--redirect are mutually exclusive'
            return 0

        aig_filename = os.path.abspath(args[1])

        with replace_report_result(write_cex=write_cex,
                                   bmc_depth=bmc_depth) as old_stdout:

            if options.redirect:
                pyabc.run_command('/pushredirect %s' % options.redirect)
            elif not options.noisy:
                pyabc.run_command('/pushredirect')

            if not options.current_dir:
                pyabc.run_command('/pushdtemp')

            try:
                basename = os.path.basename(aig_filename)
                shutil.copyfile(aig_filename, basename)
                aig_filename = basename

                result = prooffunc(aig_filename, old_stdout)

                par.cex_list = []
            except:
                import traceback
                traceback.print_exc()
                result = None

            if do_reporting and not multi:

                if result == "SAT":
                    par.report_result(0, 1)
                elif result == "UNSAT":
                    par.report_result(0, 0)
                elif type(result
                          ) == list and len(result) > 0 and result[0] == "SAT":
                    par.report_result(0, 1)
                elif type(result) == list and len(
                        result) > 0 and result[0] == "UNSAT":
                    par.report_result(0, 0)
                else:
                    par.report_result(0, 2)

            if not options.current_dir:
                pyabc.run_command('/popdtemp')

            if not options.noisy:
                pyabc.run_command('/popredirect')

        return 0

    pyabc.add_abc_command(wrapper, category_name, command_name, change)