|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Property Decider for Goto-Symex |
| 4 | +
|
| 5 | +Author: Daniel Kroening, Peter Schrammel |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +/// \file |
| 10 | +/// Property Decider for Goto-Symex |
| 11 | + |
| 12 | +#include "goto_symex_property_decider.h" |
| 13 | + |
| 14 | +goto_symex_property_decidert::goto_symex_property_decidert( |
| 15 | + const optionst &options, |
| 16 | + ui_message_handlert &ui_message_handler, |
| 17 | + symex_target_equationt &equation, |
| 18 | + const namespacet &ns) |
| 19 | + : options(options), |
| 20 | + ui_message_handler(ui_message_handler), |
| 21 | + equation(equation) |
| 22 | +{ |
| 23 | + solver_factoryt solvers( |
| 24 | + options, |
| 25 | + ns, |
| 26 | + ui_message_handler, |
| 27 | + ui_message_handler.get_ui() == ui_message_handlert::uit::XML_UI); |
| 28 | + solver = solvers.get_solver(); |
| 29 | + solver->prop_conv().set_message_handler(ui_message_handler); |
| 30 | +} |
| 31 | + |
| 32 | +exprt goto_symex_property_decidert::goalt::as_expr() const |
| 33 | +{ |
| 34 | + std::vector<exprt> tmp; |
| 35 | + tmp.reserve(instances.size()); |
| 36 | + for(const auto &inst : instances) |
| 37 | + tmp.push_back(literal_exprt(inst->cond_literal)); |
| 38 | + return conjunction(tmp); |
| 39 | +} |
| 40 | + |
| 41 | +void goto_symex_property_decidert:: |
| 42 | +update_properties_goals_from_symex_target_equation(propertiest &properties) |
| 43 | +{ |
| 44 | + for(symex_target_equationt::SSA_stepst::iterator it = |
| 45 | + equation.SSA_steps.begin(); |
| 46 | + it != equation.SSA_steps.end(); |
| 47 | + ++it) |
| 48 | + { |
| 49 | + if(it->is_assert()) |
| 50 | + { |
| 51 | + irep_idt property_id = it->get_property_id(); |
| 52 | + CHECK_RETURN(!property_id.empty()); |
| 53 | + |
| 54 | + // consider goal instance if it is in the given properties |
| 55 | + auto property_pair_it = properties.find(property_id); |
| 56 | + if( |
| 57 | + property_pair_it != properties.end() && |
| 58 | + is_property_to_check(property_pair_it->second.status)) |
| 59 | + { |
| 60 | + // it's going to be checked, but we don't know the status yet |
| 61 | + property_pair_it->second.status |= property_statust::UNKNOWN; |
| 62 | + goal_map[property_id].instances.push_back(it); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +void goto_symex_property_decidert::convert_goals() |
| 69 | +{ |
| 70 | + for(auto &goal_pair : goal_map) |
| 71 | + { |
| 72 | + // Our goal is to falsify a property, i.e., we will |
| 73 | + // add the negation of the property as goal. |
| 74 | + goal_pair.second.condition = |
| 75 | + !solver->prop_conv().convert(goal_pair.second.as_expr()); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +void goto_symex_property_decidert::freeze_goal_variables() |
| 80 | +{ |
| 81 | + for(const auto &goal_pair : goal_map) |
| 82 | + { |
| 83 | + if(!goal_pair.second.condition.is_constant()) |
| 84 | + solver->prop_conv().set_frozen(goal_pair.second.condition); |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +void goto_symex_property_decidert::add_constraint_from_goals( |
| 89 | + std::function<bool(const irep_idt &)> select_property) |
| 90 | +{ |
| 91 | + exprt::operandst disjuncts; |
| 92 | + |
| 93 | + for(const auto &goal_pair : goal_map) |
| 94 | + { |
| 95 | + if( |
| 96 | + select_property(goal_pair.first) && |
| 97 | + !goal_pair.second.condition.is_false()) |
| 98 | + { |
| 99 | + disjuncts.push_back(literal_exprt(goal_pair.second.condition)); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + // this is 'false' if there are no disjuncts |
| 104 | + solver->prop_conv().set_to_true(disjunction(disjuncts)); |
| 105 | +} |
| 106 | + |
| 107 | +decision_proceduret::resultt goto_symex_property_decidert::solve() |
| 108 | +{ |
| 109 | + return solver->prop_conv().dec_solve(); |
| 110 | +} |
| 111 | + |
| 112 | +prop_convt &goto_symex_property_decidert::get_solver() const |
| 113 | +{ |
| 114 | + return solver->prop_conv(); |
| 115 | +} |
| 116 | + |
| 117 | +symex_target_equationt &goto_symex_property_decidert::get_equation() const |
| 118 | +{ |
| 119 | + return equation; |
| 120 | +} |
| 121 | + |
| 122 | +void goto_symex_property_decidert::update_properties_status_from_goals( |
| 123 | + propertiest &properties, |
| 124 | + std::unordered_set<irep_idt> &updated_properties, |
| 125 | + decision_proceduret::resultt dec_result, |
| 126 | + bool set_pass) const |
| 127 | +{ |
| 128 | + switch(dec_result) |
| 129 | + { |
| 130 | + case decision_proceduret::resultt::D_SATISFIABLE: |
| 131 | + for(auto &goal_pair : goal_map) |
| 132 | + { |
| 133 | + if(solver->prop_conv().l_get(goal_pair.second.condition).is_true()) |
| 134 | + { |
| 135 | + properties.at(goal_pair.first).status |= property_statust::FAIL; |
| 136 | + updated_properties.insert(goal_pair.first); |
| 137 | + } |
| 138 | + } |
| 139 | + break; |
| 140 | + case decision_proceduret::resultt::D_UNSATISFIABLE: |
| 141 | + if(!set_pass) |
| 142 | + break; |
| 143 | + |
| 144 | + for(auto &property_pair : properties) |
| 145 | + { |
| 146 | + if(property_pair.second.status == property_statust::UNKNOWN) |
| 147 | + { |
| 148 | + property_pair.second.status |= property_statust::PASS; |
| 149 | + updated_properties.insert(property_pair.first); |
| 150 | + } |
| 151 | + } |
| 152 | + break; |
| 153 | + case decision_proceduret::resultt::D_ERROR: |
| 154 | + for(auto &property_pair : properties) |
| 155 | + { |
| 156 | + if(property_pair.second.status == property_statust::UNKNOWN) |
| 157 | + { |
| 158 | + property_pair.second.status |= property_statust::ERROR; |
| 159 | + updated_properties.insert(property_pair.first); |
| 160 | + } |
| 161 | + } |
| 162 | + break; |
| 163 | + } |
| 164 | +} |
0 commit comments