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 <cbmc/version.h>
20 
21 #include "mm_parser.h"
22 #include "mm2cpp.h"
23 
24 mmcc_parse_optionst::mmcc_parse_optionst(int argc, const char **argv):
26 {
27 }
28 
31 {
32  if(cmdline.isset("version"))
33  {
34  std::cout << CBMC_VERSION << '\n';
35  return 0;
36  }
37 
38  try
39  {
40  if(cmdline.args.size()==1)
41  {
42  std::ifstream in(cmdline.args[0].c_str());
43 
44  if(!in)
45  {
46  std::cerr << "failed to open `" << cmdline.args[0] << "'\n";
47  return 2;
48  }
49 
50  return convert(in, cmdline.args[0]);
51  }
52  else if(cmdline.args.empty())
53  {
54  return convert(std::cin, "stdin");
55  }
56  else
57  {
58  usage_error();
59  return 1;
60  }
61  }
62  catch(const char *error)
63  {
64  std::cerr << error << '\n';
65  return 10;
66  }
67  catch(const std::string error)
68  {
69  std::cerr << error << '\n';
70  return 10;
71  }
72 
73  return 0;
74 }
75 
77  std::istream &in,
78  const std::string &file)
79 {
80  console_message_handlert message_handler;
81 
82  mm_parser.set_message_handler(message_handler);
83  mm_parser.in=&in;
84  mm_parser.set_file(file);
85 
86  if(mm_parser.parse())
87  {
88  std::cerr << "parse error, giving up\n";
89  return 3;
90  }
91 
93 
94  return 0;
95 }
96 
99 {
100  std::cout <<
101  "\n"
102  "* * MMCC " CBMC_VERSION " - Copyright (C) 2015-2015 * *\n";
103 
104  std::cout <<
105  "\n"
106  "Usage: Purpose:\n"
107  "\n"
108  " mmcc [-?] [-h] [--help] show help\n"
109  " mmcc file.cat convert given source file\n"
110  " mmcc convert from stdin\n"
111  "\n";
112 }
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:203
virtual bool parse()
Definition: mm_parser.h:24
#define MMCC_OPTIONS
virtual void help()
display command line help
argst args
Definition: cmdline.h:35
virtual bool isset(char option) const
Definition: cmdline.cpp:30
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:122
virtual int doit()
invoke main modules
irept instruction
Definition: mm_parser.h:22
mmcc Command Line Option Processing
#define CBMC_VERSION
Definition: version.h:4
virtual void usage_error()
Definition: kdev_t.h:19