34 #include <unordered_set>
37 std::unordered_set<irep_idt>
40 auto symbols = std::unordered_set<irep_idt>{};
44 std::inserter(symbols, symbols.end()),
45 [](
const std::pair<const irep_idt, symbolt> &key_value_pair) {
46 return key_value_pair.first;
53 const std::unordered_set<irep_idt> &goto_model_without_harness_symbols)
55 for(
auto const &symbol_id : goto_model_without_harness_symbols)
59 if(symbol.is_function())
63 goto_model_with_harness.
unload(symbol_id);
64 if(symbol.is_file_local)
69 else if(!symbol.is_type && symbol.is_file_local)
76 else if(!symbol.is_type && symbol.is_static_lifetime)
82 symbol.is_extern =
true;
117 auto read_goto_binary_result =
119 if(!read_goto_binary_result.has_value())
122 got_harness_config.in_file +
"'"};
124 auto goto_model = std::move(read_goto_binary_result.value());
125 auto const goto_model_without_harness_symbols =
133 if(goto_model.symbol_table.has_symbol(
134 got_harness_config.harness_function_name))
137 "harness function `" +
138 id2string(got_harness_config.harness_function_name) +
145 auto harness_generator = factory.factory(
146 got_harness_config.harness_type, factory_options, goto_model);
149 harness_generator->generate(
150 goto_model, got_harness_config.harness_function_name);
152 if(
has_suffix(got_harness_config.out_file,
".c"))
155 auto harness_out = std::ofstream{got_harness_config.out_file};
157 goto_model.goto_functions,
184 "Usage: \tPurpose:\n"
186 " {bgoto-harness} [{y-?}] [{y-h}] [{y--help}] \t show this help\n"
187 " {bgoto-harness} {y--version} \t show version and exit\n"
188 " {bgoto-harness} {uin} {uout} {y--harness-function-name} {uname}"
189 " {y--harness-type} {uharness-type} [harness options]\n"
191 " {uin} \t goto binary to read from\n"
192 " {uout} \t file to write the harness to; the harness is printed as C"
193 " code, if {uout} has a .c suffix, else a goto binary including the harness"
195 " {y--harness-function-name} {uname} \t the name of the harness function to"
197 " {y--harness-type} {utype} \t one of the harness types listed below\n"
227 "need to specify both input and output file names (may be "
229 "<in goto binary> <output C file or goto binary>"};
240 goto_harness_config.harness_type =
247 "required option not set",
250 goto_harness_config.harness_function_name = {
253 return goto_harness_config;
260 return std::make_unique<function_call_harness_generatort>(
264 factory.register_generator(
"initialize-with-memory-snapshot", [
this]() {
265 return std::make_unique<memory_snapshot_harness_generatort>(
275 auto const common_options =
276 std::set<std::string>{
"version",
284 if(common_options.find(option) == common_options.end())
290 return factory_options;
static abstract_object_pointert transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns)
std::string get_value(char option) const
virtual bool isset(char option) const
option_namest option_names() const
Pseudo-object that can be used to iterate over options in this cmdlinet (should not outlive this)
const std::list< std::string > & get_values(const std::string &option) const
bool set(const cmdlinet &cmdline)
void set_from_symbol_table(const symbol_table_baset &)
Thrown when failing to deserialize a value from some low level format, like JSON or raw bytes.
helper to select harness type by name.
std::map< std::string, std::list< std::string > > generator_optionst
void register_generator(std::string generator_name, build_generatort build_generator)
register a new goto-harness generator with the given name.
goto_harness_configt handle_common_options()
Handle command line arguments that are common to all harness generators.
goto_harness_parse_optionst(int argc, const char *argv[])
goto_harness_generator_factoryt make_factory()
Setup the generator factory.
goto_harness_generator_factoryt::generator_optionst collect_generate_factory_options()
Gather all the options that are not handled by handle_common_options().
const symbol_tablet & get_symbol_table() const override
Accessor to get the symbol table.
symbol_tablet symbol_table
Symbol table.
std::size_t unload(const irep_idt &name)
Remove the function named name from the function map, if it exists.
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
message_handlert & get_message_handler()
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
ui_message_handlert ui_message_handler
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
virtual iteratort begin() override
virtual iteratort end() override
void dump_c(const goto_functionst &src, const bool use_system_headers, const bool use_all_headers, const bool include_harness, const namespacet &ns, std::ostream &out)
Dump C from Goto Program.
Document and give macros for the exit codes of CPROVER binaries.
#define CPROVER_EXIT_SUCCESS
Success indicates the required analysis has been performed without error.
#define FUNCTION_HARNESS_GENERATOR_HELP
#define GOTO_HARNESS_GENERATOR_TYPE_OPT
#define GOTO_HARNESS_GENERATOR_HARNESS_FUNCTION_NAME_OPT
std::unordered_set< irep_idt > get_symbol_names_from_goto_model(const goto_modelt &goto_model)
static void filter_goto_model(goto_modelt &goto_model_with_harness, const std::unordered_set< irep_idt > &goto_model_without_harness_symbols)
#define GOTO_HARNESS_OPTIONS
const std::string & id2string(const irep_idt &d)
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP
std::string align_center_with_border(const std::string &text)
Utility for displaying help centered messages borderered by "* *".
std::string banner_string(const std::string &front_end, const std::string &version)
static bool read_goto_binary(const std::string &filename, symbol_tablet &, goto_functionst &, message_handlert &)
Read a goto binary from a file, but do not update config.
#define CHECK_RETURN(CONDITION)
bool has_suffix(const std::string &s, const std::string &suffix)
const char * CBMC_VERSION
static void write_goto_binary(std::ostream &out, const symbol_table_baset &symbol_table, const goto_functionst &goto_functions, irep_serializationt &irepconverter)
Writes a goto program to disc, using goto binary format.