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 
25 class compilet : public messaget
26 {
27 public:
28  // compilation results
31 
32  // configuration
34  std::string working_directory;
35  std::string override_language;
36 
37  enum { PREPROCESS_ONLY, // gcc -E
38  COMPILE_ONLY, // gcc -c
39  ASSEMBLE_ONLY, // gcc -S
40  LINK_LIBRARY, // ld -r
41  COMPILE_LINK, // gcc -shared
43  } mode;
44 
45  std::list<std::string> library_paths;
46  std::list<std::string> source_files;
47  std::list<std::string> object_files;
48  std::list<std::string> libraries;
49  std::list<std::string> tmp_dirs;
50  std::list<irep_idt> seen_modes;
51 
52  std::string object_file_extension;
54 
55  // the two options below are mutually exclusive -- use either or
57 
58  compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror);
59 
60  ~compilet();
61 
62  bool add_input_file(const std::string &);
63  bool find_library(const std::string &);
64  bool add_files_from_archive(const std::string &file_name, bool thin_archive);
65 
66  bool parse(const std::string &filename, language_filest &);
67  bool parse_stdin();
68  bool doit();
69  bool compile();
70  bool link();
71 
72  bool parse_source(const std::string &);
73 
74  bool write_object_file(const std::string &, const goto_modelt &);
75 
76  bool write_bin_object_file(const std::string &, const goto_modelt &);
77 
79  bool wrote_object_files() const { return wrote_object; }
80 
87  std::size_t> &cprover_macros) const
88  {
90  for(const auto &pair : written_macros)
91  cprover_macros.insert({pair.first,
92  to_code_type(pair.second.type).parameters().size()});
93  }
94 
95 protected:
98 
99  std::size_t function_body_count(const goto_functionst &) const;
100 
101  void add_compiler_specific_defines(class configt &config) const;
102 
103  void convert_symbols(goto_functionst &dest);
104 
105  bool add_written_cprover_symbols(const symbol_tablet &symbol_table);
106  std::map<irep_idt, symbolt> written_macros;
107 
108  // clients must only call add_written_cprover_symbols() if an object
109  // file has been written. The case where an object file was written
110  // but there were no __CPROVER symbols in the goto-program is distinct
111  // from the case where the user forgot to write an object file before
112  // calling add_written_cprover_symbols().
114 };
115 
116 #endif // CPROVER_GOTO_CC_COMPILE_H
bool add_input_file(const std::string &)
puts input file names into a list and does preprocessing for libraries.
Definition: compile.cpp:190
std::string output_file_executable
Definition: compile.h:53
goto_modelt goto_model
Definition: compile.h:30
Globally accessible architectural configuration.
Definition: config.h:24
std::list< std::string > tmp_dirs
Definition: compile.h:49
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition: std_types.h:982
cmdlinet & cmdline
Definition: compile.h:96
std::list< std::string > libraries
Definition: compile.h:48
std::list< std::string > library_paths
Definition: compile.h:45
compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
constructor
Definition: compile.cpp:659
bool doit()
reads and source and object files, compiles and links them into goto program objects.
Definition: compile.cpp:78
bool find_library(const std::string &)
tries to find a library object file that matches the given library name.
Definition: compile.cpp:306
bool wrote_object_files() const
Has this compiler written any object files?
Definition: compile.h:79
configt config
Definition: config.cpp:24
bool parse_stdin()
parses a source file (low-level parsing)
Definition: compile.cpp:543
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:86
bool write_bin_object_file(const std::string &, const goto_modelt &)
writes the goto functions in the function table to a binary format object file.
Definition: compile.cpp:598
Symbol Table + CFG.
bool compile()
parses source files and writes object files, or keeps the symbols in the symbol_table depending on th...
Definition: compile.cpp:393
bool write_object_file(const std::string &, const goto_modelt &)
writes the goto functions in the function table to a binary format object file.
Definition: compile.cpp:587
bool warning_is_fatal
Definition: compile.h:97
bool parse_source(const std::string &)
parses a source file
Definition: compile.cpp:633
The symbol table.
Definition: symbol_table.h:19
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:93
#define PRECONDITION(CONDITION)
Definition: invariant.h:438
A collection of goto functions.
namespacet ns
Definition: compile.h:29
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
bool wrote_object
Definition: compile.h:113
bool echo_file_name
Definition: compile.h:33
std::string working_directory
Definition: compile.h:34
std::map< irep_idt, symbolt > written_macros
Definition: compile.h:106
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:230
void convert_symbols(goto_functionst &dest)
Definition: compile.cpp:699
std::size_t function_body_count(const goto_functionst &) const
Definition: compile.cpp:682
const parameterst & parameters() const
Definition: std_types.h:893
std::string object_file_extension
Definition: compile.h:52
std::list< std::string > source_files
Definition: compile.h:46
bool parse(const std::string &filename, language_filest &)
parses a source file (low-level parsing)
Definition: compile.cpp:459
std::list< std::string > object_files
Definition: compile.h:47
bool link()
parses object files and links them
Definition: compile.cpp:346
void add_compiler_specific_defines(class configt &config) const
Definition: compile.cpp:693
std::string output_directory_object
Definition: compile.h:56
std::string override_language
Definition: compile.h:35
bool add_written_cprover_symbols(const symbol_tablet &symbol_table)
Definition: compile.cpp:740
std::string output_file_object
Definition: compile.h:56
enum compilet::@3 mode
~compilet()
cleans up temporary files
Definition: compile.cpp:673
std::list< irep_idt > seen_modes
Definition: compile.h:50