36 auto p =
reinterpret_cast<SolverParams*
>(state);
39 auto delta = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - p->start).count();
42 if (p->timeout && delta > p->timeout) {
51 auto delta_s = delta / 1000;
54 if (p->memory_limit && delta > 100 && delta_s > p->last_mem_check) {
55 p->last_mem_check = delta_s;
58 size_t memory_usage = 0;
59 std::ifstream str(
"/proc/self/status");
62 static std::regex vmsize(
"VmRSS:\\s*([0-9]+)\\s*kB");
63 while (std::getline(str, line)) {
65 if (std::regex_match(line, match, vmsize)) {
66 memory_usage = strtoul(match.str(1).c_str(), NULL, 10) / 1024;
74 if (memory_usage > p->memory_limit) {
98 if (node->isLogical() ==
false)
102 auto bzlaOptions = bitwuzla_options_new();
103 bitwuzla_set_option(bzlaOptions, BITWUZLA_OPT_PRODUCE_MODELS, 1);
104 auto bzlaTermMgr = bitwuzla_term_manager_new();
105 auto bzla = bitwuzla_new(bzlaTermMgr, bzlaOptions);
109 bitwuzla_assert(bzla, bzlaAst.convert(node, bzla));
111 auto tmout = timeout != 0 ? timeout : this->timeout;
114 SolverParams p(tmout, this->memoryLimit);
115 if (tmout || this->memoryLimit) {
116 bitwuzla_set_termination_callback(bzla, this->
terminateCallback,
reinterpret_cast<void*
>(&p));
120 auto start = std::chrono::system_clock::now();
123 auto res = bitwuzla_check_sat(bzla);
134 case BITWUZLA_UNKNOWN:
140 std::vector<std::unordered_map<triton::usize, SolverModel>> ret;
141 while(res == BITWUZLA_SAT && limit >= 1) {
142 std::vector<BitwuzlaTerm> solution;
143 solution.reserve(bzlaAst.getVariables().size());
146 std::unordered_map<triton::usize, SolverModel> model;
147 for (
const auto& it : bzlaAst.getVariables()) {
148 const char* svalue = bitwuzla_term_value_get_str_fmt(bitwuzla_get_value(bzla, it.first), 2);
149 auto value = this->fromBvalueToUint512(svalue);
151 model[m.getId()] = m;
154 const auto& symvar_sort = bzlaAst.getBitvectorSorts().at(it.second->getSize());
155 auto cur_val = bitwuzla_mk_bv_value(bzlaTermMgr, symvar_sort, svalue, 2);
156 auto n = bitwuzla_mk_term2(bzlaTermMgr, BITWUZLA_KIND_EQUAL, it.first, cur_val);
157 solution.push_back(bitwuzla_mk_term1(bzlaTermMgr, BITWUZLA_KIND_NOT, n));
166 ret.push_back(model);
170 if (solution.size() > 1) {
171 bitwuzla_assert(bzla, bitwuzla_mk_term(bzlaTermMgr, BITWUZLA_KIND_OR, solution.size(), solution.data()));
174 bitwuzla_assert(bzla, solution.front());
178 res = bitwuzla_check_sat(bzla);
183 auto end = std::chrono::system_clock::now();
186 *solvingTime = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
188 bitwuzla_delete(bzla);
189 bitwuzla_term_manager_delete(bzlaTermMgr);
190 bitwuzla_options_delete(bzlaOptions);
215 if (node ==
nullptr) {
219 auto bzlaOptions = bitwuzla_options_new();
220 bitwuzla_set_option(bzlaOptions, BITWUZLA_OPT_PRODUCE_MODELS, 1);
221 auto bzlaTermMgr = bitwuzla_term_manager_new();
222 auto bzla = bitwuzla_new(bzlaTermMgr, bzlaOptions);
225 if (bitwuzla_check_sat(bzla) != BITWUZLA_SAT) {
226 bitwuzla_delete(bzla);
227 bitwuzla_options_delete(bzlaOptions);
233 auto term_value = bitwuzla_get_value(bzla, bzlaAst.convert(node, bzla));
236 if (bitwuzla_term_is_bool(term_value)) {
237 res = bitwuzla_term_value_get_bool(term_value);
239 res =
triton::uint512{bitwuzla_term_value_get_str_fmt(term_value, 10)};
242 bitwuzla_delete(bzla);
243 bitwuzla_term_manager_delete(bzlaTermMgr);
244 bitwuzla_options_delete(bzlaOptions);