3 #include <boost/spirit/home/x3.hpp>
14 namespace x3 = boost::spirit::x3;
20 std::map<std::string, std::tuple<u64, u16>>
model;
136 out <<
"local : " << std::boolalpha << config.local <<
", ";
137 out <<
"generate_model : " << std::boolalpha << config.
generate_model <<
", ";
156 out << assignment->first <<
" = " << assignment->second;
168 std::stringstream ss;
175 return std::get_if<std::pair<BooleanFunction, BooleanFunction>>(&
constraint);
182 return OK(&std::get<std::pair<BooleanFunction, BooleanFunction>>(
constraint));
184 return ERR(
"constraint is not an assignment");
193 return ERR(
"constraint is not a function");
196 Model::Model(
const std::map<std::string, std::tuple<u64, u16>>& _model) : model(_model)
207 return !(*
this == other);
212 auto s = std::accumulate(model.
model.begin(), model.
model.end(), std::string(), [](
auto accumulator,
auto entry) -> std::string {
213 return accumulator +
", " + std::get<0>(entry) +
":" + std::to_string(std::get<0>(std::get<1>(entry)));
216 out <<
"{" << s <<
"}";
230 static std::mutex mutex;
233 std::lock_guard<std::mutex> lock(mutex);
237 auto iter = s.begin();
238 auto ok = [&]() ->
bool {
253 if (ok && (iter == s.end()))
258 return ERR(
"could not parse SMT-Lib model");
263 std::vector<BooleanFunction::Node> new_nodes;
267 if (node.is_variable())
269 const auto var_name = node.variable;
270 if (
auto it =
model.find(var_name); it !=
model.end())
273 new_nodes.insert(new_nodes.end(), constant.get_nodes().begin(), constant.get_nodes().end());
277 new_nodes.push_back(node);
282 new_nodes.push_back(node);
287 if (build_res.is_error())
289 return ERR_APPEND(build_res.get_error(),
"failed to evaluate Boolean function for the model: failed to build function after replacing nodes.");
292 return OK(build_res.get().simplify_local());
316 return this->
type == _type;
339 if (result.
model.has_value())
341 out << *result.
model;
static Result< BooleanFunction > build(std::vector< Node > &&nodes)
const std::vector< BooleanFunction::Node > & get_nodes() const
static BooleanFunction Const(const BooleanFunction::Value &value)
#define ERR_APPEND(prev_error, message)
ParserContext parser_context
const auto HexValueAction
const auto BOOLECTOR_MODEL_GRAMMAR
const auto SignalAssignmentRule
const auto Z3_MODEL_GRAMMAR
const auto BinaryValueAction
const auto BinaryValueRule
const auto SignalAssigmentAction
std::ostream & operator<<(std::ostream &out, const QueryConfig &config)
std::string enum_to_string(T e)
std::string to_string() const
bool is_assignment() const
std::variant< BooleanFunction, std::pair< BooleanFunction, BooleanFunction > > constraint
A constraint that is either an assignment of two Boolean functions or a single Boolean function,...
Constraint(BooleanFunction &&constraint)
Result< const BooleanFunction * > get_function() const
Result< const std::pair< BooleanFunction, BooleanFunction > * > get_assignment() const
Model(const std::map< std::string, std::tuple< u64, u16 >> &model={})
static Result< Model > parse(const std::string &model_str, const SolverType &solver)
bool operator!=(const Model &other) const
std::map< std::string, std::tuple< u64, u16 > > model
maps variable identifiers to a (1) value and (2) its bit-size.
Result< BooleanFunction > evaluate(const BooleanFunction &bf) const
bool operator==(const Model &other) const
'ParserContext' refers to the data structure that stores parser results.
std::string current_name
stores the current name of a variable assignment
std::string current_value
stores the current value of a variable assignment
std::map< std::string, std::tuple< u64, u16 > > model
stores mapping from variables to its (1) value and (2) bit-size
std::string current_size
stores the current size of a variable assignment
bool generate_model
Controls whether the SMT solver should generate a model in case formula is satisfiable.
QueryConfig & with_remote_solver()
SolverType solver
The SMT solver identifier.
u64 timeout_in_seconds
The timeout after which the SMT solver is killed in seconds.
QueryConfig & without_model_generation()
QueryConfig & with_model_generation()
SolverCall call
The calling format for the SMT solver.
QueryConfig & with_local_solver()
QueryConfig & with_timeout(u64 seconds)
QueryConfig & with_solver(SolverType solver)
QueryConfig & with_call(SolverCall call)
static SolverResult Unknown()
SolverResult()
Default constructor (required for Result<T> initialization)
std::optional< Model > model
The (optional) model that is only available if type == SMT::ResultType::Sat and model generation is e...
static SolverResult Sat(const std::optional< Model > &model={})
bool is(const SolverResultType &type) const
static SolverResult UnSat()
SolverResultType type
Result type of the SMT query.