void value_set_analysis_fivrt::add_vars( const goto_functionst &goto_functions) { // get the globals std::list<value_set_fivrt::entryt> globals; get_globals(globals); value_set_fivrt &v=state.value_set; v.add_vars(globals); forall_goto_functions(f_it, goto_functions) { // get the locals std::set<irep_idt> locals; get_local_identifiers(f_it->second, locals); for(auto l : locals) { const symbolt &symbol=ns.lookup(l); std::list<value_set_fivrt::entryt> entries; get_entries(symbol, entries); v.add_vars(entries); } }
void invariant_propagationt::add_objects( const goto_functionst &goto_functions) { // get the globals object_listt globals; get_globals(globals); for(goto_functionst::function_mapt::const_iterator f_it=goto_functions.function_map.begin(); f_it!=goto_functions.function_map.end(); f_it++) { // get the locals std::set<irep_idt> locals; get_local_identifiers(f_it->second, locals); const goto_programt &goto_program=f_it->second.body; // cache the list for the locals to speed things up typedef hash_map_cont<irep_idt, object_listt, irep_id_hash> object_cachet; object_cachet object_cache; for(goto_programt::instructionst::const_iterator i_it=goto_program.instructions.begin(); i_it!=goto_program.instructions.end(); i_it++) { #if 0 invariant_sett &is=(*this)[i_it].invariant_set; is.add_objects(globals); #endif for(std::set<irep_idt>::const_iterator l_it=locals.begin(); l_it!=locals.end(); l_it++) { // cache hit? object_cachet::const_iterator e_it=object_cache.find(*l_it); if(e_it==object_cache.end()) { const symbolt &symbol=ns.lookup(*l_it); object_listt &objects=object_cache[*l_it]; get_objects(symbol, objects); #if 0 is.add_objects(objects); #endif } #if 0 else is.add_objects(e_it->second); #endif } } } }
void interpretert::execute_function_call() { const code_function_callt &function_call= to_code_function_call(PC->code); // function to be called mp_integer a=evaluate_address(function_call.function()); if(a==0) throw "function call to NULL"; else if(a>=memory.size()) throw "out-of-range function call"; const memory_cellt &cell=memory[integer2long(a)]; const irep_idt &identifier=cell.identifier; const goto_functionst::function_mapt::const_iterator f_it= goto_functions.function_map.find(identifier); if(f_it==goto_functions.function_map.end()) throw "failed to find function "+id2string(identifier); // return value mp_integer return_value_address; if(function_call.lhs().is_not_nil()) return_value_address= evaluate_address(function_call.lhs()); else return_value_address=0; // values of the arguments std::vector<std::vector<mp_integer> > argument_values; argument_values.resize(function_call.arguments().size()); for(std::size_t i=0; i<function_call.arguments().size(); i++) evaluate(function_call.arguments()[i], argument_values[i]); // do the call if(f_it->second.body_available) { call_stack.push(stack_framet()); stack_framet &frame=call_stack.top(); frame.return_PC=next_PC; frame.return_function=function; frame.old_stack_pointer=stack_pointer; frame.return_value_address=return_value_address; // local variables std::set<irep_idt> locals; get_local_identifiers(f_it->second, locals); for(std::set<irep_idt>::const_iterator it=locals.begin(); it!=locals.end(); it++) { const irep_idt &id=*it; const symbolt &symbol=ns.lookup(id); unsigned size=get_size(symbol.type); if(size!=0) { frame.local_map[id]=stack_pointer; for(unsigned i=0; i<stack_pointer; i++) { unsigned address=stack_pointer+i; if(address>=memory.size()) memory.resize(address+1); memory[address].value=0; memory[address].identifier=id; memory[address].offset=i; } stack_pointer+=size; } } // assign the arguments const code_typet::parameterst ¶meters= to_code_type(f_it->second.type).parameters(); if(argument_values.size()<parameters.size()) throw "not enough arguments"; for(unsigned i=0; i<parameters.size(); i++) { const code_typet::parametert &a=parameters[i]; exprt symbol_expr(ID_symbol, a.type()); symbol_expr.set(ID_identifier, a.get_identifier()); assert(i<argument_values.size()); assign(evaluate_address(symbol_expr), argument_values[i]); } // set up new PC function=f_it; next_PC=f_it->second.body.instructions.begin(); } else throw "no body for "+id2string(identifier); }