50 #define DOTGRAPHSETTINGS "color=black;" \
51 "orientation=portrait;" \
73 log.
debug() <<
"Library not found: " << library <<
" (ignoring)"
102 const unsigned warnings_before =
105 auto symbol_table_opt =
compile();
106 if(!symbol_table_opt.has_value())
113 if(
link(*symbol_table_opt))
133 const std::string &file_name,
137 std::ifstream in(file_name);
143 const std::string ext =
144 r == std::string::npos ?
"" : file_name.substr(
r + 1, file_name.length());
147 ext ==
"c" || ext ==
"cc" || ext ==
"cp" || ext ==
"cpp" || ext ==
"CPP" ||
148 ext ==
"c++" || ext ==
"C" || ext ==
"i" || ext ==
"ii" || ext ==
"class" ||
149 ext ==
"jar" || ext ==
"jsil")
156 if((ext ==
"a" || ext ==
"o") && strncmp(hdr,
"!<thin>", 8) == 0)
165 if(hdr[0] == 0x7f && memcmp(hdr + 1,
"ELF", 3) == 0)
178 log.
warning() <<
"failed to open file '" << file_name
184 log.
debug() <<
"unknown file type in '" << file_name <<
"'"
190 log.
debug() <<
"ELF object without goto-cc section: '" << file_name <<
"'"
215 const std::string &file_name,
251 std::ifstream in(tmp_file_out());
254 while(!in.fail() && std::getline(in, line))
261 log.
debug() <<
"Object file is not a goto binary: " << line
276 std::string library_file_name;
280 library_file_name =
concat_dir_file(library_path,
"lib" + name +
".a");
282 std::ifstream in(library_file_name);
288 library_file_name =
concat_dir_file(library_path,
"lib" + name +
".so");
296 log.
warning() <<
"Warning: Cannot read ELF library "
320 if(symbol_table.has_value())
384 std::cout <<
get_base_name(file_name,
false) <<
'\n' << std::flush;
388 if(!file_symbol_table.has_value())
390 const std::string &debug_outfile=
392 if(!debug_outfile.empty())
409 file_goto_model.
symbol_table = std::move(*file_symbol_table);
416 const std::string file_name_with_obj_ext =
422 cfn = file_name_with_obj_ext;
449 return std::move(symbol_table);
455 const std::string &file_name,
458 std::unique_ptr<languaget> languagep;
470 else if(file_name !=
"-")
473 if(languagep==
nullptr)
475 log.
error() <<
"failed to figure out type of file '" << file_name <<
"'"
486 std::ifstream infile(
widen(file_name));
488 std::ifstream infile(file_name);
493 log.
error() <<
"failed to open input file '" << file_name <<
"'"
505 std::ostream *os = &std::cout;
521 lf.
language->preprocess(infile, file_name, *os);
527 if(lf.
language->parse(infile, file_name))
547 std::ostream *os = &std::cout;
567 if(language.
parse(std::cin,
""))
578 const std::string &file_name,
591 log.
statistics() <<
"Writing binary format object '" << file_name <<
"'"
601 if(!outfile.is_open())
628 if(
parse(file_name, language_files))
639 if(language_files.
final(file_symbol_table))
645 return std::move(file_symbol_table);
652 warning_is_fatal(Werror),
655 cmdline.isset(
"export-function-local-symbols") ||
656 cmdline.isset(
"export-file-local-symbols")),
657 file_local_mangle_suffix(
658 cmdline.isset(
"mangle-suffix") ? cmdline.get_value(
"mangle-suffix") :
"")
668 <<
"The `--export-function-local-symbols` flag is deprecated. "
669 "Please use `--export-file-local-symbols` instead."
685 std::size_t count = 0;
688 if(f.second.body_available())
712 while(before != symbol_table_builder.
symbols.size())
714 before = symbol_table_builder.
symbols.size();
716 typedef std::set<irep_idt> symbols_sett;
717 symbols_sett symbols;
719 for(
const auto &named_symbol : symbol_table_builder.
symbols)
720 symbols.insert(named_symbol.first);
723 for(
const auto &symbol : symbols)
725 symbol_tablet::symbolst::const_iterator s_it =
726 symbol_table_builder.
symbols.find(symbol);
730 s_it->second.is_function() && !s_it->second.is_compiled() &&
731 s_it->second.value.is_not_nil())
744 for(
const auto &pair : symbol_table.
symbols)
746 const irep_idt &name=pair.second.name;
747 const typet &new_type=pair.second.type;
752 std::map<irep_idt, symbolt>::iterator old;
753 std::tie(old, inserted)=
written_macros.insert({name, pair.second});
755 if(!inserted && old->second.type!=new_type)
757 log.
error() <<
"Incompatible CPROVER macro symbol types:" <<
'\n'
758 << old->second.type.pretty() <<
"(at " << old->second.location
761 << new_type.
pretty() <<
"(at " << pair.second.location <<
")"
bool ansi_c_entry_point(symbol_tablet &symbol_table, message_handlert &message_handler, const c_object_factory_parameterst &object_factory_parameters)
unsignedbv_typet size_type()
std::string get_value(char option) const
virtual bool isset(char option) const
@ COMPILE_LINK_EXECUTABLE
void add_compiler_specific_defines() const
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
bool link(optionalt< symbol_tablet > &&symbol_table)
parses object files and links them
std::string output_directory_object
std::list< std::string > object_files
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 &)
optionalt< symbol_tablet > parse_source(const std::string &)
Parses and type checks a source file located at file_name.
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.
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.
optionalt< symbol_tablet > compile()
Parses source files and writes object files, or keeps the symbols in the symbol_table if not compilin...
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.
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_tablet &symbol_table, const bool keep_file_local=false)
bool final(symbol_table_baset &symbol_table)
std::unique_ptr< languaget > language
virtual bool preprocess(std::istream &instream, const std::string &path, std::ostream &outstream)
virtual bool parse(std::istream &instream, const std::string &path)=0
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()
virtual void set_message_handler(message_handlert &_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.
bool has_prefix(const std::string &s, const std::string &prefix)
void set_current_path(const std::string &path)
Set working directory.
std::string get_current_working_directory()
void delete_directory(const std::string &path)
deletes all files in 'path' and then the directory itself
std::string concat_dir_file(const std::string &directory, const std::string &file_name)
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
Goto Programs with Functions.
const std::string & id2string(const irep_idt &d)
static std::string binary(const constant_exprt &src)
Abstract interface to support a programming language.
bool linking(symbol_tablet &dest_symbol_table, symbol_tablet &new_symbol_table, message_handlert &message_handler)
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.
nonstd::optional< T > optionalt
bool is_goto_binary(const std::string &filename, message_handlert &message_handler)
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
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
std::list< std::string > defines
std::string get_temporary_directory(const std::string &name_template)
std::wstring widen(const char *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
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.