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/message.h>
26 #include <util/parse_options.h>
27 #include <util/version.h>
28 
29 #include "goto_cc_cmdline.h"
30 
33  goto_cc_cmdlinet &_cmdline,
34  const std::string &_base_name,
35  message_handlert &_message_handler)
36  : cmdline(_cmdline), base_name(_base_name), message_handler(_message_handler)
37 {
39 }
40 
43 {
44 }
45 
48 {
49  // clang-format off
50  std::cout << '\n' << banner_string("goto-cc", CBMC_VERSION) << '\n'
51  << align_center_with_border("Copyright (C) 2006-2018") << '\n'
52  << align_center_with_border("Daniel Kroening, Michael Tautschnig,") << '\n' // NOLINT(*)
53  << align_center_with_border("Christoph Wintersteiger") << '\n'
54  <<
55  "\n";
56 
57  help_mode();
58 
59  std::cout <<
60  "Usage: Purpose:\n"
61  "\n"
62  " --verbosity # verbosity level\n"
63  " --function name set entry point to name\n"
64  " --native-compiler cmd command to invoke as preprocessor/compiler\n"
65  " --native-linker cmd command to invoke as linker\n"
66  " --native-assembler cmd command to invoke as assembler (goto-as only)\n"
67  " --export-file-local-symbols\n"
68  " name-mangle and export file-local symbols\n"
69  " --mangle-suffix suffix append suffix to exported file-local symbols\n"
70  " --print-rejected-preprocessed-source file\n"
71  " copy failing (preprocessed) source to file\n"
72  " --object-bits number of bits used for object addresses\n"
73  "\n";
74  // clang-format on
75 }
76 
79 int goto_cc_modet::main(int argc, const char **argv)
80 {
81  if(cmdline.parse(argc, argv))
82  {
83  usage_error();
84  return EX_USAGE;
85  }
86 
87  try
88  {
89  return doit();
90  }
91 
92  catch(const char *e)
93  {
95  log.error() << e << messaget::eom;
96  return EX_SOFTWARE;
97  }
98 
99  catch(const std::string &e)
100  {
102  log.error() << e << messaget::eom;
103  return EX_SOFTWARE;
104  }
105 
106  catch(int)
107  {
108  return EX_SOFTWARE;
109  }
110 
111  catch(const std::bad_alloc &)
112  {
114  log.error() << "Out of memory" << messaget::eom;
115  return EX_SOFTWARE;
116  }
117 
118  catch(const invalid_source_file_exceptiont &e)
119  {
121  log.error().source_location = e.get_source_location();
122  log.error() << e.get_reason() << messaget::eom;
123  return EX_SOFTWARE;
124  }
125 
126  catch(const cprover_exception_baset &e)
127  {
129  log.error() << e.what() << messaget::eom;
130  return EX_SOFTWARE;
131  }
132 }
133 
137 {
138  std::cerr << "Usage error!\n\n";
139  help();
140 }
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
exception_utils.h
goto_cc_modet::register_languages
void register_languages()
Definition: goto_cc_languages.cpp:23
goto_cc_modet::message_handler
message_handlert & message_handler
Definition: goto_cc_mode.h:40
goto_cc_modet::~goto_cc_modet
~goto_cc_modet()
constructor
Definition: goto_cc_mode.cpp:42
invalid_source_file_exceptiont
Thrown when we can't handle something in an input source file.
Definition: exception_utils.h:171
messaget::eom
static eomt eom
Definition: message.h:297
version.h
goto_cc_modet::help_mode
virtual void help_mode()=0
invalid_source_file_exceptiont::get_source_location
const source_locationt & get_source_location() const
Definition: exception_utils.h:184
goto_cc_cmdline.h
CBMC_VERSION
const char * CBMC_VERSION
banner_string
std::string banner_string(const std::string &front_end, const std::string &version)
Definition: parse_options.cpp:174
goto_cc_modet::usage_error
virtual void usage_error()
prints a message informing the user about incorrect options
Definition: goto_cc_mode.cpp:136
goto_cc_modet::doit
virtual int doit()=0
message_handlert
Definition: message.h:27
goto_cc_modet::cmdline
goto_cc_cmdlinet & cmdline
Definition: goto_cc_mode.h:38
parse_options.h
goto_cc_modet::goto_cc_modet
goto_cc_modet(goto_cc_cmdlinet &, const std::string &_base_name, message_handlert &)
constructor
Definition: goto_cc_mode.cpp:32
cprover_exception_baset::what
virtual std::string what() const
A human readable description of what went wrong.
Definition: exception_utils.cpp:12
goto_cc_modet::main
int main(int argc, const char **argv)
starts the compiler
Definition: goto_cc_mode.cpp:79
goto_cc_cmdlinet::parse
virtual bool parse(int argc, const char **argv)=0
invalid_source_file_exceptiont::get_reason
const std::string & get_reason() const
Definition: exception_utils.h:179
goto_cc_modet::help
void help()
display command line help
Definition: goto_cc_mode.cpp:47
goto_cc_mode.h
message.h
goto_cc_cmdlinet
Definition: goto_cc_cmdline.h:19
align_center_with_border
std::string align_center_with_border(const std::string &text)
Utility for displaying help centered messages borderered by "* *".
Definition: parse_options.cpp:161
cprover_exception_baset
Base class for exceptions thrown in the cprover project.
Definition: exception_utils.h:24