void goto_convert( const codet &code, contextt &context, optionst &options, goto_programt &dest, message_handlert &message_handler) { goto_convertt goto_convert(context, options, message_handler); try { goto_convert.goto_convert(code, dest); } catch(int) { goto_convert.error(); } catch(const char *e) { goto_convert.error(e); } catch(const std::string &e) { goto_convert.error(e); } if(goto_convert.get_error_found()) throw 0; }
void link_to_library( symbol_tablet &symbol_table, goto_functionst &goto_functions, message_handlert &message_handler) { // this needs a fixedpoint, as library functions // may depend on other library functions messaget message(message_handler); message.status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << messaget::eom; std::set<irep_idt> added_functions; while(true) { std::set<irep_idt> called_functions; compute_called_functions(goto_functions, called_functions); // eliminate those for which we already have a body std::set<irep_idt> missing_functions; for(const auto &id : called_functions) { goto_functionst::function_mapt::const_iterator f_it=goto_functions.function_map.find(id); if(f_it!=goto_functions.function_map.end() && f_it->second.body_available()) { // it's overridden! } else if(added_functions.find(id)!=added_functions.end()) { // already added } else missing_functions.insert(id); } // done? if(missing_functions.empty()) break; add_cprover_library(missing_functions, symbol_table, message_handler); // convert to CFG for(const auto &id : missing_functions) { if(symbol_table.symbols.find(id)!=symbol_table.symbols.end()) goto_convert(id, symbol_table, goto_functions, message_handler); added_functions.insert(id); } } }
void add_cegis_library(symbol_tablet &st, goto_functionst &gf, message_handlert &msg, const size_t num_vars, const size_t num_consts, const size_t max_solution_size, const std::string &func_name) { add_execute_placeholder(st, func_name, cegis_execute_type()); std::set<irep_idt> functions; functions.insert(func_name); const std::string library_src( get_cegis_library_text(num_vars, num_consts, max_solution_size, func_name)); add_library(library_src, st, msg); goto_convert(func_name, st, gf, msg); gf.compute_loop_numbers(); gf.update(); set_init_values(st, gf); }
bool symex_parseoptionst::get_goto_program( const optionst &options, goto_functionst &goto_functions) { if(cmdline.args.empty()) { error() << "Please provide a program to verify" << eom; return true; } try { if(cmdline.args.size()==1 && is_goto_binary(cmdline.args[0])) { status() << "Reading GOTO program from file" << eom; if(read_goto_binary(cmdline.args[0], symbol_table, goto_functions, get_message_handler())) return true; config.ansi_c.set_from_symbol_table(symbol_table); if(cmdline.isset("show-symbol-table")) { show_symbol_table(); return true; } irep_idt entry_point=goto_functions.entry_point(); if(symbol_table.symbols.find(entry_point)==symbol_table.symbols.end()) { error() << "The goto binary has no entry point; please complete linking" << eom; return true; } } else if(cmdline.isset("show-parse-tree")) { if(cmdline.args.size()!=1) { error() << "Please give one source file only" << eom; return true; } std::string filename=cmdline.args[0]; #ifdef _MSC_VER std::ifstream infile(widen(filename).c_str()); #else std::ifstream infile(filename.c_str()); #endif if(!infile) { error() << "failed to open input file `" << filename << "'" << eom; return true; } languaget *language=get_language_from_filename(filename); if(language==NULL) { error() << "failed to figure out type of file `" << filename << "'" << eom; return true; } status("Parsing", filename); if(language->parse(infile, filename, get_message_handler())) { error() << "PARSING ERROR" << eom; return true; } language->show_parse(std::cout); return true; } else { if(parse()) return true; if(typecheck()) return true; if(final()) return true; // we no longer need any parse trees or language files clear_parse(); if(cmdline.isset("show-symbol-table")) { show_symbol_table(); return true; } irep_idt entry_point=goto_functions.entry_point(); if(symbol_table.symbols.find(entry_point)==symbol_table.symbols.end()) { error() << "No entry point; please provide a main function" << eom; return true; } status() << "Generating GOTO Program" << eom; goto_convert(symbol_table, goto_functions, ui_message_handler); } // finally add the library status() << "Adding CPROVER library" << eom; link_to_library(symbol_table, goto_functions, ui_message_handler); if(process_goto_program(options, goto_functions)) return true; } catch(const char *e) { error(e); return true; } catch(const std::string e) { error(e); return true; } catch(int) { return true; } catch(std::bad_alloc) { error() << "Out of memory" << eom; return true; } return false; }
int preparet::get_async_modules() { if(goto_functions.function_map.empty()) { // see if we have a "main" if(context.symbols.find("main")==context.symbols.end()) { error("failed to find entry point -- please provide a model"); return 1; } status("Generating GOTO Program"); goto_convert( context, goto_functions, get_message_handler()); } // we no longer need any parse trees or language files clear_parse(); // finally add the library status("Adding CPROVER library"); link_to_library( context, goto_functions, get_message_handler()); if(cmdline.isset("show-goto-functions")) { goto_functions.output(ns, std::cout); return 0; } unsigned functions=goto_functions.function_map.size(); unsigned instructions=0; forall_goto_functions(it, goto_functions) instructions+=it->second.body.instructions.size(); status(i2string(functions)+" functions, "+ i2string(instructions)+" instructions."); if(cmdline.isset("string-abstraction")) string_instrumentation( context, get_message_handler(), goto_functions); status("Removing function pointers"); remove_function_pointers(ns, goto_functions, cmdline.isset("pointer-check")); status("Removing unused functions"); remove_unused_functions( goto_functions, get_message_handler()); // Boom requies full inlining. bool boom= !cmdline.isset("modelchecker") || std::string(cmdline.getval("modelchecker"))=="boom"; // OSWALDO if(cmdline.isset("full-inlining") || boom) { status("Full inlining"); satabs_inline( goto_functions, ns, get_message_handler()); } else { // partially inline functions status("Partial inlining"); satabs_partial_inline( goto_functions, ns, get_message_handler()); // we do this again, to remove all the functions that are inlined now remove_unused_functions( goto_functions, get_message_handler()); status("Adjusting functions"); prepare_functions( context, goto_functions, get_message_handler()); // show it? if(cmdline.isset("show-adjusted-functions")) { goto_functions.output(ns, std::cout); return 0; } } // add loop ids goto_functions.compute_loop_numbers(); add_failed_symbols(context); // add generic checks goto_check(ns, options, goto_functions); if(cmdline.isset("string-abstraction")) { status("String Abstraction"); string_abstraction( context, get_message_handler(), goto_functions); } goto_functions.compute_location_numbers(); #if 0 // obsoleted by goto_check if(cmdline.isset("pointer-check") || cmdline.isset("show-value-sets")) { status("Pointer Analysis"); value_set_analysist value_set_analysis(ns); value_set_analysis(goto_functions); // show it? if(cmdline.isset("show-value-sets")) { show_value_sets(get_ui(), goto_functions, value_set_analysis); return 0; } if(cmdline.isset("pointer-check")) { status("Adding Pointer Checks"); // add pointer checks pointer_checks( goto_functions, context, options, value_set_analysis); } } #endif goto_functions.compute_location_numbers(); // label claims label_claims(goto_functions); // set claim if(cmdline.isset("claim")) set_claims( goto_functions, cmdline.get_values("claim")); // reachability slice? if(!cmdline.isset("no-slicing")) reachability_slicer(goto_functions); // show it? if(cmdline.isset("show-final-program")) { goto_functions.output(ns, std::cout); return 0; } return -1; // proceed! }
int preparet::get_async_modules() { if(goto_functions.function_map.empty()) { // see if we have a "main" if(context.symbols.find("main")==context.symbols.end()) { error("failed to find entry point -- please provide a model"); return 1; } status("Generating GOTO Program"); goto_convert( context, options, goto_functions, get_message_handler()); } if(cmdline.isset("show-goto-functions")) { goto_functions.output(ns, std::cout); return 0; } unsigned functions=goto_functions.function_map.size(); unsigned instructions=0; forall_goto_functions(it, goto_functions) instructions+=it->second.body.instructions.size(); status(i2string(functions)+" functions, "+ i2string(instructions)+" instructions."); if(cmdline.isset("string-abstraction")) string_instrumentation( context, get_message_handler(), goto_functions); status("Removing function pointers"); remove_function_pointers(ns, goto_functions); status("Removing unused functions"); remove_unused_functions( goto_functions, get_message_handler()); if(cmdline.isset("full-inlining")) { status("Full inlining"); satabs_inline( goto_functions, ns, get_message_handler()); } else { // partially inline functions status("Partial inlining"); satabs_partial_inline( goto_functions, ns, get_message_handler()); // we do this again, to remove all the functions that are inlined now remove_unused_functions( goto_functions, get_message_handler()); status("Adjusting functions"); prepare_functions( context, goto_functions, get_message_handler()); // show it? if(cmdline.isset("show-adjusted-functions")) { goto_functions.output(ns, std::cout); return 0; } } // add loop ids goto_functions.compute_loop_numbers(); // show it? if(cmdline.isset("show-loops")) { show_loop_numbers(get_ui(), goto_functions); return 0; } add_failed_symbols(context); // add generic checks goto_check(ns, options, goto_functions); if(cmdline.isset("string-abstraction")) { status("String Abstraction"); string_abstraction( context, get_message_handler(), goto_functions); } goto_functions.compute_location_numbers(); if(cmdline.isset("pointer-check") || cmdline.isset("show-value-sets") || cmdline.isset("data-race-check")) { status("Pointer Analysis"); value_set_analysist value_set_analysis(ns); value_set_analysis(goto_functions); // show it? if(cmdline.isset("show-value-sets")) { show_value_sets(get_ui(), goto_functions, value_set_analysis); return 0; } if(cmdline.isset("pointer-check")) { status("Adding Pointer Checks"); // add pointer checks pointer_checks( goto_functions, context, options, value_set_analysis); } if(cmdline.isset("data-race-check")) { status("Adding Data Race Checks"); add_race_assertions( value_set_analysis, context, goto_functions); value_set_analysis. update(goto_functions); } } goto_functions.compute_location_numbers(); #if 0 // do invariant propagation if(!cmdline.isset("no-invariant-sets")) { status("Invariant Propagation"); invariant_propagation( goto_functions); } else invariant_propagation.initialize( goto_functions); if(cmdline.isset("show-invariant-sets")) { invariant_propagation.output( goto_functions, std::cout); return 0; } // simplify if(!cmdline.isset("no-invariant-sets")) invariant_propagation.simplify( goto_functions); #endif // set claim if(cmdline.isset("claim")) set_claims( goto_functions, cmdline.get_values("claim")); // slice if(!cmdline.isset("no-slicing")) slicer(goto_functions); // show it? if(cmdline.isset("show-final-program")) { goto_functions.output(ns, std::cout); return 0; } return -1; // proceed! }
bool cbmc_parseoptionst::get_goto_program( const optionst &options, bmct &bmc, goto_functionst &goto_functions) { if(cmdline.args.size()==0) { error("Please provide a program to verify"); return true; } try { if(cmdline.args.size()==1 && is_goto_binary(cmdline.args[0])) { status("Reading GOTO program from file"); if(read_goto_binary(cmdline.args[0], context, goto_functions, get_message_handler())) return true; config.ansi_c.set_from_context(context); if(cmdline.isset("show-symbol-table")) { show_symbol_table(); return true; } if(context.symbols.find(ID_main)==context.symbols.end()) { error("The goto binary has no entry point; please complete linking"); return true; } } else { if(parse()) return true; if(typecheck()) return true; if(get_modules(bmc)) return true; if(final()) return true; // we no longer need any parse trees or language files clear_parse(); if(cmdline.isset("show-symbol-table")) { show_symbol_table(); return true; } if(context.symbols.find(ID_main)==context.symbols.end()) { error("No entry point; please provide a main function"); return true; } status("Generating GOTO Program"); goto_convert( context, options, goto_functions, ui_message_handler); } // finally add the library status("Adding CPROVER library"); link_to_library( context, goto_functions, options, ui_message_handler); if(process_goto_program(options, goto_functions)) return true; } catch(const char *e) { error(e); return true; } catch(const std::string e) { error(e); return true; } catch(int) { return true; } catch(std::bad_alloc) { error("Out of memory"); return true; } return false; }
bool get_goto_modelt::operator()(const std::vector<std::string> &files) { if(files.empty()) { error() << "Please provide a program" << eom; return true; } try { std::vector<std::string> binaries, sources; binaries.reserve(files.size()); sources.reserve(files.size()); for(const auto &file : files) { if(is_goto_binary(file)) binaries.push_back(file); else sources.push_back(file); } if(!sources.empty()) { language_filest language_files; language_files.set_message_handler(get_message_handler()); for(const auto &filename : sources) { #ifdef _MSC_VER std::ifstream infile(widen(filename)); #else std::ifstream infile(filename); #endif if(!infile) { error() << "failed to open input file `" << filename << '\'' << eom; return true; } std::pair<language_filest::file_mapt::iterator, bool> result=language_files.file_map.insert( std::pair<std::string, language_filet>(filename, language_filet())); language_filet &lf=result.first->second; lf.filename=filename; lf.language=get_language_from_filename(filename); if(lf.language==NULL) { error("failed to figure out type of file", filename); return true; } languaget &language=*lf.language; language.set_message_handler(get_message_handler()); status() << "Parsing " << filename << eom; if(language.parse(infile, filename)) { error() << "PARSING ERROR" << eom; return true; } lf.get_modules(); } status() << "Converting" << eom; if(language_files.typecheck(symbol_table)) { error() << "CONVERSION ERROR" << eom; return true; } if(binaries.empty()) { if(language_files.final(symbol_table)) { error() << "CONVERSION ERROR" << eom; return true; } } } for(const auto &file : binaries) { status() << "Reading GOTO program from file" << eom; if(read_object_and_link(file, *this, get_message_handler())) return true; } if(!binaries.empty()) config.set_from_symbol_table(symbol_table); status() << "Generating GOTO Program" << eom; goto_convert(symbol_table, goto_functions, get_message_handler()); }
int cbmc_parse_optionst::get_goto_program( const optionst &options, bmct &bmc, // for get_modules goto_functionst &goto_functions) { if(cmdline.args.empty()) { error() << "Please provide a program to verify" << eom; return 6; } try { if(cmdline.isset("show-parse-tree")) { if(cmdline.args.size()!=1 || is_goto_binary(cmdline.args[0])) { error() << "Please give exactly one source file" << eom; return 6; } std::string filename=cmdline.args[0]; #ifdef _MSC_VER std::ifstream infile(widen(filename).c_str()); #else std::ifstream infile(filename.c_str()); #endif if(!infile) { error() << "failed to open input file `" << filename << "'" << eom; return 6; } languaget *language=get_language_from_filename(filename); if(language==NULL) { error() << "failed to figure out type of file `" << filename << "'" << eom; return 6; } language->set_message_handler(get_message_handler()); status("Parsing", filename); if(language->parse(infile, filename)) { error() << "PARSING ERROR" << eom; return 6; } language->show_parse(std::cout); return 0; } cmdlinet::argst binaries; binaries.reserve(cmdline.args.size()); for(cmdlinet::argst::iterator it=cmdline.args.begin(); it!=cmdline.args.end(); ) // no ++it { if(is_goto_binary(*it)) { binaries.push_back(*it); it=cmdline.args.erase(it); continue; } ++it; } if(!cmdline.args.empty()) { if(parse()) return 6; if(typecheck()) return 6; int get_modules_ret=get_modules(bmc); if(get_modules_ret!=-1) return get_modules_ret; if(binaries.empty() && final()) return 6; // we no longer need any parse trees or language files clear_parse(); } for(cmdlinet::argst::const_iterator it=binaries.begin(); it!=binaries.end(); ++it) { status() << "Reading GOTO program from file " << eom; if(read_object_and_link(*it, symbol_table, goto_functions, *this)) return 6; } if(!binaries.empty()) config.set_from_symbol_table(symbol_table); if(cmdline.isset("show-symbol-table")) { show_symbol_table(); return 0; } if(entry_point(symbol_table, "main", get_message_handler())) return 6; status() << "Generating GOTO Program" << eom; goto_convert(symbol_table, goto_functions, ui_message_handler); if(process_goto_program(options, goto_functions)) return 6; } catch(const char *e) { error() << e << eom; return 6; } catch(const std::string e) { error() << e << eom; return 6; } catch(int) { return 6; } catch(std::bad_alloc) { error() << "Out of memory" << eom; return 6; } return -1; // no error, continue }