CBMC
goto_cc_mode.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Command line option container
4 
5 Author: CM Wintersteiger, 2006
6 
7 \*******************************************************************/
8 
11 
12 #include "goto_cc_mode.h"
13 
14 #include <iostream>
15 
16 #ifdef _WIN32
17 #define EX_OK 0
18 #define EX_USAGE 64
19 #define EX_SOFTWARE 70
20 #else
21 #include <sysexits.h>
22 #endif
23 
24 #include <util/exception_utils.h>
25 #include <util/help_formatter.h>
26 #include <util/message.h>
27 #include <util/parse_options.h>
28 #include <util/version.h>
29 
30 #include "goto_cc_cmdline.h"
31 
34  goto_cc_cmdlinet &_cmdline,
35  const std::string &_base_name,
36  message_handlert &_message_handler)
37  : cmdline(_cmdline), base_name(_base_name), message_handler(_message_handler)
38 {
40 }
41 
44 {
45 }
46 
49 {
50  // clang-format off
51  std::cout << '\n' << banner_string("goto-cc", CBMC_VERSION) << '\n'
52  << align_center_with_border("Copyright (C) 2006-2018") << '\n'
53  << align_center_with_border("Daniel Kroening, Michael Tautschnig,") << '\n' // NOLINT(*)
54  << align_center_with_border("Christoph Wintersteiger") << '\n'
55  <<
56  "\n";
57  // clang-format on
58 
59  help_mode();
60 
61  std::cout << help_formatter(
62  "Usage: \tPurpose:\n"
63  "\n"
64  " {y--verbosity} {u#} \t verbosity level\n"
65  " {y--function} {uname} \t set entry point to name\n"
66  " {y--native-compiler} {ucmd} \t command to invoke as "
67  "preprocessor/compiler\n"
68  " {y--native-linker} {ucmd} \t command to invoke as linker\n"
69  " {y--native-assembler} {ucmd} \t command to invoke as assembler "
70  "(goto-as only)\n"
71  " {y--export-file-local-symbols} \t "
72  "name-mangle and export file-local symbols\n"
73  " {y--mangle-suffix} {usuffix} \t append suffix to exported file-local "
74  "symbols\n"
75  " {y--print-rejected-preprocessed-source} {ufile} \t "
76  "copy failing (preprocessed) source to file\n"
77  " {y--object-bits} {N} \t number of bits used for object addresses\n"
78  "\n");
79 }
80 
83 int goto_cc_modet::main(int argc, const char **argv)
84 {
85  if(cmdline.parse(argc, argv))
86  {
87  usage_error();
88  return EX_USAGE;
89  }
90 
91  try
92  {
93  return doit();
94  }
95 
96  catch(const char *e)
97  {
99  log.error() << e << messaget::eom;
100  return EX_SOFTWARE;
101  }
102 
103  catch(const std::string &e)
104  {
106  log.error() << e << messaget::eom;
107  return EX_SOFTWARE;
108  }
109 
110  catch(int)
111  {
112  return EX_SOFTWARE;
113  }
114 
115  catch(const std::bad_alloc &)
116  {
118  log.error() << "Out of memory" << messaget::eom;
119  return EX_SOFTWARE;
120  }
121 
122  catch(const invalid_source_file_exceptiont &e)
123  {
125  log.error().source_location = e.get_source_location();
126  log.error() << e.get_reason() << messaget::eom;
127  return EX_SOFTWARE;
128  }
129 
130  catch(const cprover_exception_baset &e)
131  {
133  log.error() << e.what() << messaget::eom;
134  return EX_SOFTWARE;
135  }
136 }
137 
140 {
141  std::cerr << "Usage error!\n\n";
142  help();
143 }
Base class for exceptions thrown in the cprover project.
Definition: c_errors.h:64
virtual bool parse(int argc, const char **argv)=0
~goto_cc_modet()
constructor
virtual int doit()=0
goto_cc_modet(goto_cc_cmdlinet &, const std::string &_base_name, message_handlert &)
constructor
goto_cc_cmdlinet & cmdline
Definition: goto_cc_mode.h:38
virtual void help_mode()=0
message_handlert & message_handler
Definition: goto_cc_mode.h:40
virtual void usage_error()
Prints a message informing the user about incorrect options.
void help()
display command line help
int main(int argc, const char **argv)
starts the compiler
Thrown when we can't handle something in an input source file.
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
static eomt eom
Definition: message.h:297
Command line interpretation for goto-cc.
Command line interpretation for goto-cc.
Help Formatter.
static help_formattert help_formatter(const std::string &s)
double log(double x)
Definition: math.c:2776
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)
const char * CBMC_VERSION