43 #define DOTGRAPHSETTINGS "color=black;" \ 44 "orientation=portrait;" \ 52 #if defined(__linux__) || \ 53 defined(__FreeBSD_kernel__) || \ 55 defined(__unix__) || \ 56 defined(__CYGWIN__) || \ 62 #include <util/pragma_push.def> 64 #pragma warning(disable:4668) 71 #define pclose _pclose 72 #include <util/pragma_pop.def> 93 debug() <<
"Library not found: " << library <<
" (ignoring)" <<
eom;
109 error() <<
"cannot link source files" <<
eom;
115 error() <<
"cannot preprocess object files" <<
eom;
119 const unsigned warnings_before=
154 std::ifstream in(file_name);
160 const std::string ext =
161 r == std::string::npos ?
"" : file_name.substr(
r + 1, file_name.length());
164 ext ==
"c" || ext ==
"cc" || ext ==
"cp" || ext ==
"cpp" || ext ==
"CPP" ||
165 ext ==
"c++" || ext ==
"C" || ext ==
"i" || ext ==
"ii" || ext ==
"class" ||
166 ext ==
"jar" || ext ==
"jsil")
173 if((ext ==
"a" || ext ==
"o") && strncmp(hdr,
"!<thin>", 8) == 0)
182 if(hdr[0] == 0x7f && memcmp(hdr + 1,
"ELF", 3) == 0)
195 warning() <<
"failed to open file `" << file_name
196 <<
"': " << std::strerror(errno) <<
eom;
201 debug() <<
"unknown file type in `" << file_name <<
"'" <<
eom;
206 debug() <<
"ELF object without goto-cc section: `" << file_name <<
"'" 231 const std::string &file_name,
234 std::stringstream cmd;
245 error() <<
"Cannot create temporary directory" <<
eom;
250 if(chdir(
tmp_dirs.back().c_str())!=0)
252 error() <<
"Cannot switch to temporary directory" <<
eom;
259 stream=popen(cmd.str().c_str(),
"r");
269 stream = popen(cmd.str().c_str(),
"r");
271 if(stream !=
nullptr)
275 while((ch = fgetc(stream)) != EOF)
279 line += static_cast<char>(ch);
288 debug() <<
"Object file is not a goto binary: " << line <<
eom;
298 error() <<
"Could not change back to working directory" <<
eom;
313 tmp = library_path +
"\\lib";
315 tmp = library_path +
"/lib";
318 std::ifstream in(tmp+name+
".a");
324 std::string libname=tmp+name+
".so";
332 warning() <<
"Warning: Cannot read ELF library " << libname <<
eom;
403 std::cout <<
get_base_name(file_name,
false) <<
'\n' << std::flush;
409 const std::string &debug_outfile=
411 if(!debug_outfile.empty())
416 warning() <<
"Failed sources in " << debug_outfile <<
eom;
433 const std::string file_name_with_obj_ext =
439 cfn = file_name_with_obj_ext;
460 const std::string &file_name,
467 std::ifstream infile(
widen(file_name));
469 std::ifstream infile(file_name);
474 error() <<
"failed to open input file `" << file_name <<
"'" <<
eom;
478 std::unique_ptr<languaget> languagep;
493 if(languagep==
nullptr)
495 error() <<
"failed to figure out type of file `" << file_name <<
"'" <<
eom;
508 std::ostream *os = &std::cout;
518 error() <<
"failed to open output file `" 524 lf.
language->preprocess(infile, file_name, *os);
530 if(lf.
language->parse(infile, file_name))
553 std::ostream *os = &std::cout;
563 error() <<
"failed to open output file `" 573 if(language.
parse(std::cin,
""))
588 const std::string &file_name,
599 const std::string &file_name,
602 statistics() <<
"Writing binary format object `" 603 << file_name <<
"'" <<
eom;
611 if(!outfile.is_open())
613 error() <<
"Error opening file `" << file_name <<
"'" <<
eom;
623 <<
"; " << cnt <<
" have a body." <<
eom;
638 if(
parse(file_name, language_files))
644 error() <<
"CONVERSION ERROR" <<
eom;
650 error() <<
"CONVERSION ERROR" <<
eom;
661 ns(goto_model.symbol_table),
663 warning_is_fatal(Werror)
684 std::size_t count = 0;
687 if(f.second.body_available())
711 while(before != symbol_table_builder.
symbols.size())
713 before = symbol_table_builder.
symbols.size();
715 typedef std::set<irep_idt> symbols_sett;
716 symbols_sett symbols;
718 for(
const auto &named_symbol : symbol_table_builder.
symbols)
719 symbols.insert(named_symbol.first);
722 for(
const auto &symbol : symbols)
724 symbol_tablet::symbolst::const_iterator s_it =
725 symbol_table_builder.
symbols.find(symbol);
729 s_it->second.is_function() && !s_it->second.is_compiled() &&
730 s_it->second.value.is_not_nil())
732 debug() <<
"Compiling " << s_it->first <<
eom;
742 for(
const auto &pair : symbol_table.
symbols)
744 const irep_idt &name=pair.second.name;
745 const typet &new_type=pair.second.type;
750 std::map<irep_idt, symbolt>::iterator old;
751 std::tie(old, inserted)=
written_macros.insert({name, pair.second});
753 if(!inserted && old->second.type!=new_type)
755 error() <<
"Incompatible CPROVER macro symbol types:" <<
eom 756 << old->second.type.pretty() <<
"(at " << old->second.location
758 <<
"(at " << pair.second.location <<
")" <<
eom;
std::string concat_dir_file(const std::string &directory, const std::string &file_name)
The type of an expression, extends irept.
bool add_input_file(const std::string &)
puts input file names into a list and does preprocessing for libraries.
struct configt::ansi_ct ansi_c
std::string output_file_executable
const std::string & id2string(const irep_idt &d)
Globally accessible architectural configuration.
bool final(symbol_table_baset &symbol_table)
static file_typet detect_file_type(const std::string &file_name)
std::wstring widen(const char *s)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
void set_compiled()
Set the symbol's value to "compiled"; to be used once the code-typed value has been converted to a go...
std::unique_ptr< languaget > get_language_from_mode(const irep_idt &mode)
Get the language corresponding to the given mode.
std::list< std::string > tmp_dirs
std::list< std::string > libraries
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
std::list< std::string > defines
bool is_goto_binary(const std::string &filename)
std::list< std::string > library_paths
language_filet & add_file(const std::string &filename)
std::string get_value(char option) const
compilet(cmdlinet &_cmdline, message_handlert &mh, bool Werror)
constructor
function_mapt function_map
unsignedbv_typet size_type()
bool doit()
reads and source and object files, compiles and links them into goto program objects.
void convert_function(const irep_idt &identifier, goto_functionst::goto_functiont &result)
std::unique_ptr< languaget > get_language_from_filename(const std::string &filename)
Get the language corresponding to the registered file name extensions.
symbol_tablet symbol_table
Symbol table.
bool find_library(const std::string &)
tries to find a library object file that matches the given library name.
#define CHECK_RETURN(CONDITION)
bool parse(std::istream &instream, const std::string &path) override
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
std::string get_current_working_directory()
bool parse_stdin()
parses a source file (low-level parsing)
mstreamt & warning() const
std::unique_ptr< languaget > language
const irep_idt & id() const
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.
virtual bool isset(char option) const
bool compile()
parses source files and writes object files, or keeps the symbols in the symbol_table depending on th...
bool write_goto_binary(std::ostream &out, const goto_modelt &goto_model, int version)
Writes a goto program to disc.
bool write_object_file(const std::string &, const goto_modelt &)
writes the goto functions in the function table to a binary format object file.
bool preprocess(std::istream &instream, const std::string &path, std::ostream &outstream) override
ANSI-C preprocessing.
bool parse_source(const std::string &)
parses a source file
#define INITIALIZE_FUNCTION
void delete_directory(const std::string &path)
deletes all files in 'path' and then the directory itself
bool typecheck(symbol_tablet &symbol_table)
bool has_prefix(const std::string &s, const std::string &prefix)
A collection of goto functions.
virtual void set_message_handler(message_handlert &_message_handler)
Class that provides messages with a built-in verbosity 'level'.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
std::string working_directory
std::map< irep_idt, symbolt > written_macros
Compile and link source and object files.
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.
message_handlert & get_message_handler()
Goto Programs with Functions.
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
std::string get_temporary_directory(const std::string &name_template)
static symbol_table_buildert wrap(symbol_table_baset &base_symbol_table)
void convert_symbols(goto_functionst &dest)
const char * CBMC_VERSION
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)
std::size_t function_body_count(const goto_functionst &) const
static std::string binary(const constant_exprt &src)
#define UNREACHABLE
This should be used to mark dead code.
std::size_t get_message_count(unsigned level) const
std::string object_file_extension
std::list< std::string > source_files
bool parse(const std::string &filename, language_filest &)
parses a source file (low-level parsing)
std::list< std::string > object_files
bool link()
parses object files and links them
void add_compiler_specific_defines(class configt &config) const
std::string output_directory_object
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
std::string override_language
bool add_written_cprover_symbols(const symbol_tablet &symbol_table)
std::string output_file_object
goto_functionst goto_functions
GOTO functions.
mstreamt & statistics() const
~compilet()
cleans up temporary files