44 #define DOTGRAPHSETTINGS "color=black;" \
45 "orientation=portrait;" \
67 log.
debug() <<
"Library not found: " << library <<
" (ignoring)"
96 const unsigned warnings_before =
99 auto symbol_table_opt =
compile();
100 if(!symbol_table_opt.has_value())
107 if(
link(*symbol_table_opt))
127 const std::string &file_name,
131 std::ifstream in(file_name);
137 const std::string ext =
138 r == std::string::npos ?
"" : file_name.substr(
r + 1, file_name.length());
141 ext ==
"c" || ext ==
"cc" || ext ==
"cp" || ext ==
"cpp" || ext ==
"CPP" ||
142 ext ==
"c++" || ext ==
"C" || ext ==
"i" || ext ==
"ii" || ext ==
"class" ||
150 if((ext ==
"a" || ext ==
"o") &&
strncmp(hdr,
"!<thin>", 8) == 0)
159 if(hdr[0] == 0x7f &&
memcmp(hdr + 1,
"ELF", 3) == 0)
172 log.
warning() <<
"failed to open file '" << file_name
178 log.
debug() <<
"unknown file type in '" << file_name <<
"'"
184 log.
debug() <<
"ELF object without goto-cc section: '" << file_name <<
"'"
209 const std::string &file_name,
219 std::filesystem::current_path(
tmp_dirs.back());
250 std::ifstream in(tmp_file_out());
253 while(!in.fail() && std::getline(in, line))
255 std::string t = std::filesystem::path(tstr).append(line).string();
260 log.
debug() <<
"Object file is not a goto binary: " << line
275 std::string library_file_name;
280 std::filesystem::path(library_path).append(
"lib" + name +
".a").string();
282 std::ifstream in(library_file_name);
288 library_file_name = std::filesystem::path(library_path)
289 .append(
"lib" + name +
".so")
298 log.
warning() <<
"Warning: Cannot read ELF library "
322 if(symbol_table.has_value())
383 std::cout <<
get_base_name(file_name,
false) <<
'\n' << std::flush;
387 if(!file_symbol_table.has_value())
389 const std::string &debug_outfile=
391 if(!debug_outfile.empty())
408 file_goto_model.
symbol_table = std::move(*file_symbol_table);
415 const std::string file_name_with_obj_ext =
421 .append(file_name_with_obj_ext)
425 cfn = file_name_with_obj_ext;
452 return std::move(symbol_table);
458 const std::string &file_name,
461 std::unique_ptr<languaget> languagep;
473 else if(file_name !=
"-")
476 if(languagep==
nullptr)
478 log.
error() <<
"failed to figure out type of file '" << file_name <<
"'"
490 log.
error() <<
"failed to open input file '" << file_name <<
"'"
502 std::ostream *os = &std::cout;
544 std::ostream *os = &std::cout;
575 const std::string &file_name,
588 log.
statistics() <<
"Writing binary format object '" << file_name <<
"'"
598 if(!outfile.is_open())
620 std::optional<symbol_tablet>
625 if(
parse(file_name, language_files))
637 if(language_files.
final(file_symbol_table))
643 return std::move(file_symbol_table);
650 warning_is_fatal(Werror),
653 cmdline.isset(
"export-function-local-symbols") ||
654 cmdline.isset(
"export-file-local-symbols")),
655 file_local_mangle_suffix(
656 cmdline.isset(
"mangle-suffix") ? cmdline.get_value(
"mangle-suffix") :
"")
666 <<
"The `--export-function-local-symbols` flag is deprecated. "
667 "Please use `--export-file-local-symbols` instead."
678 std::filesystem::remove_all(dir);
683 std::size_t count = 0;
686 if(f.second.body_available())
710 while(before != symbol_table_builder.
symbols.size())
712 before = symbol_table_builder.
symbols.size();
714 typedef std::set<irep_idt> symbols_sett;
715 symbols_sett symbols;
717 for(
const auto &named_symbol : symbol_table_builder.
symbols)
718 symbols.insert(named_symbol.first);
721 for(
const auto &symbol : symbols)
723 symbol_tablet::symbolst::const_iterator s_it =
724 symbol_table_builder.
symbols.find(symbol);
728 s_it->second.is_function() && !s_it->second.is_compiled() &&
729 s_it->second.value.is_not_nil())
742 for(
const auto &pair : symbol_table.
symbols)
744 const irep_idt &name=pair.second.name;
745 const typet &new_type=pair.second.type;
753 std::map<irep_idt, symbolt>::iterator old;
754 std::tie(old, inserted)=
written_macros.insert({name, pair.second});
756 if(!inserted && old->second.type!=new_type)
758 log.
error() <<
"Incompatible CPROVER macro symbol types:" <<
'\n'
759 << old->second.type.pretty() <<
"(at " << old->second.location
762 << new_type.
pretty() <<
"(at " << pair.second.location <<
")"
bool ansi_c_entry_point(symbol_table_baset &symbol_table, message_handlert &message_handler, const c_object_factory_parameterst &object_factory_parameters)
std::string get_value(char option) const
virtual bool isset(char option) const
@ COMPILE_LINK_EXECUTABLE
void add_compiler_specific_defines() const
std::optional< symbol_tablet > compile()
Parses source files and writes object files, or keeps the symbols in the symbol_table if not compilin...
bool parse_stdin(languaget &)
parses a source file (low-level parsing)
bool parse(const std::string &filename, language_filest &)
parses a source file (low-level parsing)
std::string working_directory
std::list< std::string > tmp_dirs
std::string override_language
std::string output_file_object
bool add_input_file(const std::string &)
puts input file names into a list and does preprocessing for libraries.
std::list< std::string > libraries
std::string output_directory_object
std::list< std::string > object_files
bool link(std::optional< symbol_tablet > &&symbol_table)
parses object files and links them
bool doit()
reads and source and object files, compiles and links them into goto program objects.
std::list< std::string > source_files
~compilet()
cleans up temporary files
bool add_written_cprover_symbols(const symbol_tablet &symbol_table)
std::string object_file_extension
compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
constructor
const bool keep_file_local
Whether to keep implementations of file-local symbols.
static std::size_t function_body_count(const goto_functionst &)
void convert_symbols(goto_modelt &)
std::map< irep_idt, symbolt > written_macros
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 find_library(const std::string &)
tries to find a library object file that matches the given library name.
std::optional< symbol_tablet > parse_source(const std::string &)
Parses and type checks a source file located at file_name.
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.
const std::string file_local_mangle_suffix
String to include in all mangled names.
std::list< std::string > library_paths
std::string output_file_executable
struct configt::ansi_ct ansi_c
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
bool starts_with(const char *s) const
equivalent of as_string().starts_with(s)
Mangles the names in an entire program and its symbol table.
void mangle()
Mangle all file-local function symbols in the program.
void convert_function(const irep_idt &identifier, goto_functionst::goto_functiont &result)
A collection of goto functions.
function_mapt function_map
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
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.
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const irep_idt & id() const
language_filet & add_file(const std::string &filename)
bool typecheck(symbol_table_baset &symbol_table, const bool keep_file_local, message_handlert &message_handler)
bool final(symbol_table_baset &symbol_table)
std::unique_ptr< languaget > language
virtual bool parse(std::istream &instream, const std::string &path, message_handlert &message_handler)=0
virtual bool preprocess(std::istream &instream, const std::string &path, std::ostream &outstream, message_handlert &)
std::size_t get_message_count(unsigned level) const
Class that provides messages with a built-in verbosity 'level'.
mstreamt & statistics() const
mstreamt & warning() const
mstreamt & status() const
message_handlert & get_message_handler()
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
static symbol_table_buildert wrap(symbol_table_baset &base_symbol_table)
void set_compiled()
Set the symbol's value to "compiled"; to be used once the code-typed value has been converted to a go...
The type of an expression, extends irept.
static file_typet detect_file_type(const std::string &file_name, message_handlert &message_handler)
Compile and link source and object files.
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
Goto Programs with Functions.
static std::string binary(const constant_exprt &src)
Abstract interface to support a programming language.
bool linking(symbol_table_baset &dest_symbol_table, const symbol_table_baset &new_symbol_table, message_handlert &message_handler)
Merges the symbol table new_symbol_table into dest_symbol_table, renaming symbols from new_symbol_tab...
std::unique_ptr< languaget > get_language_from_filename(const std::string &filename)
Get the language corresponding to the registered file name extensions.
std::unique_ptr< languaget > get_language_from_mode(const irep_idt &mode)
Get the language corresponding to the given mode.
Mangle names of file-local functions to make them unique.
#define FILE_LOCAL_PREFIX
bool is_goto_binary(const std::string &filename, message_handlert &message_handler)
bool read_objects_and_link(const std::list< std::string > &file_names, goto_modelt &dest, message_handlert &message_handler)
Reads object files and updates the config if any files were read.
int run(const std::string &what, const std::vector< std::string > &argv)
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define INITIALIZE_FUNCTION
int strncmp(const char *s1, const char *s2, size_t n)
int memcmp(const void *s1, const void *s2, size_t n)
char * strerror(int errnum)
std::list< std::string > defines
std::string get_temporary_directory(const std::string &name_template)
#define widen_if_needed(s)
void validate_goto_model(const goto_functionst &goto_functions, const validation_modet vm, const goto_model_validation_optionst validation_options)
const char * CBMC_VERSION
static void write_goto_binary(std::ostream &out, const symbol_table_baset &symbol_table, const goto_functionst &goto_functions, irep_serializationt &irepconverter)
Writes a goto program to disc, using goto binary format.