mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add --print-smt flag to output SMTChecker SMTLIB code
This commit is contained in:
@@ -47,8 +47,11 @@ BMC::BMC(
|
||||
CharStreamProvider const& _charStreamProvider
|
||||
):
|
||||
SMTEncoder(_context, _settings, _errorReporter, _unsupportedErrorReporter, _charStreamProvider),
|
||||
m_interface(make_unique<smtutil::SMTPortfolio>(_smtlib2Responses, _smtCallback, _settings.solvers, _settings.timeout))
|
||||
m_interface(make_unique<smtutil::SMTPortfolio>(
|
||||
_smtlib2Responses, _smtCallback, _settings.solvers, _settings.timeout, _settings.printQuery
|
||||
))
|
||||
{
|
||||
solAssert(!_settings.printQuery || _settings.solvers == smtutil::SMTSolverChoice::SMTLIB2(), "Only SMTLib2 solver can be enabled to print queries");
|
||||
#if defined (HAVE_Z3) || defined (HAVE_CVC4)
|
||||
if (m_settings.solvers.cvc4 || m_settings.solvers.z3)
|
||||
if (!_smtlib2Responses.empty())
|
||||
@@ -1192,6 +1195,15 @@ BMC::checkSatisfiableAndGenerateModel(vector<smtutil::Expression> const& _expres
|
||||
vector<string> values;
|
||||
try
|
||||
{
|
||||
if (m_settings.printQuery)
|
||||
{
|
||||
auto portfolio = dynamic_cast<smtutil::SMTPortfolio*>(m_interface.get());
|
||||
string smtlibCode = portfolio->dumpQuery(_expressionsToEvaluate);
|
||||
m_errorReporter.info(
|
||||
6240_error,
|
||||
"BMC: Requested query:\n" + smtlibCode
|
||||
);
|
||||
}
|
||||
tie(result, values) = m_interface->check(_expressionsToEvaluate);
|
||||
}
|
||||
catch (smtutil::SolverError const& _e)
|
||||
|
||||
@@ -72,6 +72,7 @@ CHC::CHC(
|
||||
m_smtlib2Responses(_smtlib2Responses),
|
||||
m_smtCallback(_smtCallback)
|
||||
{
|
||||
solAssert(!_settings.printQuery || _settings.solvers == smtutil::SMTSolverChoice::SMTLIB2(), "Only SMTLib2 solver can be enabled to print queries");
|
||||
}
|
||||
|
||||
void CHC::analyze(SourceUnit const& _source)
|
||||
@@ -1807,6 +1808,16 @@ tuple<CheckResult, smtutil::Expression, CHCSolverInterface::CexGraph> CHC::query
|
||||
CheckResult result;
|
||||
smtutil::Expression invariant(true);
|
||||
CHCSolverInterface::CexGraph cex;
|
||||
if (m_settings.printQuery)
|
||||
{
|
||||
auto smtLibInterface = dynamic_cast<CHCSmtLib2Interface*>(m_interface.get());
|
||||
solAssert(smtLibInterface, "Requested to print queries but CHCSmtLib2Interface not available");
|
||||
string smtLibCode = smtLibInterface->dumpQuery(_query);
|
||||
m_errorReporter.info(
|
||||
2339_error,
|
||||
"CHC: Requested query:\n" + smtLibCode
|
||||
);
|
||||
}
|
||||
tie(result, invariant, cex) = m_interface->query(_query);
|
||||
switch (result)
|
||||
{
|
||||
|
||||
@@ -169,6 +169,7 @@ struct ModelCheckerSettings
|
||||
ModelCheckerEngine engine = ModelCheckerEngine::None();
|
||||
ModelCheckerExtCalls externalCalls = {};
|
||||
ModelCheckerInvariants invariants = ModelCheckerInvariants::Default();
|
||||
bool printQuery = false;
|
||||
bool showProvedSafe = false;
|
||||
bool showUnproved = false;
|
||||
bool showUnsupported = false;
|
||||
@@ -186,6 +187,7 @@ struct ModelCheckerSettings
|
||||
engine == _other.engine &&
|
||||
externalCalls.mode == _other.externalCalls.mode &&
|
||||
invariants == _other.invariants &&
|
||||
printQuery == _other.printQuery &&
|
||||
showProvedSafe == _other.showProvedSafe &&
|
||||
showUnproved == _other.showUnproved &&
|
||||
showUnsupported == _other.showUnsupported &&
|
||||
|
||||
@@ -430,7 +430,7 @@ std::optional<Json::Value> checkSettingsKeys(Json::Value const& _input)
|
||||
|
||||
std::optional<Json::Value> checkModelCheckerSettingsKeys(Json::Value const& _input)
|
||||
{
|
||||
static set<string> keys{"bmcLoopIterations", "contracts", "divModNoSlacks", "engine", "extCalls", "invariants", "showProvedSafe", "showUnproved", "showUnsupported", "solvers", "targets", "timeout"};
|
||||
static set<string> keys{"bmcLoopIterations", "contracts", "divModNoSlacks", "engine", "extCalls", "invariants", "printQuery", "showProvedSafe", "showUnproved", "showUnsupported", "solvers", "targets", "timeout"};
|
||||
return checkKeys(_input, keys, "modelChecker");
|
||||
}
|
||||
|
||||
@@ -1096,6 +1096,18 @@ std::variant<StandardCompiler::InputsAndSettings, Json::Value> StandardCompiler:
|
||||
ret.modelCheckerSettings.solvers = solvers;
|
||||
}
|
||||
|
||||
if (modelCheckerSettings.isMember("printQuery"))
|
||||
{
|
||||
auto const& printQuery = modelCheckerSettings["printQuery"];
|
||||
if (!printQuery.isBool())
|
||||
return formatFatalError(Error::Type::JSONError, "settings.modelChecker.printQuery must be a Boolean value.");
|
||||
|
||||
if (!(ret.modelCheckerSettings.solvers == smtutil::SMTSolverChoice::SMTLIB2()))
|
||||
return formatFatalError(Error::Type::JSONError, "Only SMTLib2 solver can be enabled to print queries");
|
||||
|
||||
ret.modelCheckerSettings.printQuery = printQuery.asBool();
|
||||
}
|
||||
|
||||
if (modelCheckerSettings.isMember("targets"))
|
||||
{
|
||||
auto const& targetsArray = modelCheckerSettings["targets"];
|
||||
|
||||
Reference in New Issue
Block a user