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/symbol.h>
18 #include <util/rename_symbol.h>
19 
20 #include <langapi/language_ui.h>
22 
23 class compilet:public language_uit
24 {
25 public:
29  std::string working_directory;
30  std::string override_language;
31 
32  enum { PREPROCESS_ONLY, // gcc -E
33  COMPILE_ONLY, // gcc -c
34  ASSEMBLE_ONLY, // gcc -S
35  LINK_LIBRARY, // ld -r
36  COMPILE_LINK, // gcc -shared
38  } mode;
39 
40  std::list<std::string> library_paths;
41  std::list<std::string> source_files;
42  std::list<std::string> object_files;
43  std::list<std::string> libraries;
44  std::list<std::string> tmp_dirs;
45  std::list<irep_idt> seen_modes;
46 
47  std::string object_file_extension;
49 
50  compilet(cmdlinet &_cmdline, ui_message_handlert &mh, bool Werror);
51 
52  ~compilet();
53 
54  bool add_input_file(const std::string &);
55  bool find_library(const std::string &);
56  bool add_files_from_archive(const std::string &file_name, bool thin_archive);
57 
58  bool parse(const std::string &filename);
59  bool parse_stdin();
60  bool doit();
61  bool compile();
62  bool link();
63 
64  bool parse_source(const std::string &);
65 
66  bool write_object_file(
67  const std::string &,
68  const symbol_tablet &,
69  goto_functionst &);
70 
72  const std::string &,
73  const symbol_tablet &,
74  goto_functionst &);
75 
77  bool wrote_object_files() const { return wrote_object; }
78 
85  std::size_t> &cprover_macros) const
86  {
88  for(const auto &pair : written_macros)
89  cprover_macros.insert({pair.first,
90  to_code_type(pair.second.type).parameters().size()});
91  }
92 
93 protected:
96 
97  unsigned function_body_count(const goto_functionst &) const;
98 
99  void add_compiler_specific_defines(class configt &config) const;
100 
101  void convert_symbols(goto_functionst &dest);
102 
104  std::map<irep_idt, symbolt> written_macros;
105 
106  // clients must only call add_written_cprover_symbols() if an object
107  // file has been written. The case where an object file was written
108  // but there were no __CPROVER symbols in the goto-program is distinct
109  // from the case where the user forgot to write an object file before
110  // calling add_written_cprover_symbols().
112 };
113 
114 #endif // CPROVER_GOTO_CC_COMPILE_H
symbol_tablet symbol_table
Definition: language_ui.h:25
bool add_input_file(const std::string &)
puts input file names into a list and does preprocessing for libraries.
Definition: compile.cpp:183
std::string output_file_executable
Definition: compile.h:48
compilet(cmdlinet &_cmdline, ui_message_handlert &mh, bool Werror)
constructor
Definition: compile.cpp:639
Globally accessible architectural configuration.
Definition: config.h:24
virtual bool parse()
Definition: language_ui.cpp:38
Symbol table entry.
std::list< std::string > tmp_dirs
Definition: compile.h:44
const code_typet & to_code_type(const typet &type)
Cast a generic typet to a code_typet.
Definition: std_types.h:987
cmdlinet & cmdline
Definition: compile.h:94
std::list< std::string > libraries
Definition: compile.h:43
enum compilet::@2 mode
std::list< std::string > library_paths
Definition: compile.h:40
const cmdlinet & _cmdline
Definition: language_ui.h:54
bool doit()
reads and source and object files, compiles and links them into goto program objects.
Definition: compile.cpp:69
bool find_library(const std::string &)
tries to find a library object file that matches the given library name.
Definition: compile.cpp:299
bool wrote_object_files() const
Has this compiler written any object files?
Definition: compile.h:77
configt config
Definition: config.cpp:23
bool write_bin_object_file(const std::string &, const symbol_tablet &, goto_functionst &)
writes the goto functions in the function table to a binary format object file.
Definition: compile.cpp:583
bool parse_stdin()
parses a source file (low-level parsing)
Definition: compile.cpp:526
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:84
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:385
bool warning_is_fatal
Definition: compile.h:95
bool parse_source(const std::string &)
parses a source file
Definition: compile.cpp:619
goto_functionst compiled_functions
Definition: compile.h:27
The symbol table.
Definition: symbol_table.h:19
TO_BE_DOCUMENTED.
Definition: namespace.h:74
#define PRECONDITION(CONDITION)
Definition: invariant.h:230
namespacet ns
Definition: compile.h:26
bool wrote_object
Definition: compile.h:111
bool echo_file_name
Definition: compile.h:28
std::string working_directory
Definition: compile.h:29
unsigned function_body_count(const goto_functionst &) const
Definition: compile.cpp:663
bool write_object_file(const std::string &, const symbol_tablet &, goto_functionst &)
writes the goto functions in the function table to a binary format object file.
Definition: compile.cpp:571
std::map< irep_idt, symbolt > written_macros
Definition: compile.h:104
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:223
void convert_symbols(goto_functionst &dest)
Definition: compile.cpp:682
const parameterst & parameters() const
Definition: std_types.h:905
std::string object_file_extension
Definition: compile.h:47
std::list< std::string > source_files
Definition: compile.h:41
std::list< std::string > object_files
Definition: compile.h:42
bool link()
parses object files and links them
Definition: compile.cpp:342
void add_compiler_specific_defines(class configt &config) const
Definition: compile.cpp:677
std::string override_language
Definition: compile.h:30
bool add_written_cprover_symbols(const symbol_tablet &symbol_table)
Definition: compile.cpp:724
std::string output_file_object
Definition: compile.h:48
~compilet()
cleans up temporary files
Definition: compile.cpp:653
std::list< irep_idt > seen_modes
Definition: compile.h:45