45 #define DOTGRAPHSETTINGS "color=black;" \ 46 "orientation=portrait;" \ 54 #if defined(__linux__) || \ 55 defined(__FreeBSD_kernel__) || \ 57 defined(__unix__) || \ 58 defined(__CYGWIN__) || \ 68 #define pclose _pclose 85 for(std::list<std::string>::const_iterator it =
libraries.begin();
91 debug() <<
"Library not found: " << *it <<
" (ignoring)" <<
eom;
107 error() <<
"cannot link source files" <<
eom;
113 error() <<
"cannot preprocess object files" <<
eom;
117 const unsigned warnings_before=
144 std::ifstream in(file_name);
147 warning() <<
"failed to open file `" << file_name <<
"'" <<
eom;
152 size_t r=file_name.rfind(
'.', file_name.length()-1);
154 if(r==std::string::npos)
157 warning() <<
"input file `" << file_name
158 <<
"' has no extension, not considered" <<
eom;
162 std::string ext = file_name.substr(r+1, file_name.length());
184 char td[] =
"goto-cc.XXXXXX";
191 error() <<
"Cannot create temporary directory" <<
eom;
196 std::stringstream cmd(
"");
197 if(chdir(
tmp_dirs.back().c_str())!=0)
199 error() <<
"Cannot switch to temporary directory" <<
eom;
208 stream=popen(cmd.str().c_str(),
"r");
216 if(file_name[0]!=
'/' && file_name[1]!=
':')
218 if(file_name[0]!=
'/')
230 cmd <<
"ar t " << file_name;
233 stream=popen(cmd.str().c_str(),
"r");
239 while((ch=fgetc(stream))!=EOF)
243 line+=
static_cast<char>(ch);
267 error() <<
"Could not change back to working directory" <<
eom;
286 for(std::list<std::string>::const_iterator
297 std::ifstream in(tmp+name+
".a");
303 std::string libname=tmp+name+
".so";
309 warning() <<
"Warning: Cannot read ELF library " << libname <<
eom;
326 in.open(file_name, std::ios::in);
330 for(std::size_t i=0; i<4; i++)
332 if(buf[0]==0x7f && buf[1]==
'E' &&
333 buf[2]==
'L' && buf[3]==
'F')
403 const std::string &debug_outfile=
405 if(!debug_outfile.empty())
407 std::ifstream in(file_name, std::ios::binary);
408 std::ofstream out(debug_outfile, std::ios::binary);
410 warning() <<
"Failed sources in " << debug_outfile <<
eom;
449 std::ifstream infile(
widen(file_name));
451 std::ifstream infile(file_name);
456 error() <<
"failed to open input file `" << file_name <<
"'" <<
eom;
475 if(languagep==
nullptr)
477 error() <<
"failed to figure out type of file `" << file_name <<
"'" <<
eom;
486 std::pair<language_filest::file_mapt::iterator, bool>
488 std::pair<std::string, language_filet>(file_name, language_file));
498 std::ostream *os = &std::cout;
508 error() <<
"failed to open output file `" 520 if(language.
parse(infile, file_name))
544 std::ostream *os = &std::cout;
554 error() <<
"failed to open output file `" 564 if(language.
parse(std::cin,
""))
580 const std::string &file_name,
592 const std::string &file_name,
596 statistics() <<
"Writing binary format object `" 597 << file_name <<
"'" <<
eom;
603 std::ofstream outfile(file_name, std::ios::binary);
605 if(!outfile.is_open())
607 error() <<
"Error opening file `" << file_name <<
"'" <<
eom;
617 <<
"; " << cnt <<
" have a body." <<
eom;
663 for(std::list<std::string>::const_iterator it =
tmp_dirs.begin();
673 for(goto_functionst::function_mapt::const_iterator it=
677 if(it->second.body_available())
700 typedef std::set<irep_idt> symbols_sett;
701 symbols_sett symbols;
704 symbols.insert(it->first);
707 for(symbols_sett::const_iterator
715 if(s_it->second.type.id()==ID_code &&
716 !s_it->second.is_macro &&
717 !s_it->second.is_type &&
718 s_it->second.value.id()!=
"compiled" &&
719 s_it->second.value.is_not_nil())
721 debug() <<
"Compiling " << s_it->first <<
eom;
723 s_it->second.value=
exprt(
"compiled");
std::string concat_dir_file(const std::string &directory, const std::string &file_name)
symbol_tablet symbol_table
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
compilet(cmdlinet &_cmdline, ui_message_handlert &mh, bool Werror)
constructor
Globally accessible architectural configuration.
std::wstring widen(const char *s)
std::list< std::string > tmp_dirs
std::list< std::string > libraries
std::list< std::string > defines
bool is_goto_binary(const std::string &filename)
std::list< std::string > library_paths
language_filest language_files
unsigned function_body_count(const goto_functionst &)
std::string get_value(char option) const
const cmdlinet & _cmdline
unsignedbv_typet size_type()
bool doit()
reads and source and object files, compiles and links them into goto program objects.
virtual bool preprocess(std::istream &instream, const std::string &path, std::ostream &outstream)
bool find_library(const std::string &)
tries to find a library object file that matches the given library name.
static mstreamt & eom(mstreamt &m)
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
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.
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
std::string get_current_working_directory()
bool parse_stdin()
parses a source file (low-level parsing)
#define Forall_symbols(it, expr)
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 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
static irep_idt entry_point()
goto_functionst compiled_functions
void delete_directory(const std::string &path)
deletes all files in 'path' and then the directory itself
virtual void set_message_handler(message_handlert &_message_handler)
function_mapt function_map
bool read_object_and_link(const std::string &file_name, symbol_tablet &symbol_table, goto_functionst &functions, message_handlert &message_handler)
reads an object file
std::string working_directory
binary irep conversions with hashing
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.
bool is_elf_file(const std::string &)
checking if we can load an object file
Compile and link source and object files.
message_handlert & get_message_handler()
bool ansi_c_entry_point(symbol_tablet &symbol_table, const std::string &standard_main, message_handlert &message_handler)
languaget * get_language_from_mode(const irep_idt &mode)
Goto Programs with Functions.
std::string get_temporary_directory(const std::string &name_template)
void convert_symbols(goto_functionst &dest)
Base class for all expressions.
languaget * get_language_from_filename(const std::string &filename)
std::string object_file_extension
std::list< std::string > source_files
bool has_suffix(const std::string &s, const std::string &suffix)
std::list< std::string > object_files
bool write_goto_binary(std::ostream &out, const symbol_tablet &lsymbol_table, const goto_functionst &functions, int version)
Writes a goto program to disc.
virtual bool parse(std::istream &instream, const std::string &path)=0
bool link()
parses object files and links them
void add_compiler_specific_defines(class configt &config) const
void convert_function(const irep_idt &identifier)
std::string override_language
std::string output_file_object
~compilet()
cleans up temporary files
unsigned get_message_count(unsigned level) const