cprover
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 <cstdio>
15 #include <iostream>
16 
17 #ifdef _WIN32
18 #define EX_OK 0
19 #define EX_USAGE 64
20 #define EX_SOFTWARE 70
21 #else
22 #include <sysexits.h>
23 #endif
24 
25 #include <util/exception_utils.h>
26 #include <util/parse_options.h>
27 #include <util/version.h>
28 
31  goto_cc_cmdlinet &_cmdline,
32  const std::string &_base_name,
33  message_handlert &_message_handler):
34  messaget(_message_handler),
35  cmdline(_cmdline),
36  base_name(_base_name)
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  " --print-rejected-preprocessed-source file\n"
68  " copy failing (preprocessed) source to file\n"
69  " --object-bits number of bits used for object addresses\n"
70  "\n";
71  // clang-format on
72 }
73 
76 int goto_cc_modet::main(int argc, const char **argv)
77 {
78  if(cmdline.parse(argc, argv))
79  {
80  usage_error();
81  return EX_USAGE;
82  }
83 
84  try
85  {
86  return doit();
87  }
88 
89  catch(const char *e)
90  {
91  error() << e << eom;
92  return EX_SOFTWARE;
93  }
94 
95  catch(const std::string &e)
96  {
97  error() << e << eom;
98  return EX_SOFTWARE;
99  }
100 
101  catch(int)
102  {
103  return EX_SOFTWARE;
104  }
105 
106  catch(const std::bad_alloc &)
107  {
108  error() << "Out of memory" << eom;
109  return EX_SOFTWARE;
110  }
111  catch(const cprover_exception_baset &e)
112  {
113  error() << e.what() << eom;
114  return EX_SOFTWARE;
115  }
116 }
117 
121 {
122  std::cerr << "Usage error!\n\n";
123  help();
124 }
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
exception_utils.h
goto_cc_modet::register_languages
void register_languages()
Definition: goto_cc_languages.cpp:20
goto_cc_modet::~goto_cc_modet
~goto_cc_modet()
constructor
Definition: goto_cc_mode.cpp:42
messaget::eom
static eomt eom
Definition: message.h:297
version.h
goto_cc_modet::help_mode
virtual void help_mode()=0
CBMC_VERSION
const char * CBMC_VERSION
messaget::error
mstreamt & error() const
Definition: message.h:399
banner_string
std::string banner_string(const std::string &front_end, const std::string &version)
Definition: parse_options.cpp:163
goto_cc_modet::usage_error
virtual void usage_error()
prints a message informing the user about incorrect options
Definition: goto_cc_mode.cpp:120
goto_cc_modet::doit
virtual int doit()=0
cprover_exception_baset::what
virtual std::string what() const =0
A human readable description of what went wrong.
message_handlert
Definition: message.h:28
goto_cc_modet::cmdline
goto_cc_cmdlinet & cmdline
Definition: goto_cc_mode.h:37
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:30
goto_cc_modet::main
int main(int argc, const char **argv)
starts the compiler
Definition: goto_cc_mode.cpp:76
goto_cc_cmdlinet::parse
virtual bool parse(int argc, const char **argv)=0
goto_cc_modet::help
void help()
display command line help
Definition: goto_cc_mode.cpp:47
goto_cc_mode.h
Command line interpretation for goto-cc.
goto_cc_cmdlinet
Definition: goto_cc_cmdline.h:20
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:150
cprover_exception_baset
Base class for exceptions thrown in the cprover project.
Definition: exception_utils.h:25