-
Notifications
You must be signed in to change notification settings - Fork 6k
/
Copy pathSMTLib2Interface.h
119 lines (84 loc) · 3.26 KB
/
SMTLib2Interface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
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/>.
*/
// SPDX-License-Identifier: GPL-3.0
#pragma once
#include <libsmtutil/BMCSolverInterface.h>
#include <libsmtutil/SMTLib2Context.h>
#include <libsolidity/interface/ReadFile.h>
#include <libsolutil/Common.h>
#include <libsolutil/FixedHash.h>
#include <cstdio>
#include <map>
#include <set>
#include <string>
#include <vector>
namespace solidity::smtutil
{
class SMTLib2Commands
{
public:
void push();
void pop();
void clear();
void assertion(std::string _expr);
void setOption(std::string _name, std::string _value);
void setLogic(std::string _logic);
void declareVariable(std::string _name, std::string _sort);
void declareFunction(std::string const& _name, std::vector<std::string> const& _domain, std::string const& _codomain);
void declareTuple(
std::string const& _name,
std::vector<std::string> const& _memberNames,
std::vector<std::string> const& _memberSorts
);
[[nodiscard]] std::string toString() const;
private:
std::vector<std::string> m_commands;
std::vector<std::size_t> m_frameLimits;
};
class SMTLib2Interface: public BMCSolverInterface
{
public:
/// Noncopyable.
SMTLib2Interface(SMTLib2Interface const&) = delete;
SMTLib2Interface& operator=(SMTLib2Interface const&) = delete;
explicit SMTLib2Interface(
std::map<util::h256, std::string> _queryResponses = {},
frontend::ReadCallback::Callback _smtCallback = {},
std::optional<unsigned> _queryTimeout = {}
);
void reset() override;
void push() override;
void pop() override;
void declareVariable(std::string const&, SortPointer const&) override;
void addAssertion(Expression const& _expr) override;
std::pair<CheckResult, std::vector<std::string>> check(std::vector<Expression> const& _expressionsToEvaluate) override;
std::vector<std::string> unhandledQueries() override { return m_unhandledQueries; }
// Used by CHCSmtLib2Interface
std::string toSExpr(Expression const& _expr);
std::string toSmtLibSort(SortPointer _sort);
std::vector<std::string> toSmtLibSort(std::vector<SortPointer> const& _sort);
std::string dumpQuery(std::vector<Expression> const& _expressionsToEvaluate);
protected:
virtual void setupSmtCallback() {}
void declareFunction(std::string const& _name, SortPointer const& _sort);
std::string checkSatAndGetValuesCommand(std::vector<Expression> const& _expressionsToEvaluate);
/// Communicates with the solver via the callback. Throws SMTSolverError on error.
virtual std::string querySolver(std::string const& _input);
SMTLib2Commands m_commands;
SMTLib2Context m_context;
std::map<util::h256, std::string> m_queryResponses;
std::vector<std::string> m_unhandledQueries;
frontend::ReadCallback::Callback m_smtCallback;
};
}