Beispiel #1
0
def main():
    config = parseArgs(sys.argv[1:])
    logging.basicConfig(format='[%(name)s] %(levelname)s: %(message)s',
                        level=config.getLogLevel())
    folderName = os.path.join(os.path.dirname(__file__), 'smtlib')
    onlyfiles = [
        os.path.join(folderName, f) for f in os.listdir(folderName)
        if os.path.isfile(os.path.join(folderName, f)) and f.endswith(".smt2")
    ]
    for filePath in onlyfiles:
        with open(filePath, "r") as f:
            print(filePath)
            reset_env()
            parser = SmtLibParser()
            parser._reset()
            script = parser.get_script(f)
            status = "unsat"
            for f in script.filter_by_command_name("set-info"):
                if f.args[0] == ":status":
                    status = f.args[1]
                    assert (status == "sat" or status == "unsat")
            a = AblectorSolver(get_env(), QF_AUFBV, config)
            script.evaluate(a)
            b = BoolectorSolver(get_env(), QF_AUFBV, generate_models=True)

            if a.last_result:  # Check if assignment actually makes sense...
                assert (status == "sat")
                with open(filePath) as f:
                    newScriptSrc = ""
                    content = f.readlines()
                    for line in content:
                        if line.startswith(";ASSERT "):
                            varName = line[8:].strip()
                            print(varName + ": " +
                                  a.btor.Match_by_symbol(varName).assignment)
                            newScriptSrc += "(assert (= " + varName + " #b" + a.btor.Match_by_symbol(
                                varName).assignment + "))\n"
                        else:
                            newScriptSrc += line
                    parser._reset()
                    scriptWithValues = parser.get_script(
                        io.StringIO(newScriptSrc))
                    scriptWithValues.evaluate(b)
                    assert (b.last_result)
                print("SAT")
            else:
                assert (status == "unsat")
                print("UNSAT")
Beispiel #2
0
    def _recover_declarations(self, data):
        decls = {'consts': {}, 'funs': {}}

        parser = SmtLibParser()
        parser._reset()
        script = SmtLibScript()
        try:
            for cmd in parser.get_command_generator(cStringIO(data)):
                script.add_command(cmd)
        except RuntimeError:
            # Oblivious hack to prevent oop pysmt-related error
            pass
        script.annotations = parser.cache.annotations
        symbol_decls = script.filter_by_command_name('declare-fun')
        self._recover_declared_symbols(symbol_decls, decls)
        symbol_decls = script.filter_by_command_name('declare-const')
        self._recover_declared_symbols(symbol_decls, decls)
        asserts = script.filter_by_command_name('assert')
        self._prune_unused_symbols(asserts, decls)

        return decls