bool ast::is_taut(z3::solver& solver, const z3::expr& expr) { solver.push(); solver.add(!expr); auto res = solver.check(); solver.pop(); return res == z3::unsat; }
void addConstraintsToSolver(z3::solver &solver) { std::vector<z3::expr*>::iterator it; for (it = _inputNodes.begin(); it != _inputNodes.end(); ++it) { (*it)->simplify(); solver.add(*(*it)); } for (it = _outputNodes.begin(); it != _outputNodes.end(); ++it) { (*it)->simplify(); solver.add(*(*it)); } // FIXME : remove because not a condition // for (it = _hiddenNodes.begin(); it != _hiddenNodes.end(); ++it) // solver.add(*(*it)); }
void Z3BaseSolverImpl::configureSolver() { // TODO: Turn this into some sort of optional logging... errs() << "[Z3] Initializing..." << '\n'; Z3_param_descrs solver_params = Z3_solver_get_param_descrs(context_, solver_); Z3_param_descrs_inc_ref(context_, solver_params); errs() << "[Z3] Available parameters:" << '\n'; errs() << "[Z3] " << Z3_param_descrs_to_string(context_, solver_params) << '\n'; z3::params params(context_); params.set("array.extensional", false); Z3_params_validate(context_, params, solver_params); solver_.set(params); Z3_param_descrs_dec_ref(context_, solver_params); }
void Z3BaseSolverImpl::extractModel(const std::vector<const Array*> &objects, std::vector<std::vector<unsigned char> > &values) { z3::model model = solver_.get_model(); #if 0 // TODO: Turn into proper debug logging std::stringstream model_ss; model_ss << solver_ << '\n'; model_ss << model; model_ss.flush(); errs() << "[Z3][Debug] Model: " << '\n' << model_ss.str() << '\n'; #endif values.reserve(objects.size()); for (std::vector<const Array*>::const_iterator it = objects.begin(), ie = objects.end(); it != ie; ++it) { const Array *array = *it; std::vector<unsigned char> data; #if 0 // TODO: Turn into proper debug logging errs() << "[Z3][Debug] Array name: " << array->name << '\n'; #endif data.reserve(array->size); for (unsigned offset = 0; offset < array->size; ++offset) { z3::expr value_ast = model.eval( builder_->getInitialRead(array, offset), true); unsigned value_num; #if 0 // TODO: Turn into proper debug logging std::stringstream ss; ss << builder_->getInitialRead(array, offset) << " // " << value_ast; ss.flush(); errs() << "[Z3][Debug] Initial read eval: " << ss.str() << '\n'; #endif Z3_bool conv_result = Z3_get_numeral_uint(context_, value_ast, &value_num); assert(conv_result == Z3_TRUE && "Could not convert value"); assert(value_num < (1 << 8*sizeof(unsigned char)) && "Invalid model value"); data.push_back((unsigned char)value_num); } values.push_back(data); } }
Z3AssertArrayBuilder::Z3AssertArrayBuilder(z3::solver &solver, Z3ArrayBuilderCache *cache) : Z3ArrayBuilder(solver.ctx(), cache), solver_(solver) { }