2017-07-10 16:13:38 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2017-07-10 16:13:38 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-05-18 15:42:24 +00:00
|
|
|
#include <libsmtutil/SolverInterface.h>
|
2017-07-11 11:26:43 +00:00
|
|
|
|
|
|
|
#include <libsolidity/interface/ReadFile.h>
|
2020-05-19 12:52:31 +00:00
|
|
|
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/Common.h>
|
|
|
|
#include <libsolutil/FixedHash.h>
|
2017-07-10 19:21:11 +00:00
|
|
|
|
2017-07-11 11:26:43 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
2018-12-17 17:26:10 +00:00
|
|
|
#include <cstdio>
|
2017-07-10 16:13:38 +00:00
|
|
|
#include <map>
|
2018-12-17 17:26:10 +00:00
|
|
|
#include <set>
|
2017-07-10 16:13:38 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
namespace solidity::smtutil
|
2017-07-10 16:13:38 +00:00
|
|
|
{
|
|
|
|
|
2017-07-13 16:22:51 +00:00
|
|
|
class SMTLib2Interface: public SolverInterface, public boost::noncopyable
|
2017-07-10 16:13:38 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-09-17 14:06:43 +00:00
|
|
|
explicit SMTLib2Interface(
|
2020-05-11 17:56:29 +00:00
|
|
|
std::map<util::h256, std::string> _queryResponses = {},
|
2020-11-02 20:20:20 +00:00
|
|
|
frontend::ReadCallback::Callback _smtCallback = {},
|
|
|
|
std::optional<unsigned> _queryTimeout = {}
|
2019-09-17 14:06:43 +00:00
|
|
|
);
|
2017-07-10 16:13:38 +00:00
|
|
|
|
2017-07-13 16:22:51 +00:00
|
|
|
void reset() override;
|
2017-07-10 16:13:38 +00:00
|
|
|
|
2017-07-13 16:22:51 +00:00
|
|
|
void push() override;
|
|
|
|
void pop() override;
|
2017-07-10 16:13:38 +00:00
|
|
|
|
2019-09-24 15:35:31 +00:00
|
|
|
void declareVariable(std::string const&, SortPointer const&) override;
|
2017-07-10 16:13:38 +00:00
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
void addAssertion(Expression const& _expr) override;
|
|
|
|
std::pair<CheckResult, std::vector<std::string>> check(std::vector<Expression> const& _expressionsToEvaluate) override;
|
2017-07-10 19:21:11 +00:00
|
|
|
|
2017-10-13 13:19:53 +00:00
|
|
|
std::vector<std::string> unhandledQueries() override { return m_unhandledQueries; }
|
|
|
|
|
2019-09-24 15:35:31 +00:00
|
|
|
// Used by CHCSmtLib2Interface
|
2020-05-19 12:14:46 +00:00
|
|
|
std::string toSExpr(Expression const& _expr);
|
2018-11-21 14:13:50 +00:00
|
|
|
std::string toSmtLibSort(Sort const& _sort);
|
2018-11-21 15:57:02 +00:00
|
|
|
std::string toSmtLibSort(std::vector<SortPointer> const& _sort);
|
2017-07-13 16:22:51 +00:00
|
|
|
|
2019-09-24 15:35:31 +00:00
|
|
|
std::map<std::string, SortPointer> variables() { return m_variables; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void declareFunction(std::string const& _name, SortPointer const& _sort);
|
|
|
|
|
2017-07-10 19:21:11 +00:00
|
|
|
void write(std::string _data);
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
std::string checkSatAndGetValuesCommand(std::vector<Expression> const& _expressionsToEvaluate);
|
2017-07-10 19:21:11 +00:00
|
|
|
std::vector<std::string> parseValues(std::string::const_iterator _start, std::string::const_iterator _end);
|
|
|
|
|
2017-07-13 19:06:29 +00:00
|
|
|
/// Communicates with the solver via the callback. Throws SMTSolverError on error.
|
|
|
|
std::string querySolver(std::string const& _input);
|
|
|
|
|
2017-07-10 19:21:11 +00:00
|
|
|
std::vector<std::string> m_accumulatedOutput;
|
2019-09-24 15:35:31 +00:00
|
|
|
std::map<std::string, SortPointer> m_variables;
|
2020-04-03 13:10:16 +00:00
|
|
|
std::set<std::string> m_userSorts;
|
2017-10-13 13:19:53 +00:00
|
|
|
|
2020-05-11 17:56:29 +00:00
|
|
|
std::map<util::h256, std::string> m_queryResponses;
|
2017-10-13 13:19:53 +00:00
|
|
|
std::vector<std::string> m_unhandledQueries;
|
2019-09-17 14:06:43 +00:00
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
frontend::ReadCallback::Callback m_smtCallback;
|
2017-07-10 16:13:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|