Go to the documentation of this file.
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,
182 <<
"Usage: Purpose:\n"
184 <<
" goto-harness [-?] [-h] [--help] show help\n"
185 <<
" goto-harness --version show version\n"
186 <<
" goto-harness <in> <out> --harness-function-name <name> --harness-type "
187 "<harness-type> [harness options]\n"
189 <<
"<in> goto binary to read from\n"
190 <<
"<out> file to write the harness to\n"
191 <<
" the harness is printed as C code, if <out> "
193 " else a goto binary including the harness is "
195 <<
"--harness-function-name the name of the harness function to "
197 <<
"--harness-type one of the harness types listed below\n"
224 "need to specify both input and output file names (may be "
226 "<in goto binary> <output C file or goto binary>"};
237 goto_harness_config.harness_type =
244 "required option not set",
247 goto_harness_config.harness_function_name = {
250 return goto_harness_config;
257 return util_make_unique<function_call_harness_generatort>(
261 factory.register_generator(
"initialize-with-memory-snapshot", [
this]() {
262 return util_make_unique<memory_snapshot_harness_generatort>(
272 auto const common_options =
273 std::set<std::string>{
"version",
281 if(common_options.find(option) == common_options.end())
287 return factory_options;
#define GOTO_HARNESS_GENERATOR_HARNESS_FUNCTION_NAME_OPT
void unload(const irep_idt &name)
ui_message_handlert ui_message_handler
virtual bool isset(char option) const
#define GOTO_HARNESS_GENERATOR_TYPE_OPT
#define CHECK_RETURN(CONDITION)
static abstract_object_pointert transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns)
bool write_goto_binary(std::ostream &out, const symbol_tablet &symbol_table, const goto_functionst &goto_functions, irep_serializationt &irepconverter)
Writes a goto program to disc, using goto binary format.
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP
Thrown when failing to deserialize a value from some low level format, like JSON or raw bytes.
goto_harness_parse_optionst(int argc, const char *argv[])
static void filter_goto_model(goto_modelt &goto_model_with_harness, const std::unordered_set< irep_idt > &goto_model_without_harness_symbols)
void register_generator(std::string generator_name, build_generatort build_generator)
register a new goto-harness generator with the given name.
std::unordered_set< irep_idt > get_symbol_names_from_goto_model(const goto_modelt &goto_model)
goto_harness_generator_factoryt::generator_optionst collect_generate_factory_options()
Gather all the options that are not handled by handle_common_options().
bool has_suffix(const std::string &s, const std::string &suffix)
virtual iteratort begin() override
std::map< std::string, std::list< std::string > > generator_optionst
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
const char * CBMC_VERSION
#define GOTO_HARNESS_OPTIONS
std::string banner_string(const std::string &front_end, const std::string &version)
virtual iteratort end() override
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const std::string & id2string(const irep_idt &d)
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)
std::string get_value(char option) const
helper to select harness type by name.
void set_from_symbol_table(const symbol_tablet &)
bool remove(const irep_idt &name)
Remove a symbol from the symbol table.
option_namest option_names() const
Pseudo-object that can be used to iterate over options in this cmdlinet (should not outlive this)
goto_harness_generator_factoryt make_factory()
Setup the generator factory.
goto_harness_configt handle_common_options()
Handle command line arguments that are common to all harness generators.
message_handlert & get_message_handler()
bool set(const cmdlinet &cmdline)
const symbol_tablet & get_symbol_table() const override
Accessor to get the symbol table.
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 CPROVER_EXIT_SUCCESS
Success indicates the required analysis has been performed without error.
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
const std::list< std::string > & get_values(const std::string &option) const
symbol_tablet symbol_table
Symbol table.
#define FUNCTION_HARNESS_GENERATOR_HELP
std::string align_center_with_border(const std::string &text)
Utility for displaying help centered messages borderered by "* *".