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
const parameterst & parameters() const
Definition: std_types.h:860
void add_compiler_specific_defines() const
Definition: compile.cpp:694
cmdlinet & cmdline
Definition: compile.h:106
bool wrote_object
Definition: compile.h:147
bool parse_stdin(languaget &)
parses a source file (low-level parsing)
Definition: compile.cpp:539
bool parse(const std::string &filename, language_filest &)
parses a source file (low-level parsing)
Definition: compile.cpp:452
std::string working_directory
Definition: compile.h:99
std::list< std::string > tmp_dirs
Definition: compile.h:102
bool echo_file_name
Definition: compile.h:30
@ ASSEMBLE_ONLY
Definition: compile.h:35
@ LINK_LIBRARY
Definition: compile.h:36
@ PREPROCESS_ONLY
Definition: compile.h:33
@ COMPILE_LINK_EXECUTABLE
Definition: compile.h:38
@ COMPILE_ONLY
Definition: compile.h:34
@ COMPILE_LINK
Definition: compile.h:37
std::string override_language
Definition: compile.h:100
std::string output_file_object
Definition: compile.h:50
bool write_bin_object_file(const std::string &file_name, const goto_modelt &src_goto_model)
Definition: compile.h:117
bool add_input_file(const std::string &)
puts input file names into a list and does preprocessing for libraries.
Definition: compile.cpp:171
std::list< std::string > libraries
Definition: compile.h:44
std::list< irep_idt > seen_modes
Definition: compile.h:103
bool link(optionalt< symbol_tablet > &&symbol_table)
parses object files and links them
Definition: compile.cpp:313
std::string output_directory_object
Definition: compile.h:50
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
enum compilet::@4 mode
std::list< std::string > object_files
Definition: compile.h:43
bool doit()
reads and source and object files, compiles and links them into goto program objects.
Definition: compile.cpp:58
std::list< std::string > source_files
Definition: compile.h:42
~compilet()
cleans up temporary files
Definition: compile.cpp:675
bool wrote_object_files() const
Has this compiler written any object files?
Definition: compile.h:82
bool add_written_cprover_symbols(const symbol_tablet &symbol_table)
Definition: compile.cpp:742
std::string object_file_extension
Definition: compile.h:46
compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
constructor
Definition: compile.cpp:648
bool validate_goto_model
Definition: compile.h:31
const bool keep_file_local
Whether to keep implementations of file-local symbols.
Definition: compile.h:110
bool warning_is_fatal
Definition: compile.h:107
static std::size_t function_body_count(const goto_functionst &)
Definition: compile.cpp:683
optionalt< symbol_tablet > parse_source(const std::string &)
Parses and type checks a source file located at file_name.
Definition: compile.cpp:621
void convert_symbols(goto_modelt &)
Definition: compile.cpp:700
std::map< irep_idt, symbolt > written_macros
Definition: compile.h:140
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
bool find_library(const std::string &)
tries to find a library object file that matches the given library name.
Definition: compile.cpp:272
messaget log
Definition: compile.h:105
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
const std::string file_local_mangle_suffix
String to include in all mangled names.
Definition: compile.h:113
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
std::list< std::string > library_paths
Definition: compile.h:41
std::string output_file_executable
Definition: compile.h:47
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
A collection of goto functions.
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
message_handlert & get_message_handler()
Definition: message.h:184
The symbol table.
Definition: symbol_table.h:20
Symbol Table + CFG.
nonstd::optional< T > optionalt
Definition: optional.h:35
#define PRECONDITION(CONDITION)
Definition: invariant.h:464
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition: std_types.h:949