cprover
mmcc_parse_options.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: mmcc Command Line Option Processing
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "mmcc_parse_options.h"
13 
14 #include <iostream>
15 #include <fstream>
16 
17 #include <util/cout_message.h>
18 
19 #include "mm_parser.h"
20 #include "mm2cpp.h"
21 
22 mmcc_parse_optionst::mmcc_parse_optionst(int argc, const char **argv):
24 {
25 }
26 
29 {
30  if(cmdline.isset("version"))
31  {
32  std::cout << CBMC_VERSION << '\n';
33  return 0;
34  }
35 
36  try
37  {
38  if(cmdline.args.size()==1)
39  {
40  std::ifstream in(cmdline.args[0].c_str());
41 
42  if(!in)
43  {
44  std::cerr << "failed to open `" << cmdline.args[0] << "'\n";
45  return 2;
46  }
47 
48  return convert(in, cmdline.args[0]);
49  }
50  else if(cmdline.args.empty())
51  {
52  return convert(std::cin, "stdin");
53  }
54  else
55  {
56  usage_error();
57  return 1;
58  }
59  }
60  catch(const char *error)
61  {
62  std::cerr << error << '\n';
63  return 10;
64  }
65  catch(const std::string &error)
66  {
67  std::cerr << error << '\n';
68  return 10;
69  }
70 
71  return 0;
72 }
73 
75  std::istream &in,
76  const std::string &file)
77 {
79 
81  mm_parser.in=&in;
83 
84  if(mm_parser.parse())
85  {
86  std::cerr << "parse error, giving up\n";
87  return 3;
88  }
89 
91 
92  return 0;
93 }
94 
97 {
98  // clang-format off
99  std::cout << '\n' << banner_string("MMCC", CBMC_VERSION) << '\n'
100  <<
101  " Copyright (C) 2015-2015\n"
102  "\n"
103  "Usage: Purpose:\n"
104  "\n"
105  " mmcc [-?] [-h] [--help] show help\n"
106  " mmcc file.cat convert given source file\n"
107  " mmcc convert from stdin\n"
108  "\n";
109  // clang-format on
110 }
irep_idt model_name
Definition: mm_parser.h:21
std::istream * in
Definition: parser.h:26
void mm2cpp(const irep_idt &model_name, const irept &instruction, std::ostream &out)
Definition: mm2cpp.cpp:204
virtual bool parse()
Definition: mm_parser.h:24
#define MMCC_OPTIONS
virtual void help()
display command line help
argst args
Definition: cmdline.h:37
virtual bool isset(char option) const
Definition: cmdline.cpp:27
void set_file(const irep_idt &file)
Definition: parser.h:85
mmcc_parse_optionst(int argc, const char **argv)
mm_parsert mm_parser
Definition: mm_parser.cpp:12
int convert(std::istream &, const std::string &)
virtual void set_message_handler(message_handlert &_message_handler)
Definition: message.h:148
std::string banner_string(const std::string &front_end, const std::string &version)
virtual int doit()
invoke main modules
irept instruction
Definition: mm_parser.h:22
mmcc Command Line Option Processing
virtual void usage_error()
goto_programt coverage_criteriont message_handlert & message_handler
Definition: cover.cpp:66
Definition: kdev_t.h:19