CBMC
goto_bmc_parse_options.cpp
Go to the documentation of this file.
1 // Author: Fotis Koutoulakis for Diffblue Ltd.
2 
4 
5 #include <util/exit_codes.h>
6 #include <util/help_formatter.h>
7 #include <util/message.h>
8 #include <util/version.h>
9 
12 
13 #include "api.h"
14 
18  argc,
19  argv,
20  std::string("goto-bmc") + CBMC_VERSION)
21 {
22 }
23 
25 {
26  auto api_options = api_optionst::create();
27 
28  if(cmdline.isset("version"))
29  {
31  return CPROVER_EXIT_SUCCESS;
32  }
33 
34  api_sessiont api{api_options};
35 
36  if(cmdline.args.size() != 1 || !api.is_goto_binary(cmdline.args[0]))
37  {
38  log.error() << "Please give exactly one binary file" << messaget::eom;
40  }
41 
42  std::string filename = cmdline.args[0];
43 
44  if(cmdline.isset("validate-goto-model"))
45  {
46  api_options.validate_goto_model(true);
47  }
48 
49  log.status() << "goto-bmc version " << *api.get_api_version()
50  << messaget::eom;
51 
52  // The API works with a callback for querying state - we for now just print
53  // collected messages from the message buffer to stdout.
54  struct call_back_contextt
55  {
56  std::reference_wrapper<messaget> log;
57  bool error_seen;
58  } call_back_context{log};
59  const auto callback = [](
60  const api_messaget &message,
61  api_call_back_contextt api_call_back_context) {
62  auto context = static_cast<call_back_contextt *>(api_call_back_context);
63  const bool is_error_message = api_message_is_error(message);
64  context->error_seen |= is_error_message;
65  (is_error_message ? context->log.get().error()
66  : context->log.get().status())
68  };
69 
70  api.set_message_callback(callback, &call_back_context);
71 
72  // Finally, we read the goto-binary the user supplied...
73  api.read_goto_binary(filename);
74  if(call_back_context.error_seen)
76 
77  // ... and run analysis on it.
78  auto result = api.run_verifier();
79 
80  return verifier_result_to_exit_code(result->final_result());
81 }
82 
84 {
85  log.status() << '\n'
86  << banner_string("goto-bmc", CBMC_VERSION) << '\n'
87  << align_center_with_border("Copyright (C) 2023") << '\n'
88  << align_center_with_border("Diffblue Ltd.") << '\n';
89 
91  "\n"
92  "Usage: \tPurpose:\n"
93  "\n"
94  " {bgoto-bmc} [{y-?}] [{y-h}] [{y--help}] \t show this help\n"
95  " {bgoto-bmc} {y--version} \t show version and exit\n"
96  " {bgoto-bmc} [options] {ufile_name} \t perform bounded model checking on"
97  " symex-ready goto-binary {ufile_name}\n");
99 }
const char * api_message_get_string(const api_messaget &message)
Given a api_message, this function returns that message expressed as a C language string.
Definition: api.cpp:82
bool api_message_is_error(const api_messaget &message)
Definition: api.cpp:87
void * api_call_back_contextt
The type of pointers to contextual data passed to the api_message_callback functions.
Definition: api.h:40
static api_optionst create()
Definition: api_options.cpp:11
virtual bool isset(char option) const
Definition: cmdline.cpp:30
argst args
Definition: cmdline.h:151
goto_bmc_parse_optionst(int argc, const char **argv)
mstreamt & error() const
Definition: message.h:391
mstreamt & status() const
Definition: message.h:406
static eomt eom
Definition: message.h:289
Document and give macros for the exit codes of CPROVER binaries.
#define CPROVER_EXIT_INCORRECT_TASK
The command line is correctly structured but cannot be carried out due to missing files,...
Definition: exit_codes.h:49
#define CPROVER_EXIT_PARSE_ERROR
An error during parsing of the input program.
Definition: exit_codes.h:37
#define CPROVER_EXIT_SUCCESS
Success indicates the required analysis has been performed without error.
Definition: exit_codes.h:16
#define GOTO_BMC_OPTIONS
Help Formatter.
static help_formattert help_formatter(const std::string &s)
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)
int verifier_result_to_exit_code(verifier_resultt result)
Interface for the various verification engines providing results.
const char * CBMC_VERSION