Go to the documentation of this file.
47 #define DOTGRAPHSETTINGS "color=black;" \
48 "orientation=portrait;" \
72 debug() <<
"Library not found: " << library <<
" (ignoring)" <<
eom;
88 error() <<
"cannot link source files" <<
eom;
94 error() <<
"cannot preprocess object files" <<
eom;
98 const unsigned warnings_before=
131 const std::string &file_name,
135 std::ifstream in(file_name);
141 const std::string ext =
142 r == std::string::npos ?
"" : file_name.substr(
r + 1, file_name.length());
145 ext ==
"c" || ext ==
"cc" || ext ==
"cp" || ext ==
"cpp" || ext ==
"CPP" ||
146 ext ==
"c++" || ext ==
"C" || ext ==
"i" || ext ==
"ii" || ext ==
"class" ||
147 ext ==
"jar" || ext ==
"jsil")
154 if((ext ==
"a" || ext ==
"o") && strncmp(hdr,
"!<thin>", 8) == 0)
163 if(hdr[0] == 0x7f && memcmp(hdr + 1,
"ELF", 3) == 0)
176 warning() <<
"failed to open file '" << file_name
177 <<
"': " << std::strerror(errno) <<
eom;
182 debug() <<
"unknown file type in '" << file_name <<
"'" <<
eom;
187 debug() <<
"ELF object without goto-cc section: '" << file_name <<
"'"
212 const std::string &file_name,
229 error() <<
"Failed to extract archive " << file_name <<
eom;
244 error() <<
"Failed to list archive " << file_name <<
eom;
248 std::ifstream in(tmp_file_out());
251 while(!in.fail() && std::getline(in, line))
258 debug() <<
"Object file is not a goto binary: " << line <<
eom;
272 std::string library_file_name;
276 library_file_name =
concat_dir_file(library_path,
"lib" + name +
".a");
278 std::ifstream in(library_file_name);
284 library_file_name =
concat_dir_file(library_path,
"lib" + name +
".so");
292 warning() <<
"Warning: Cannot read ELF library " << library_file_name
375 std::cout <<
get_base_name(file_name,
false) <<
'\n' << std::flush;
381 const std::string &debug_outfile=
383 if(!debug_outfile.empty())
388 warning() <<
"Failed sources in " << debug_outfile <<
eom;
405 const std::string file_name_with_obj_ext =
411 cfn = file_name_with_obj_ext;
439 const std::string &file_name,
442 std::unique_ptr<languaget> languagep;
454 else if(file_name !=
"-")
457 if(languagep==
nullptr)
459 error() <<
"failed to figure out type of file '" << file_name <<
"'" <<
eom;
469 std::ifstream infile(
widen(file_name));
471 std::ifstream infile(file_name);
476 error() <<
"failed to open input file '" << file_name <<
"'" <<
eom;
487 std::ostream *os = &std::cout;
503 lf.
language->preprocess(infile, file_name, *os);
509 if(lf.
language->parse(infile, file_name))
529 std::ostream *os = &std::cout;
549 if(language.
parse(std::cin,
""))
565 const std::string &file_name,
570 status() <<
"Validating goto model" <<
eom;
574 statistics() <<
"Writing binary format object '" << file_name <<
"'" <<
eom;
582 if(!outfile.is_open())
584 error() <<
"Error opening file '" << file_name <<
"'" <<
eom;
595 << cnt <<
" have a body." <<
eom;
610 if(
parse(file_name, language_files))
616 error() <<
"CONVERSION ERROR" <<
eom;
622 error() <<
"CONVERSION ERROR" <<
eom;
633 ns(goto_model.symbol_table),
635 warning_is_fatal(Werror),
638 cmdline.isset(
"export-function-local-symbols") ||
639 cmdline.isset(
"export-file-local-symbols")),
640 file_local_mangle_suffix(
641 cmdline.isset(
"mangle-suffix") ? cmdline.get_value(
"mangle-suffix") :
"")
649 warning() <<
"The `--export-function-local-symbols` flag is deprecated. "
650 "Please use `--export-file-local-symbols` instead."
667 std::size_t count = 0;
670 if(f.second.body_available())
694 while(before != symbol_table_builder.
symbols.size())
696 before = symbol_table_builder.
symbols.size();
698 typedef std::set<irep_idt> symbols_sett;
699 symbols_sett symbols;
701 for(
const auto &named_symbol : symbol_table_builder.
symbols)
702 symbols.insert(named_symbol.first);
705 for(
const auto &symbol : symbols)
707 symbol_tablet::symbolst::const_iterator s_it =
708 symbol_table_builder.
symbols.find(symbol);
712 s_it->second.is_function() && !s_it->second.is_compiled() &&
713 s_it->second.value.is_not_nil())
715 debug() <<
"Compiling " << s_it->first <<
eom;
725 for(
const auto &pair : symbol_table.
symbols)
727 const irep_idt &name=pair.second.name;
728 const typet &new_type=pair.second.type;
733 std::map<irep_idt, symbolt>::iterator old;
734 std::tie(old, inserted)=
written_macros.insert({name, pair.second});
736 if(!inserted && old->second.type!=new_type)
738 error() <<
"Incompatible CPROVER macro symbol types:" <<
eom
739 << old->second.type.pretty() <<
"(at " << old->second.location
741 <<
"(at " << pair.second.location <<
")" <<
eom;
Class that provides messages with a built-in verbosity 'level'.
#define UNREACHABLE
This should be used to mark dead code.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
std::list< std::string > defines
virtual bool isset(char option) const
std::list< std::string > source_files
bool parse(const std::string &filename, language_filest &)
parses a source file (low-level parsing)
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.
bool parse_stdin(languaget &)
parses a source file (low-level parsing)
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
bool typecheck(symbol_tablet &symbol_table, const bool keep_file_local=false)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
mstreamt & status() const
bool write_goto_binary(std::ostream &out, const symbol_tablet &symbol_table, const goto_functionst &goto_functions, irep_serializationt &irepconverter)
Writes a goto program to disc, using goto binary format.
std::size_t function_body_count(const goto_functionst &) const
void convert_function(const irep_idt &identifier, goto_functionst::goto_functiont &result)
std::unique_ptr< languaget > get_language_from_mode(const irep_idt &mode)
Get the language corresponding to the given mode.
bool doit()
reads and source and object files, compiles and links them into goto program objects.
int run(const std::string &what, const std::vector< std::string > &argv)
std::list< std::string > libraries
void mangle()
Mangle all file-local function symbols in the program.
struct configt::ansi_ct ansi_c
function_mapt function_map
Mangles the names in an entire program and its symbol table.
void add_compiler_specific_defines() const
bool link()
parses object files and links them
std::map< irep_idt, symbolt > written_macros
std::unique_ptr< languaget > get_language_from_filename(const std::string &filename)
Get the language corresponding to the registered file name extensions.
const char * CBMC_VERSION
std::string output_file_object
std::list< std::string > object_files
bool add_written_cprover_symbols(const symbol_tablet &symbol_table)
std::string working_directory
void set_compiled()
Set the symbol's value to "compiled"; to be used once the code-typed value has been converted to a go...
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const std::string & id2string(const irep_idt &d)
const std::string file_local_mangle_suffix
String to include in all mangled names.
std::string concat_dir_file(const std::string &directory, const std::string &file_name)
compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
constructor
std::string output_file_executable
void convert_symbols(goto_functionst &dest)
#define INITIALIZE_FUNCTION
std::string get_value(char option) const
virtual bool parse(std::istream &instream, const std::string &path)=0
std::list< std::string > library_paths
Compile and link source and object files.
virtual void set_message_handler(message_handlert &_message_handler)
language_filet & add_file(const std::string &filename)
const irep_idt & id() const
std::string object_file_extension
~compilet()
cleans up temporary files
std::unique_ptr< languaget > language
@ COMPILE_LINK_EXECUTABLE
std::wstring widen(const char *s)
std::string override_language
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
bool ansi_c_entry_point(symbol_tablet &symbol_table, message_handlert &message_handler, const c_object_factory_parameterst &object_factory_parameters)
bool add_input_file(const std::string &)
puts input file names into a list and does preprocessing for libraries.
std::string output_directory_object
bool find_library(const std::string &)
tries to find a library object file that matches the given library name.
const bool keep_file_local
Whether to keep implementations of file-local symbols.
bool final(symbol_table_baset &symbol_table)
A collection of goto functions.
bool compile()
parses source files and writes object files, or keeps the symbols in the symbol_table depending on th...
message_handlert & get_message_handler()
bool parse_source(const std::string &)
parses a source file
goto_functionst goto_functions
GOTO functions.
static symbol_table_buildert wrap(symbol_table_baset &base_symbol_table)
const symbolst & symbols
Read-only field, used to look up symbols given their names.
bool write_bin_object_file(const std::string &, const goto_modelt &)
Writes the goto functions of src_goto_model to a binary format object file.
static std::string binary(const constant_exprt &src)
bool read_object_and_link(const std::string &file_name, goto_modelt &dest, message_handlert &message_handler)
reads an object file, and also updates config
bool is_goto_binary(const std::string &filename, message_handlert &message_handler)
static file_typet detect_file_type(const std::string &file_name, message_handlert &message_handler)
void validate(const validation_modet vm=validation_modet::INVARIANT, const goto_model_validation_optionst &goto_model_validation_options=goto_model_validation_optionst{}) const override
Check that the goto model is well-formed.
virtual bool preprocess(std::istream &instream, const std::string &path, std::ostream &outstream)
std::string get_current_working_directory()
bool has_prefix(const std::string &s, const std::string &prefix)
std::string get_temporary_directory(const std::string &name_template)
std::list< std::string > tmp_dirs
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
void set_current_path(const std::string &path)
Set working directory.
Goto Programs with Functions.
unsignedbv_typet size_type()
mstreamt & warning() const
void delete_directory(const std::string &path)
deletes all files in 'path' and then the directory itself
symbol_tablet symbol_table
Symbol table.
Mangle names of file-local functions to make them unique.
std::size_t get_message_count(unsigned level) const
mstreamt & statistics() const