CBMC
cover_instrument_location.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Coverage Instrumentation
4 
5 Author: Daniel Kroening
6 
7 \*******************************************************************/
8 
11 
12 #include "cover_instrument.h"
13 
14 #include "cover_basic_blocks.h"
15 #include "cover_filter.h"
16 
18  const irep_idt &function_id,
19  goto_programt &goto_program,
21  const cover_blocks_baset &basic_blocks,
22  const assertion_factoryt &make_assertion) const
23 {
24  if(is_non_cover_assertion(i_it))
25  i_it->turn_into_skip();
26 
27  const std::size_t block_nr = basic_blocks.block_of(i_it);
28  const auto representative_instruction = basic_blocks.instruction_of(block_nr);
29  // we only instrument the selected instruction
30  if(representative_instruction && *representative_instruction == i_it)
31  {
32  const std::string b = std::to_string(block_nr + 1); // start with 1
33  const std::string id = id2string(function_id) + "#" + b;
34  source_locationt source_location =
35  basic_blocks.source_location_of(block_nr);
36 
37  // filter goals
38  if(goal_filters(source_location))
39  {
40  const auto &source_lines = basic_blocks.source_lines_of(block_nr);
41  const std::string comment =
42  "block " + b + " (lines " + source_lines.to_string() + ")";
43  source_location.set_basic_block_source_lines(source_lines.to_irep());
44  goto_program.insert_before_swap(i_it);
45  initialize_source_location(source_location, comment, function_id);
46  *i_it = make_assertion(false_exprt(), source_location);
47  i_it++;
48  }
49  }
50 }
virtual const source_linest & source_lines_of(std::size_t block_nr) const =0
virtual const source_locationt & source_location_of(std::size_t block_nr) const =0
virtual std::optional< goto_programt::const_targett > instruction_of(std::size_t block_nr) const =0
virtual std::size_t block_of(goto_programt::const_targett t) const =0
const goal_filterst & goal_filters
bool is_non_cover_assertion(goto_programt::const_targett t) const
void initialize_source_location(source_locationt &source_location, const std::string &comment, const irep_idt &function_id) const
std::function< goto_programt::instructiont(const exprt &, const source_locationt &)> assertion_factoryt
The type of function used to make goto_program assertions.
void instrument(const irep_idt &function_id, goto_programt &, goto_programt::targett &, const cover_blocks_baset &, const assertion_factoryt &) const override
Override this method to implement an instrumenter.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
The Boolean constant false.
Definition: std_expr.h:3077
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
Definition: goto_program.h:643
instructionst::iterator targett
Definition: goto_program.h:614
void set_basic_block_source_lines(irept source_lines)
Basic blocks detection for Coverage Instrumentation.
Filters for the Coverage Instrumentation.
Coverage Instrumentation.
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
static std::string comment(const rw_set_baset::entryt &entry, bool write)
Definition: race_check.cpp:108
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.