cprover
compile.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Compile and link source and object files.
4 
5 Author: CM Wintersteiger
6 
7 Date: June 2006
8 
9 \*******************************************************************/
10 
13 
14 #ifndef CPROVER_GOTO_CC_COMPILE_H
15 #define CPROVER_GOTO_CC_COMPILE_H
16 
17 #include <util/cmdline.h>
18 #include <util/message.h>
19 #include <util/rename_symbol.h>
20 
22 
23 class language_filest;
24 class languaget;
25 
26 class compilet
27 {
28 public:
29  // configuration
31  bool validate_goto_model = false;
32 
33  enum { PREPROCESS_ONLY, // gcc -E
34  COMPILE_ONLY, // gcc -c
35  ASSEMBLE_ONLY, // gcc -S
36  LINK_LIBRARY, // ld -r
37  COMPILE_LINK, // gcc -shared
39  } mode;
40 
41  std::list<std::string> library_paths;
42  std::list<std::string> source_files;
43  std::list<std::string> object_files;
44  std::list<std::string> libraries;
45 
46  std::string object_file_extension;
48 
49  // the two options below are mutually exclusive -- use either or
51 
52  compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror);
53 
54  ~compilet();
55 
56  bool add_input_file(const std::string &);
57  bool find_library(const std::string &);
58  bool add_files_from_archive(const std::string &file_name, bool thin_archive);
59 
60  bool parse(const std::string &filename, language_filest &);
61  bool parse_stdin(languaget &);
62  bool doit();
64  bool link(optionalt<symbol_tablet> &&symbol_table);
65 
66  optionalt<symbol_tablet> parse_source(const std::string &);
67 
75  static bool write_bin_object_file(
76  const std::string &file_name,
77  const goto_modelt &src_goto_model,
79  message_handlert &message_handler);
80 
82  bool wrote_object_files() const { return wrote_object; }
83 
90  std::size_t> &cprover_macros) const
91  {
93  for(const auto &pair : written_macros)
94  cprover_macros.insert({pair.first,
95  to_code_type(pair.second.type).parameters().size()});
96  }
97 
98 protected:
99  std::string working_directory;
100  std::string override_language;
101 
102  std::list<std::string> tmp_dirs;
103  std::list<irep_idt> seen_modes;
104 
108 
110  const bool keep_file_local;
111 
113  const std::string file_local_mangle_suffix;
114 
115  static std::size_t function_body_count(const goto_functionst &);
116 
118  const std::string &file_name,
119  const goto_modelt &src_goto_model)
120  {
122  file_name,
123  src_goto_model,
126  {
127  return true;
128  }
129 
130  wrote_object = true;
131 
132  return false;
133  }
134 
135  void add_compiler_specific_defines() const;
136 
138 
139  bool add_written_cprover_symbols(const symbol_tablet &symbol_table);
140  std::map<irep_idt, symbolt> written_macros;
141 
142  // clients must only call add_written_cprover_symbols() if an object
143  // file has been written. The case where an object file was written
144  // but there were no __CPROVER symbols in the goto-program is distinct
145  // from the case where the user forgot to write an object file before
146  // calling add_written_cprover_symbols().
148 };
149 
150 #endif // CPROVER_GOTO_CC_COMPILE_H
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
compilet::wrote_object
bool wrote_object
Definition: compile.h:147
symbol_tablet
The symbol table.
Definition: symbol_table.h:20
compilet::echo_file_name
bool echo_file_name
Definition: compile.h:30
compilet::compile
optionalt< symbol_tablet > compile()
Parses source files and writes object files, or keeps the symbols in the symbol_table if not compilin...
Definition: compile.cpp:370
compilet::source_files
std::list< std::string > source_files
Definition: compile.h:42
compilet::parse
bool parse(const std::string &filename, language_filest &)
parses a source file (low-level parsing)
Definition: compile.cpp:452
compilet::add_files_from_archive
bool add_files_from_archive(const std::string &file_name, bool thin_archive)
extracts goto binaries from AR archive and add them as input files.
Definition: compile.cpp:212
compilet::parse_stdin
bool parse_stdin(languaget &)
parses a source file (low-level parsing)
Definition: compile.cpp:539
compilet::write_bin_object_file
static bool write_bin_object_file(const std::string &file_name, const goto_modelt &src_goto_model, bool validate_goto_model, message_handlert &message_handler)
Writes the goto functions of src_goto_model to a binary format object file.
Definition: compile.cpp:575
compilet::COMPILE_ONLY
@ COMPILE_ONLY
Definition: compile.h:34
compilet::doit
bool doit()
reads and source and object files, compiles and links them into goto program objects.
Definition: compile.cpp:58
goto_model.h
Symbol Table + CFG.
compilet::libraries
std::list< std::string > libraries
Definition: compile.h:44
compilet::COMPILE_LINK_EXECUTABLE
@ COMPILE_LINK_EXECUTABLE
Definition: compile.h:38
goto_modelt
Definition: goto_model.h:26
compilet::COMPILE_LINK
@ COMPILE_LINK
Definition: compile.h:37
compilet::cmdline
cmdlinet & cmdline
Definition: compile.h:106
rename_symbol.h
compilet::ASSEMBLE_ONLY
@ ASSEMBLE_ONLY
Definition: compile.h:35
compilet::validate_goto_model
bool validate_goto_model
Definition: compile.h:31
compilet::wrote_object_files
bool wrote_object_files() const
Has this compiler written any object files?
Definition: compile.h:82
compilet::add_compiler_specific_defines
void add_compiler_specific_defines() const
Definition: compile.cpp:692
compilet::written_macros
std::map< irep_idt, symbolt > written_macros
Definition: compile.h:140
to_code_type
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition: std_types.h:738
cmdlinet
Definition: cmdline.h:21
compilet::output_file_object
std::string output_file_object
Definition: compile.h:50
compilet::object_files
std::list< std::string > object_files
Definition: compile.h:43
compilet::add_written_cprover_symbols
bool add_written_cprover_symbols(const symbol_tablet &symbol_table)
Definition: compile.cpp:740
compilet::working_directory
std::string working_directory
Definition: compile.h:99
compilet::file_local_mangle_suffix
const std::string file_local_mangle_suffix
String to include in all mangled names.
Definition: compile.h:113
compilet::compilet
compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
constructor
Definition: compile.cpp:647
compilet::convert_symbols
void convert_symbols(goto_modelt &)
Definition: compile.cpp:698
compilet::output_file_executable
std::string output_file_executable
Definition: compile.h:47
PRECONDITION
#define PRECONDITION(CONDITION)
Definition: invariant.h:464
compilet::parse_source
optionalt< symbol_tablet > parse_source(const std::string &)
Parses and type checks a source file located at file_name.
Definition: compile.cpp:621
compilet::LINK_LIBRARY
@ LINK_LIBRARY
Definition: compile.h:36
compilet::library_paths
std::list< std::string > library_paths
Definition: compile.h:41
compilet::object_file_extension
std::string object_file_extension
Definition: compile.h:46
message_handlert
Definition: message.h:28
compilet::warning_is_fatal
bool warning_is_fatal
Definition: compile.h:107
compilet::~compilet
~compilet()
cleans up temporary files
Definition: compile.cpp:673
code_typet::parameters
const parameterst & parameters() const
Definition: std_types.h:649
compilet::override_language
std::string override_language
Definition: compile.h:100
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
compilet::log
messaget log
Definition: compile.h:105
compilet::function_body_count
static std::size_t function_body_count(const goto_functionst &)
Definition: compile.cpp:681
compilet::add_input_file
bool add_input_file(const std::string &)
puts input file names into a list and does preprocessing for libraries.
Definition: compile.cpp:171
compilet::output_directory_object
std::string output_directory_object
Definition: compile.h:50
compilet::find_library
bool find_library(const std::string &)
tries to find a library object file that matches the given library name.
Definition: compile.cpp:272
compilet::PREPROCESS_ONLY
@ PREPROCESS_ONLY
Definition: compile.h:33
compilet::link
bool link(optionalt< symbol_tablet > &&symbol_table)
parses object files and links them
Definition: compile.cpp:313
compilet::keep_file_local
const bool keep_file_local
Whether to keep implementations of file-local symbols.
Definition: compile.h:110
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:23
compilet::mode
enum compilet::@4 mode
messaget::get_message_handler
message_handlert & get_message_handler()
Definition: message.h:184
cmdline.h
compilet::write_bin_object_file
bool write_bin_object_file(const std::string &file_name, const goto_modelt &src_goto_model)
Definition: compile.h:117
languaget
Definition: language.h:40
compilet::seen_modes
std::list< irep_idt > seen_modes
Definition: compile.h:103
compilet::tmp_dirs
std::list< std::string > tmp_dirs
Definition: compile.h:102
compilet
Definition: compile.h:27
message.h
compilet::cprover_macro_arities
void cprover_macro_arities(std::map< irep_idt, std::size_t > &cprover_macros) const
__CPROVER_... macros written to object files and their arities
Definition: compile.h:89
language_filest
Definition: language_file.h:62