int goto_instrument_parse_optionst::doit() { if(cmdline.isset("version")) { std::cout << CBMC_VERSION << std::endl; return 0; } if(cmdline.args.size()!=1 && cmdline.args.size()!=2) { help(); return 0; } eval_verbosity(); try { register_languages(); get_goto_program(); instrument_goto_program(); if(cmdline.isset("show-value-sets")) { do_function_pointer_removal(); do_partial_inlining(); // recalculate numbers, etc. goto_functions.update(); status() << "Pointer Analysis" << eom; namespacet ns(symbol_table); value_set_analysist value_set_analysis(ns); value_set_analysis(goto_functions); show_value_sets(get_ui(), goto_functions, value_set_analysis); return 0; } if(cmdline.isset("show-global-may-alias")) { do_function_pointer_removal(); do_partial_inlining(); do_remove_returns(); parameter_assignments(symbol_table, goto_functions); // recalculate numbers, etc. goto_functions.update(); namespacet ns(symbol_table); global_may_alias_analysist global_may_alias_analysis; global_may_alias_analysis(goto_functions, ns); global_may_alias_analysis.output(ns, goto_functions, std::cout); return 0; } if(cmdline.isset("show-local-bitvector-analysis")) { do_function_pointer_removal(); do_partial_inlining(); parameter_assignments(symbol_table, goto_functions); // recalculate numbers, etc. goto_functions.update(); namespacet ns(symbol_table); forall_goto_functions(it, goto_functions) { local_bitvector_analysist local_bitvector_analysis(it->second); std::cout << ">>>>" << std::endl; std::cout << ">>>> " << it->first << std::endl; std::cout << ">>>>" << std::endl; local_bitvector_analysis.output(std::cout, it->second, ns); std::cout << std::endl; } return 0; }
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::process_goto_program( const optionst &options, goto_functionst &goto_functions) { try { namespacet ns(context); if(cmdline.isset("string-abstraction")) string_instrumentation( context, get_message_handler(), goto_functions); status("Function Pointer Removal"); remove_function_pointers(ns, goto_functions, cmdline.isset("pointer-check")); status("Partial Inlining"); // do partial inlining goto_partial_inline(goto_functions, ns, ui_message_handler); status("Generic Property Instrumentation"); // 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); } // add failed symbols // needs to be done before pointer analysis add_failed_symbols(context); 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 true; } status("Adding Pointer Checks"); // add pointer checks pointer_checks( goto_functions, context, options, value_set_analysis); } // recalculate numbers, etc. goto_functions.update(); // add loop ids goto_functions.compute_loop_numbers(); // if we aim to cover, replace // all assertions by false to prevent simplification if(cmdline.isset("cover-assertions")) make_assertions_false(goto_functions); // show it? if(cmdline.isset("show-loops")) { show_loop_numbers(get_ui(), goto_functions); return true; } // show it? if(cmdline.isset("show-goto-functions")) { goto_functions.output(ns, std::cout); 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::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! }
void goto_fence_inserter_parse_optionst::instrument_goto_program( goto_functionst &goto_functions) { optionst options; // unwind loops if(cmdline.isset("unwind")) { status() << "Unwinding loops" << eom; options.set_option("unwind", cmdline.get_value("unwind")); } // we add the library, as some analyses benefit status() << "Adding CPROVER library" << eom; link_to_library(symbol_table, goto_functions, ui_message_handler); namespacet ns(symbol_table); if( cmdline.isset("mm") || cmdline.isset("all-shared") || cmdline.isset("volatile") || cmdline.isset("pensieve") || cmdline.isset("naive") || cmdline.isset("all-shared-aeg") ) { if(cmdline.isset("remove-function-pointers")) { status() << "remove soundly function pointers" << eom; remove_function_pointers(symbol_table, goto_functions, cmdline.isset("pointer-check")); } if(cmdline.isset("async")) { status() << "Replace pthread_creates by __CPROVER_ASYNC_0:" << eom; replace_async(ns, goto_functions); goto_functions.update(); } // do partial inlining status() << "Partial Inlining" << eom; goto_partial_inline(goto_functions, ns, ui_message_handler); if(cmdline.isset("const-function-pointer-propagation")) { /* propagate const pointers to functions */ status() << "Propagate Constant Function Pointers" << eom; propagate_const_function_pointers(symbol_table, goto_functions, get_message_handler()); } // goto_functions.output(ns, std::cout); // return; #if 0 status() << "Function Pointer Removal" << eom; remove_function_pointers(symbol_table, goto_functions, cmdline.isset("pointer-check")); #endif #if 0 // do partial inlining status() << "Partial Inlining" << eom; goto_partial_inline(goto_functions, ns, ui_message_handler); #endif status() << "Pointer Analysis" << eom; #ifdef POINTER_ANALYSIS_FI value_set_analysis_fit value_set_analysis(ns); #else value_set_analysist value_set_analysis(ns); #endif #ifndef LOCAL_MAY value_set_analysis(goto_functions); #endif status() << "Removing asm code" << eom; remove_asm(symbol_table, goto_functions); goto_functions.update(); if(cmdline.isset("all-shared")) { status() << "Shared variables accesses detection" << eom; fence_all_shared(get_message_handler(), value_set_analysis, symbol_table, goto_functions); // simple analysis, coupled with script to insert; // does not transform the goto-binary return; } if(cmdline.isset("all-shared-aeg")) { status() << "Shared variables accesses detection (CF)" << eom; fence_all_shared_aeg(get_message_handler(), value_set_analysis, symbol_table, goto_functions); // simple analysis, coupled with script to insert; // does not transform the goto-binary return; } else if(cmdline.isset("volatile")) { status() << "Detection of variables declared volatile" << eom; fence_volatile(get_message_handler(), value_set_analysis, symbol_table, goto_functions); // simple analysis, coupled with script to insert; // does not transform the goto-binary return; } else if(cmdline.isset("pensieve") || cmdline.isset("naive")) { status() << "Delay-set analysis" << eom; const unsigned unwind_loops= cmdline.isset("unwind") ? unsafe_string2unsigned(cmdline.get_value("unwind")) : 0; const unsigned max_po_trans= cmdline.isset("max-po-trans") ? unsafe_string2unsigned(cmdline.get_value("max-po-trans")) : 0; fence_pensieve( value_set_analysis, symbol_table, goto_functions, unwind_loops, max_po_trans, !cmdline.isset("no-po-rendering"), cmdline.isset("render-cluster-file"), cmdline.isset("render-cluster-function"), cmdline.isset("naive"), get_message_handler()); // simple analysis, coupled with script to insert; // does not transform the goto-binary return; } else if(cmdline.isset("mm")) { std::string mm=cmdline.get_value("mm"); memory_modelt model; status() << "Fence detection for " << mm << " via critical cycles and ILP" << eom; // strategy of instrumentation instrumentation_strategyt inst_strategy; if(cmdline.isset("one-event-per-cycle")) inst_strategy=one_event_per_cycle; else if(cmdline.isset("minimum-interference")) inst_strategy=min_interference; else if(cmdline.isset("read-first")) inst_strategy=read_first; else if(cmdline.isset("write-first")) inst_strategy=write_first; else if(cmdline.isset("my-events")) inst_strategy=my_events; else /* default: instruments all unsafe pairs */ inst_strategy=all; const unsigned unwind_loops = cmdline.isset("unwind") ? unsafe_string2unsigned(cmdline.get_value("unwind")) : 0; const unsigned max_var = cmdline.isset("max-var") ? unsafe_string2unsigned(cmdline.get_value("max-var")) : 0; const unsigned max_po_trans = cmdline.isset("max-po-trans") ? unsafe_string2unsigned(cmdline.get_value("max-po-trans")) : 0; if(mm=="tso") { status() << "Adding weak memory (TSO) Instrumentation" << eom; model=TSO; } else if(mm=="pso") { status() << "Adding weak memory (PSO) Instrumentation" << eom; model=PSO; } else if(mm=="rmo") { status() << "Adding weak memory (RMO) Instrumentation" << eom; model=RMO; } else if(mm=="power") { status() << "Adding weak memory (Power) Instrumentation" << eom; model=Power; } else { status/*error*/() << "Unknown weak memory model" << eom; model=Unknown; } /* inference mode */ infer_modet infer_mode=INFER; if(cmdline.isset("userdef")) infer_mode=USER_DEF; loop_strategyt loops=arrays_only; if(cmdline.isset("force-loop-duplication")) loops=all_loops; if(cmdline.isset("no-loop-duplication")) loops=no_loop; /*if(model!=Unknown)*/ fence_weak_memory( model, value_set_analysis, symbol_table, goto_functions, cmdline.isset("scc"), inst_strategy, unwind_loops, !cmdline.isset("cfg-kill"), cmdline.isset("no-dependencies"), loops, max_var, max_po_trans, !cmdline.isset("no-po-rendering"), cmdline.isset("render-cluster-file"), cmdline.isset("render-cluster-function"), cmdline.isset("cav11"), cmdline.isset("hide-internals"), cmdline.isset("print-graph"), infer_mode, get_message_handler(), cmdline.isset("ignore-arrays")); } } // add failed symbols add_failed_symbols(symbol_table); // recalculate numbers, etc. goto_functions.update(); // add loop ids goto_functions.compute_loop_numbers(); // label the assertions label_properties(goto_functions); }