goto_programt::targett cegis_assign(const symbol_tablet &st, goto_functionst &gf, const goto_programt::targett &insert_after_pos, const exprt &lhs, const exprt &rhs, const source_locationt &loc) { goto_programt &body=get_entry_body(gf); return cegis_assign(st, body, insert_after_pos, lhs, rhs, loc); }
goto_programt::targett declare_cegis_meta_variable(symbol_tablet &st, goto_functionst &gf, const goto_programt::targett &pos, const std::string &base_name, const typet &type) { const std::string symbol_name(get_cegis_meta_name(base_name)); const symbolt &symbol=create_cegis_symbol(st, symbol_name, type); return declare_local_var(get_entry_body(gf), pos, symbol); }
void insert_jsa_constraint(jsa_programt &prog, const bool use_assume) { const goto_program_instruction_typet instr_type(use_assume ? ASSUME : ASSERT); goto_programt &body=get_entry_body(prog.gf); imply_true(prog, body, prog.inductive_step, instr_type); imply_true(prog, body, prog.property_entailment, instr_type); add_guard_goto(prog, body); }
void link_result_var(const symbol_tablet &st, goto_functionst &gf, const size_t num_user_vars, const size_t max_solution_size, goto_programt::targett pos) { goto_programt &body=get_entry_body(gf); const size_t num_temps=max_solution_size - 1; pos=link_temp_vars(st, body, --pos, num_temps, num_user_vars); ++pos; set_rops_reference(st, body, pos, get_affected_variable(*pos), num_temps); }
void remove_loop(jsa_programt &p) { goto_programt::instructionst &b=get_entry_body(p.gf).instructions; auto pred=std::mem_fn(&goto_programt::instructiont::is_backwards_goto); const goto_programt::targett bw_goto=std::find_if(b.begin(), b.end(), pred); assert(b.end() != bw_goto); assert(b.end() == std::find_if(std::next(bw_goto), b.end(), pred)); goto_programt::targett body_begin; goto_programt::targett body_end; invariant_remove_loop(p.st, b, bw_goto, p.guard, p.body.first, p.body.second); }
void assume_renondet_inputs_valid(jsa_programt &prog) { if (prog.counterexample_locations.empty()) return; const symbol_tablet &st=prog.st; goto_programt &body=get_entry_body(prog.gf); for (const goto_programt::targett &pos : prog.inductive_step_renondets) { const irep_idt &id=get_affected_variable(*pos); const symbol_exprt lhs(st.lookup(id).symbol_expr()); const typet &type=lhs.type(); if (is_jsa_heap(type)) assume_valid_heap(st, body, pos, address_of_exprt(lhs)); } }
void propagate_controller_sizes(const symbol_tablet &st, goto_functionst &gf) { const symbolt &symbol=st.lookup(CEGIS_CONTROL_SOLUTION_VAR_NAME); const struct_exprt &controller_value=to_struct_expr(symbol.value); const namespacet ns(st); const exprt &a_size=get_a_size(ns, controller_value); const exprt &b_size=get_b_size(ns, controller_value); replace_sizes_visitort visitor(a_size, b_size); goto_programt &body=get_entry_body(gf); for (goto_programt::instructiont &instr : body.instructions) { instr.code.visit(visitor); instr.guard.visit(visitor); } }
void add_jsa_constraint_meta_variables(jsa_programt &p) { symbol_tablet &st=p.st; goto_programt &body=get_entry_body(p.gf); const typet type(c_bool_type()); declare_lambda(p, body); p.base_case=insert_before_preserve_labels(body, p.body.first); declare_jsa_meta_variable(st, p.base_case, JSA_BASE_CASE, type); p.inductive_assumption=body.insert_after(p.base_case); declare_jsa_meta_variable(st, p.inductive_assumption, JSA_IND_ASSUME, type); p.inductive_step=insert_before_preserve_labels(body, p.body.second); declare_jsa_meta_variable(st, p.inductive_step, JSA_IND_STEP, type); p.property_entailment=insert_before_preserve_labels(body, p.body.second); declare_jsa_meta_variable(st, p.property_entailment, JSA_PROP_ENTAIL, type); p.body.second=p.property_entailment; }
size_t default_cegis_constant_strategy(symbol_tablet &st, goto_functionst &gf) { const std::vector<constant_exprt> literals(collect_integer_literals(st, gf)); size_t max_word_width=0u; size_t const_index=0u; goto_programt::targett pos=get_entry_body(gf).instructions.begin(); // XXX: Literals strategy, benchmark performance for (const constant_exprt &expr : literals) { // XXX: Debug //std::cout << "<id>" << const_index << "</id>" << std::endl; //std::cout << "<value>" << expr.to_string() << "</value>" << std::endl; // XXX: Debug const std::string base_name(get_name(const_index++)); pos=declare_cegis_meta_variable(st, gf, pos, base_name, expr.type()); pos=assign_cegis_meta_variable(st, gf, pos, base_name, expr); max_word_width=std::max(max_word_width, get_min_word_width(expr)); } return max_word_width; }
void execute_inv_prog(const symbol_tablet &st, goto_functionst &gf, const size_t max_solution_size, const goto_programt::targett &decl, const std::string &prog_base_name) { goto_programt &body=get_entry_body(gf); goto_programt::targett pos=decl; goto_programt::targett execution=body.insert_after(++pos); execution->type=goto_program_instruction_typet::FUNCTION_CALL; execution->source_location=default_cegis_source_location(); code_function_callt call; call.function()=st.lookup(DANGER_EXECUTE).symbol_expr(); const std::string prog_name(get_cegis_meta_name(prog_base_name)); const symbol_exprt prog_symbol(st.lookup(prog_name).symbol_expr()); const typet size_type(unsigned_int_type()); const constant_exprt index(from_integer(0u, size_type)); const index_exprt first_elem(prog_symbol, index); call.arguments().push_back(address_of_exprt(first_elem)); const constant_exprt size(from_integer(max_solution_size, size_type)); call.arguments().push_back(size); execution->code=call; }
void safety_fitness_configt::set_test_case(const counterexamplet &ce) { if (quantifiers.empty()) return; goto_functionst &gf=program.gf; // TODO: Implement for multiple loops (change constraint, instrumentation) const counterexamplet::assignmentst &ass=ce.x.back(); typedef counterexamplet::assignmentst counterexamplet; for (goto_programt::targett quantifier : quantifiers) { const irep_idt &var=get_affected_variable(*quantifier); const counterexamplet::const_iterator it=ass.find(var); if (ass.end() == it) continue; symbol_tablet &st=program.st; if (program_contains_ce) { goto_programt::targett assignment=quantifier; erase_target(get_entry_body(gf).instructions, ++assignment); } invariant_assign_user_variable(st, gf, quantifier, var, it->second); } gf.update(); program_contains_ce=true; }