cprover
branch.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Branch Instrumentation
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "branch.h"
13 
14 #include <util/cprover_prefix.h>
15 #include <util/prefix.h>
16 
17 #include "function.h"
18 
19 void branch(
20  symbol_tablet &symbol_table,
21  goto_functionst &goto_functions,
22  const irep_idt &id)
23 {
24  Forall_goto_functions(f_it, goto_functions)
25  {
26  // don't instrument our internal functions
27  if(has_prefix(id2string(f_it->first), CPROVER_PREFIX))
28  continue;
29 
30  // don't instrument the function to be called,
31  // or otherwise this will be recursive
32  if(f_it->first==id)
33  continue;
34 
35  // patch in a call to `id' at the branch points
36  goto_programt &body=f_it->second.body;
37 
39  {
40  // if C goto T is transformed into:
41  //
42  // if !C goto T' i_it
43  // id("taken"); t1
44  // goto T t2
45  // T': id("not-taken"); t3
46  // ...
47 
48  if(i_it->is_goto() &&
49  !i_it->guard.is_constant())
50  {
51  // negate condition
52  i_it->guard.make_not();
53 
55  t1->make_function_call(
56  function_to_call(symbol_table, id, "taken"));
57  t1->function=f_it->first;
58 
60  t2->make_goto();
61  t2->targets=i_it->targets;
62 
64  t3->make_function_call(
65  function_to_call(symbol_table, id, "not-taken"));
66  t3->function=f_it->first;
67  i_it->targets.clear();
68  i_it->targets.push_back(t3);
69  }
70  }
71  }
72 }
Function Entering and Exiting.
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
#define CPROVER_PREFIX
Branch Instrumentation.
The symbol table.
Definition: symbol_table.h:52
targett insert_after(const_targett target)
Insertion after the given target.
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
A specialization of goto_program_templatet over goto programs in which instructions have codet type...
Definition: goto_program.h:24
void branch(symbol_tablet &symbol_table, goto_functionst &goto_functions, const irep_idt &id)
Definition: branch.cpp:19
#define Forall_goto_functions(it, functions)
#define Forall_goto_program_instructions(it, program)
Definition: goto_program.h:73
code_function_callt function_to_call(symbol_tablet &symbol_table, const irep_idt &id, const irep_idt &argument)
Definition: function.cpp:22