Exemple #1
0
def barcelogic_extract_search_status(tracefile):
    """Extracts and returns the search status from the
    given tracefile."""

    ret = common.UNKNOWN

    if not common.is_file_empty(tracefile):

        uns_regex = re.compile(rb"^unsat\r?$", re.MULTILINE)
        sat_regex = re.compile(rb"^sat\r?$", re.MULTILINE)
        opt_regex = re.compile(rb"^\(optimal .*\)\r?$", re.MULTILINE)

        with io.open(tracefile, 'r', newline=None) as fd_trace:
            with mmap.mmap(fd_trace.fileno(), 0, access=mmap.ACCESS_READ) as output:

                uns_match = re.search(uns_regex, output)
                sat_match = re.search(sat_regex, output)
                opt_match = re.search(opt_regex, output)

                # NOTE: in Barcelogic, this may be violated if the optimization
                # search interval is unsatisfiable for one optimization goal but
                # satisfiable for another (requires multi-objective optimization).
                # Currently, we do not handle this corner case. Report any violation.
                assert sum([bool(x) for x in (uns_match, sat_match, opt_match)]) <= 1

                if any((sat_match, opt_match)):
                    ret = common.SAT
                elif uns_match:
                    ret = common.UNSAT
                else:
                    ret = common.UNKNOWN

    return ret
Exemple #2
0
def cvc4_extract_search_status(tracefile):
    """Extracts and returns the search status from the
    given tracefile."""

    ret = common.UNKNOWN

    if not common.is_file_empty(tracefile):

        uns_regex = re.compile(rb"^unsat\r?$", re.MULTILINE)
        sat_regex = re.compile(rb"^sat\r?$", re.MULTILINE)

        with io.open(tracefile, 'r', newline=None) as fd_trace:
            with mmap.mmap(fd_trace.fileno(), 0,
                           access=mmap.ACCESS_READ) as output:

                uns_match = re.search(uns_regex, output)
                sat_match = re.search(sat_regex, output)

                assert sum([bool(x) for x in (uns_match, sat_match)]) <= 1

                if sat_match:
                    ret = common.SAT
                elif uns_match:
                    ret = common.UNSAT
                else:
                    ret = common.UNKNOWN

    return ret
Exemple #3
0
def zthree_extract_models(tracefile):
    """Extract and returns all models contained
    in the given tracefile."""

    regex = re.compile(
        (rb"\(define-fun (.*) \(\) (Int|Bool|Real|\(_ BitVec [0-9]+\))"
         rb"\r?\n +(.*)\)"))

    models = []

    if not common.is_file_empty(tracefile):
        with io.open(tracefile, 'r', newline=None) as fd_trace:
            with mmap.mmap(fd_trace.fileno(), 0,
                           access=mmap.ACCESS_READ) as output:
                model = {}
                for match in re.finditer(regex, output):
                    var, stype, value = (x.decode("utf-8")
                                         for x in match.groups())

                    if "BitVec" in stype:
                        stype = "BitVec"

                    if var in model:
                        models.append(model)
                        model = {}

                    model[var] = common.smtlib_to_python_type(stype, value)

                if model:
                    models.append(model)

    return models
Exemple #4
0
def cvc4_extract_models(tracefile):
    """Extract and returns all models contained
    in the given tracefile."""

    models = []

    if not common.is_file_empty(tracefile):
        regex = re.compile((rb"\(define-fun (.*) \(\) "
                            rb"(Int|Bool|Real|\(_ BitVec [0-9]+\))"
                            rb"\r?\n? +(.*)\)"))
        regex_pvt = re.compile(r"^_private_(.*)")

        with io.open(tracefile, 'r', newline=None) as fd_trace:
            with mmap.mmap(fd_trace.fileno(), 0,
                           access=mmap.ACCESS_READ) as output:
                model = {}
                for match in re.finditer(regex, output):
                    var, stype, value = (x.decode("utf-8")
                                         for x in match.groups())

                    if "BitVec" in stype:
                        stype = "BitVec"

                    var = var.replace('_@_', '|')
                    var = var.replace('_@@_', ':')

                    if re.match(regex_pvt, var):
                        var = ".{}".format(var[9:])

                    if var in model:
                        models.append(model)
                        model = {}

                    model[var] = common.smtlib_to_python_type(stype, value)

                if model:
                    models.append(model)

    return models