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 #include <util/version.h>
19 
20 #include "mm_parser.h"
21 #include "mm2cpp.h"
22 
23 mmcc_parse_optionst::mmcc_parse_optionst(int argc, const char **argv):
25 {
26 }
27 
30 {
31  if(cmdline.isset("version"))
32  {
33  std::cout << CBMC_VERSION << '\n';
34  return 0;
35  }
36 
37  try
38  {
39  if(cmdline.args.size()==1)
40  {
41  std::ifstream in(cmdline.args[0].c_str());
42 
43  if(!in)
44  {
45  std::cerr << "failed to open `" << cmdline.args[0] << "'\n";
46  return 2;
47  }
48 
49  return convert(in, cmdline.args[0]);
50  }
51  else if(cmdline.args.empty())
52  {
53  return convert(std::cin, "stdin");
54  }
55  else
56  {
57  usage_error();
58  return 1;
59  }
60  }
61  catch(const char *error)
62  {
63  std::cerr << error << '\n';
64  return 10;
65  }
66  catch(const std::string &error)
67  {
68  std::cerr << error << '\n';
69  return 10;
70  }
71 
72  return 0;
73 }
74 
76  std::istream &in,
77  const std::string &file)
78 {
80 
82  mm_parser.in=&in;
84 
85  if(mm_parser.parse())
86  {
87  std::cerr << "parse error, giving up\n";
88  return 3;
89  }
90 
92 
93  return 0;
94 }
95 
98 {
99  // clang-format off
100  std::cout << '\n' << banner_string("MMCC", CBMC_VERSION) << '\n'
101  <<
102  " Copyright (C) 2015-2015\n"
103  "\n"
104  "Usage: Purpose:\n"
105  "\n"
106  " mmcc [-?] [-h] [--help] show help\n"
107  " mmcc file.cat convert given source file\n"
108  " mmcc convert from stdin\n"
109  "\n";
110  // clang-format on
111 }
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
const char * CBMC_VERSION
Definition: version.cpp:1
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