cprover
rebuild_goto_start_function.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2  Module: Goto Programs
3  Author: Thomas Kiley, thomas@diffblue.com
4 \*******************************************************************/
5 
8 
10 
11 #include <util/symbol.h>
12 #include <util/symbol_table.h>
13 #include <util/prefix.h>
14 #include <util/cmdline.h>
15 
16 #include <langapi/mode.h>
17 #include <langapi/language.h>
18 
19 #include <memory>
20 
28 template <typename maybe_lazy_goto_modelt>
31  const optionst &options,
32  maybe_lazy_goto_modelt &goto_model,
33  message_handlert &message_handler)
34  : messaget(message_handler), options(options), goto_model(goto_model)
35 {
36 }
37 
44 template<typename maybe_lazy_goto_modelt>
46 {
47  const irep_idt &mode=get_entry_point_mode();
48 
49  // Get the relevant languaget to generate the new entry point with
50  std::unique_ptr<languaget> language=get_language_from_mode(mode);
51  INVARIANT(language, "No language found for mode: "+id2string(mode));
52  language->set_message_handler(get_message_handler());
53  language->set_language_options(options);
54 
55  // To create a new entry point we must first remove the old one
56  remove_existing_entry_point();
57 
58  bool return_code=
59  language->generate_support_functions(goto_model.symbol_table);
60 
61  // Remove the function from the goto functions so it is copied back in
62  // from the symbol table during goto_convert
63  if(!return_code)
64  goto_model.unload(goto_functionst::entry_point());
65 
66  return return_code;
67 }
68 
72 template<typename maybe_lazy_goto_modelt>
75 {
76  const symbolt &current_entry_point=
77  *goto_model.symbol_table.lookup(goto_functionst::entry_point());
78  return current_entry_point.mode;
79 }
80 
83 template<typename maybe_lazy_goto_modelt>
86 {
87  // Remove the function itself
88  goto_model.symbol_table.remove(goto_functionst::entry_point());
89 
90  // And any symbols created in the scope of the entry point
91  std::vector<irep_idt> entry_point_symbols;
92  for(const auto &symbol_entry : goto_model.symbol_table.symbols)
93  {
94  const bool is_entry_point_symbol=
95  has_prefix(
96  id2string(symbol_entry.first),
98 
99  if(is_entry_point_symbol)
100  entry_point_symbols.push_back(symbol_entry.first);
101  }
102 
103  for(const irep_idt &entry_point_symbol : entry_point_symbols)
104  {
105  goto_model.symbol_table.remove(entry_point_symbol);
106  }
107 }
108 
Goto Programs Author: Thomas Kiley, thomas@diffblue.com.
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
Symbol table entry.
irep_idt mode
Language mode.
Definition: symbol.h:49
std::unique_ptr< languaget > get_language_from_mode(const irep_idt &mode)
Get the language corresponding to the given mode.
Definition: mode.cpp:50
Symbol table entry.
Definition: symbol.h:27
irep_idt get_entry_point_mode() const
Find out the mode of the current entry point to determine the mode of the replacement entry point.
Abstract interface to support a programming language.
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
virtual bool generate_support_functions(symbol_tablet &symbol_table)=0
Create language-specific support functions, such as __CPROVER_start, __CPROVER_initialize and languag...
virtual void set_message_handler(message_handlert &_message_handler)
Definition: message.h:169
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:144
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:35
Author: Diffblue Ltd.
bool operator()()
To rebuild the _start function in the event the program was compiled into GOTO with a different entry...
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
void remove_existing_entry_point()
Eliminate the existing entry point function symbol and any symbols created in that scope from the sym...
rebuild_goto_start_function_baset(const optionst &options, maybe_lazy_goto_modelt &goto_model, message_handlert &message_handler)
To rebuild the _start function in the event the program was compiled into GOTO with a different entry...
virtual void set_language_options(const optionst &)
Set language-specific options.
Definition: language.h:43