CBMC
goto_program2code.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Dump Goto-Program as C/C++ Source
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_INSTRUMENT_GOTO_PROGRAM2CODE_H
13 #define CPROVER_GOTO_INSTRUMENT_GOTO_PROGRAM2CODE_H
14 
15 #include <list>
16 #include <unordered_set>
17 
18 #include <analyses/natural_loops.h>
19 
20 class code_blockt;
21 
23 {
24  typedef std::list<irep_idt> id_listt;
25  typedef std::map<
30  typedef std::unordered_map<irep_idt, unsigned> dead_mapt;
31  typedef std::list<std::pair<goto_programt::const_targett, bool> >
33 
34  struct caset
35  {
36  const exprt value; // condition upon which this case is taken
39  goto_programt::const_targett case_last; // last instruction of case
40 
42  const exprt &v,
45  value(v), case_selector(sel), case_start(st),
46  case_last(goto_program.instructions.end())
47  {
48  }
49  };
50  typedef std::list<caset> cases_listt;
51 
52 public:
54  const irep_idt &identifier,
55  const goto_programt &_goto_program,
56  symbol_tablet &_symbol_table,
57  code_blockt &_dest,
58  id_listt &_local_static,
59  id_listt &_type_names,
60  const std::unordered_set<irep_idt> &_typedef_names,
61  std::set<std::string> &_system_headers)
62  : func_name(identifier),
63  goto_program(_goto_program),
64  symbol_table(_symbol_table),
65  ns(_symbol_table),
66  toplevel_block(_dest),
67  local_static(_local_static),
68  type_names(_type_names),
69  typedef_names(_typedef_names),
70  system_headers(_system_headers)
71  {
72  PRECONDITION(local_static.empty());
73 
74  for(id_listt::const_iterator
75  it=type_names.begin();
76  it!=type_names.end();
77  ++it)
78  type_names_set.insert(*it);
79  }
80 
81  void operator()();
82 
83 protected:
87  const namespacet ns;
91  const std::unordered_set<irep_idt> &typedef_names;
92  std::set<std::string> &system_headers;
93  std::unordered_set<exprt, irep_hash> va_list_expr;
94 
97  std::unordered_set<irep_idt> labels_in_use;
100  std::unordered_set<irep_idt> local_static_set;
101  std::unordered_set<irep_idt> type_names_set;
102  std::unordered_set<irep_idt> const_removed;
103 
105 
106  void build_loop_map();
107  void build_dead_map();
108  void scan_for_varargs();
109 
110  void cleanup_code(codet &code, const irep_idt parent_stmt);
111 
113  const exprt &function,
115 
116  void cleanup_code_block(
117  codet &code,
118  const irep_idt parent_stmt);
119 
121  codet &code,
122  const irep_idt parent_stmt);
123 
124  void cleanup_expr(exprt &expr, bool no_typecast);
125 
126  void add_local_types(const typet &type);
127 
128  void remove_const(typet &type);
129 
132  goto_programt::const_targett upper_bound,
133  code_blockt &dest);
134 
136 
139  goto_programt::const_targett upper_bound,
140  code_blockt &dest);
141 
144  goto_programt::const_targett upper_bound,
145  code_blockt &dest);
146 
147  void convert_assign_rec(const code_assignt &assign, code_blockt &dest);
148 
151  goto_programt::const_targett upper_bound,
152  code_blockt &dest);
153 
156  goto_programt::const_targett upper_bound,
157  code_blockt &dest);
158 
162  code_blockt &dest);
163 
166  goto_programt::const_targett upper_bound,
167  code_blockt &dest);
168 
172  code_blockt &dest);
173 
176  goto_programt::const_targett upper_bound,
177  code_blockt &dest);
178 
181  goto_programt::const_targett upper_bound,
182  const exprt &switch_var,
183  cases_listt &cases,
184  goto_programt::const_targett &first_target,
185  goto_programt::const_targett &default_target);
186 
188  goto_programt::const_targett upper_bound,
189  const cfg_dominatorst &dominators,
190  cases_listt &cases,
191  std::set<unsigned> &processed_locations);
192 
193  bool remove_default(
194  const cfg_dominatorst &dominators,
195  const cases_listt &cases,
196  goto_programt::const_targett default_target);
197 
200  goto_programt::const_targett upper_bound,
201  code_blockt &dest);
202 
205  goto_programt::const_targett upper_bound,
206  code_blockt &dest);
207 
210 
213  goto_programt::const_targett upper_bound,
214  code_blockt &dest);
215 
218 
221  goto_programt::const_targett upper_bound,
222  code_blockt &dest);
223 };
224 
225 #endif // CPROVER_GOTO_INSTRUMENT_GOTO_PROGRAM2CODE_H
A goto_instruction_codet representing an assignment in the program.
A codet representing sequential composition of program statements.
Definition: std_code.h:130
exprt::operandst argumentst
Data structure for representing an arbitrary statement in a program.
Definition: std_code_base.h:29
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Base class for all expressions.
Definition: expr.h:56
std::map< goto_programt::const_targett, goto_programt::const_targett, goto_programt::target_less_than > loopt
goto_programt::const_targett convert_goto_switch(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
std::list< irep_idt > id_listt
goto_programt::const_targett convert_assign_varargs(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
std::unordered_set< irep_idt > local_static_set
std::unordered_set< irep_idt > type_names_set
goto_programt::const_targett convert_goto_break_continue(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
void cleanup_code_ifthenelse(codet &code, const irep_idt parent_stmt)
loop_last_stackt loop_last_stack
void convert_labels(goto_programt::const_targett target, code_blockt &dest)
goto_programt::const_targett convert_decl(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
symbol_tablet & symbol_table
goto_program2codet(const irep_idt &identifier, const goto_programt &_goto_program, symbol_tablet &_symbol_table, code_blockt &_dest, id_listt &_local_static, id_listt &_type_names, const std::unordered_set< irep_idt > &_typedef_names, std::set< std::string > &_system_headers)
goto_programt::const_targett convert_do_while(goto_programt::const_targett target, goto_programt::const_targett loop_end, code_blockt &dest)
goto_programt::const_targett convert_goto_goto(goto_programt::const_targett target, code_blockt &dest)
const goto_programt & goto_program
goto_programt::const_targett convert_start_thread(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
goto_programt::const_targett get_cases(goto_programt::const_targett target, goto_programt::const_targett upper_bound, const exprt &switch_var, cases_listt &cases, goto_programt::const_targett &first_target, goto_programt::const_targett &default_target)
void cleanup_code_block(codet &code, const irep_idt parent_stmt)
std::list< caset > cases_listt
void copy_source_location(goto_programt::const_targett, codet &dst)
bool remove_default(const cfg_dominatorst &dominators, const cases_listt &cases, goto_programt::const_targett default_target)
goto_programt::const_targett convert_throw(goto_programt::const_targett target, code_blockt &dest)
std::unordered_set< irep_idt > const_removed
goto_programt::const_targett convert_catch(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
void remove_const(typet &type)
std::list< std::pair< goto_programt::const_targett, bool > > loop_last_stackt
std::unordered_set< exprt, irep_hash > va_list_expr
goto_programt::const_targett convert_goto(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
void add_local_types(const typet &type)
void cleanup_expr(exprt &expr, bool no_typecast)
void cleanup_code(codet &code, const irep_idt parent_stmt)
void cleanup_function_call(const exprt &function, code_function_callt::argumentst &arguments)
goto_programt::const_targett convert_assign(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
goto_programt::const_targett convert_instruction(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
void convert_assign_rec(const code_assignt &assign, code_blockt &dest)
std::unordered_set< irep_idt > labels_in_use
std::unordered_map< irep_idt, unsigned > dead_mapt
goto_programt::const_targett convert_goto_while(goto_programt::const_targett target, goto_programt::const_targett loop_end, code_blockt &dest)
goto_programt::const_targett convert_goto_if(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
std::set< std::string > & system_headers
const namespacet ns
code_blockt & toplevel_block
const std::unordered_set< irep_idt > & typedef_names
natural_loopst loops
const irep_idt & func_name
goto_programt::const_targett convert_set_return_value(goto_programt::const_targett target, goto_programt::const_targett upper_bound, code_blockt &dest)
bool set_block_end_points(goto_programt::const_targett upper_bound, const cfg_dominatorst &dominators, cases_listt &cases, std::set< unsigned > &processed_locations)
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
instructionst::const_iterator const_targett
Definition: goto_program.h:615
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
A concretized version of natural_loops_templatet<const goto_programt, goto_programt::const_targett>
Definition: natural_loops.h:88
The symbol table.
Definition: symbol_table.h:14
The type of an expression, extends irept.
Definition: type.h:29
Compute natural loops in a goto_function.
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
goto_programt::const_targett case_start
caset(const goto_programt &goto_program, const exprt &v, goto_programt::const_targett sel, goto_programt::const_targett st)
goto_programt::const_targett case_selector
goto_programt::const_targett case_last
A total order over targett and const_targett.
Definition: goto_program.h:392