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! }
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; }
int preparet::doit() { register_languages(); try { // do we have a goto binary? 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 1; config.ansi_c.set_from_context(context); } else { // // parsing // if(parse()) return 1; // // type checking // if(typecheck()) return 1; // // final adjustments // if(final()) return 1; } { int return_value_get_sync_modules=get_sync_modules(); if(return_value_get_sync_modules>=0) return return_value_get_sync_modules; } { int return_value_get_async_modules=get_async_modules(); if(return_value_get_async_modules>=0) return return_value_get_async_modules; } // 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, options, get_message_handler()); if(cmdline.isset("show-claims")) { show_claims(ns, get_ui(), goto_functions); return 0; } // get the user provided predicates if(cmdline.isset("predicates")) get_predicates( cmdline.getval("predicates"), get_message_handler(), ns, user_provided_predicates); } catch(const char *e) { error(e); return 1; } catch(const std::string e) { error(e); return 1; } catch(int) { return 1; } return -1; // proceed! }
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 }