/*******************************************************************\ Module: Read goto object files. Author: CM Wintersteiger Date: June 2006 \*******************************************************************/ /// \file /// Read goto object files. #include "read_bin_goto_object.h" #include #include #include #include "goto_functions.h" #include "write_goto_binary.h" static void read_bin_symbol_table_object( std::istream &in, symbol_table_baset &symbol_table, irep_serializationt &irepconverter) { const std::size_t count = irepconverter.read_gb_word(in); // # of symbols for(std::size_t i=0; i(irepconverter.reference_convert(in)); sym.value = static_cast(irepconverter.reference_convert(in)); sym.location = static_cast( irepconverter.reference_convert(in)); sym.name = irepconverter.read_string_ref(in); sym.module = irepconverter.read_string_ref(in); sym.base_name = irepconverter.read_string_ref(in); sym.mode = irepconverter.read_string_ref(in); sym.pretty_name = irepconverter.read_string_ref(in); // obsolete: symordering irepconverter.read_gb_word(in); std::size_t flags=irepconverter.read_gb_word(in); sym.is_weak = (flags &(1 << 16))!=0; sym.is_type = (flags &(1 << 15))!=0; sym.is_property = (flags &(1 << 14))!=0; sym.is_macro = (flags &(1 << 13))!=0; sym.is_exported = (flags &(1 << 12))!=0; sym.is_input = (flags &(1 << 11))!=0; sym.is_output = (flags &(1 << 10))!=0; sym.is_state_var = (flags &(1 << 9))!=0; sym.is_parameter = (flags &(1 << 8))!=0; sym.is_auxiliary = (flags &(1 << 7))!=0; // sym.binding = (flags &(1 << 6))!=0; sym.is_lvalue = (flags &(1 << 5))!=0; sym.is_static_lifetime = (flags &(1 << 4))!=0; sym.is_thread_local = (flags &(1 << 3))!=0; sym.is_file_local = (flags &(1 << 2))!=0; sym.is_extern = (flags &(1 << 1))!=0; sym.is_volatile = (flags &1)!=0; symbol_table.add(sym); } } /// The serialised form of the goto-model currently includes the parameter /// identifiers in the symbol table attached to the types of function symbols. /// However it is not included in the goto functions. Therefore this function is /// needed to copy the parameter identifiers from the symbol table to the /// functions. static void copy_parameter_identifiers( const symbol_table_baset &symbol_table, goto_functionst &functions) { for(const auto &name_symbol : symbol_table) { const auto &symbol = name_symbol.second; if(symbol.is_type) continue; const auto code_type = type_try_dynamic_cast(symbol.type); if(!code_type) continue; // Makes sure there is an empty function for every function symbol. auto emplaced = functions.function_map.emplace(symbol.name, goto_functiont()); emplaced.first->second.set_parameter_identifiers(*code_type); } } static void read_bin_functions_object( std::istream &in, goto_functionst &functions, irep_serializationt &irepconverter) { const std::size_t count = irepconverter.read_gb_word(in); // # of functions for(std::size_t fct_index = 0; fct_index < count; ++fct_index) { irep_idt fname=irepconverter.read_gb_string(in); goto_functionst::goto_functiont &f = functions.function_map[fname]; typedef std::map< goto_programt::targett, std::list, goto_programt::target_less_than> target_mapt; target_mapt target_map; typedef std::map rev_target_mapt; rev_target_mapt rev_target_map; bool hidden=false; std::size_t ins_count = irepconverter.read_gb_word(in); // # of instructions for(std::size_t ins_index = 0; ins_index < ins_count; ++ins_index) { goto_programt::targett itarget = f.body.add_instruction(); // take copies as references into irepconverter are not stable codet code = static_cast(irepconverter.reference_convert(in)); source_locationt source_location = static_cast( irepconverter.reference_convert(in)); goto_program_instruction_typet instruction_type = (goto_program_instruction_typet)irepconverter.read_gb_word(in); exprt guard = static_cast(irepconverter.reference_convert(in)); goto_programt::instructiont instruction{ code, source_location, instruction_type, guard, {}}; instruction.target_number = irepconverter.read_gb_word(in); if(instruction.is_target() && rev_target_map.insert( rev_target_map.end(), std::make_pair(instruction.target_number, itarget))->second!=itarget) UNREACHABLE; std::size_t t_count = irepconverter.read_gb_word(in); // # of targets for(std::size_t i=0; i