mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow running Eldarica from the command line
This commit is contained in:
@@ -40,12 +40,14 @@ using namespace solidity::smtutil;
|
||||
CHCSmtLib2Interface::CHCSmtLib2Interface(
|
||||
map<h256, string> const& _queryResponses,
|
||||
ReadCallback::Callback _smtCallback,
|
||||
SMTSolverChoice _enabledSolvers,
|
||||
optional<unsigned> _queryTimeout
|
||||
):
|
||||
CHCSolverInterface(_queryTimeout),
|
||||
m_smtlib2(make_unique<SMTLib2Interface>(_queryResponses, _smtCallback, m_queryTimeout)),
|
||||
m_queryResponses(std::move(_queryResponses)),
|
||||
m_smtCallback(_smtCallback)
|
||||
m_smtCallback(_smtCallback),
|
||||
m_enabledSolvers(_enabledSolvers)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
@@ -203,12 +205,15 @@ string CHCSmtLib2Interface::querySolver(string const& _input)
|
||||
util::h256 inputHash = util::keccak256(_input);
|
||||
if (m_queryResponses.count(inputHash))
|
||||
return m_queryResponses.at(inputHash);
|
||||
|
||||
smtAssert(m_enabledSolvers.smtlib2 || m_enabledSolvers.eld);
|
||||
if (m_smtCallback)
|
||||
{
|
||||
auto result = m_smtCallback(ReadCallback::kindString(ReadCallback::Kind::SMTQuery), _input);
|
||||
if (result.success)
|
||||
return result.responseOrErrorMessage;
|
||||
}
|
||||
|
||||
m_unhandledQueries.push_back(_input);
|
||||
return "unknown\n";
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
explicit CHCSmtLib2Interface(
|
||||
std::map<util::h256, std::string> const& _queryResponses = {},
|
||||
frontend::ReadCallback::Callback _smtCallback = {},
|
||||
SMTSolverChoice _enabledSolvers = SMTSolverChoice::All(),
|
||||
std::optional<unsigned> _queryTimeout = {}
|
||||
);
|
||||
|
||||
@@ -78,6 +79,7 @@ private:
|
||||
std::vector<std::string> m_unhandledQueries;
|
||||
|
||||
frontend::ReadCallback::Callback m_smtCallback;
|
||||
SMTSolverChoice m_enabledSolvers;
|
||||
|
||||
std::map<Sort const*, std::string> m_sortNames;
|
||||
};
|
||||
|
||||
@@ -42,28 +42,23 @@ namespace solidity::smtutil
|
||||
struct SMTSolverChoice
|
||||
{
|
||||
bool cvc4 = false;
|
||||
bool eld = false;
|
||||
bool smtlib2 = false;
|
||||
bool z3 = false;
|
||||
|
||||
static constexpr SMTSolverChoice All() noexcept { return {true, true, true}; }
|
||||
static constexpr SMTSolverChoice CVC4() noexcept { return {true, false, false}; }
|
||||
static constexpr SMTSolverChoice SMTLIB2() noexcept { return {false, true, false}; }
|
||||
static constexpr SMTSolverChoice Z3() noexcept { return {false, false, true}; }
|
||||
static constexpr SMTSolverChoice None() noexcept { return {false, false, false}; }
|
||||
static constexpr SMTSolverChoice All() noexcept { return {true, true, true, true}; }
|
||||
static constexpr SMTSolverChoice CVC4() noexcept { return {true, false, false, false}; }
|
||||
static constexpr SMTSolverChoice ELD() noexcept { return {false, true, false, false}; }
|
||||
static constexpr SMTSolverChoice SMTLIB2() noexcept { return {false, false, true, false}; }
|
||||
static constexpr SMTSolverChoice Z3() noexcept { return {false, false, false, true}; }
|
||||
static constexpr SMTSolverChoice None() noexcept { return {false, false, false, false}; }
|
||||
|
||||
static std::optional<SMTSolverChoice> fromString(std::string const& _solvers)
|
||||
{
|
||||
SMTSolverChoice solvers;
|
||||
if (_solvers == "all")
|
||||
{
|
||||
smtAssert(solvers.setSolver("cvc4"), "");
|
||||
smtAssert(solvers.setSolver("smtlib2"), "");
|
||||
smtAssert(solvers.setSolver("z3"), "");
|
||||
}
|
||||
else
|
||||
for (auto&& s: _solvers | ranges::views::split(',') | ranges::to<std::vector<std::string>>())
|
||||
if (!solvers.setSolver(s))
|
||||
return {};
|
||||
for (auto&& s: _solvers | ranges::views::split(',') | ranges::to<std::vector<std::string>>())
|
||||
if (!solvers.setSolver(s))
|
||||
return {};
|
||||
|
||||
return solvers;
|
||||
}
|
||||
@@ -71,6 +66,7 @@ struct SMTSolverChoice
|
||||
SMTSolverChoice& operator&=(SMTSolverChoice const& _other)
|
||||
{
|
||||
cvc4 &= _other.cvc4;
|
||||
eld &= _other.eld;
|
||||
smtlib2 &= _other.smtlib2;
|
||||
z3 &= _other.z3;
|
||||
return *this;
|
||||
@@ -87,17 +83,20 @@ struct SMTSolverChoice
|
||||
bool operator==(SMTSolverChoice const& _other) const noexcept
|
||||
{
|
||||
return cvc4 == _other.cvc4 &&
|
||||
eld == _other.eld &&
|
||||
smtlib2 == _other.smtlib2 &&
|
||||
z3 == _other.z3;
|
||||
}
|
||||
|
||||
bool setSolver(std::string const& _solver)
|
||||
{
|
||||
static std::set<std::string> const solvers{"cvc4", "smtlib2", "z3"};
|
||||
static std::set<std::string> const solvers{"cvc4", "eld", "smtlib2", "z3"};
|
||||
if (!solvers.count(_solver))
|
||||
return false;
|
||||
if (_solver == "cvc4")
|
||||
cvc4 = true;
|
||||
if (_solver == "eld")
|
||||
eld = true;
|
||||
else if (_solver == "smtlib2")
|
||||
smtlib2 = true;
|
||||
else if (_solver == "z3")
|
||||
@@ -106,8 +105,8 @@ struct SMTSolverChoice
|
||||
}
|
||||
|
||||
bool none() const noexcept { return !some(); }
|
||||
bool some() const noexcept { return cvc4 || smtlib2 || z3; }
|
||||
bool all() const noexcept { return cvc4 && smtlib2 && z3; }
|
||||
bool some() const noexcept { return cvc4 || eld || smtlib2 || z3; }
|
||||
bool all() const noexcept { return cvc4 && eld && smtlib2 && z3; }
|
||||
};
|
||||
|
||||
enum class CheckResult
|
||||
|
||||
Reference in New Issue
Block a user