CBMC
as86_cmdline.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: A special command line object for as86 (of Bruce's C Compiler)
4 
5 Author: Michael Tautschnig
6 
7 \*******************************************************************/
8 
11 
12 #include "as86_cmdline.h"
13 
14 #include <iostream>
15 
16 #include <util/prefix.h>
17 
18 // non-as86 options
20 {
21  "--verbosity",
22  "--function",
23  "--native-assembler",
24  "--print-rejected-preprocessed-source",
25  nullptr
26 };
27 
29 {
30  "-0",
31  "-1",
32  "-2",
33  "-3",
34  "-a",
35  "-g",
36  "-j",
37  "-O",
38  "-u",
39  "-u-", // both -u and -u- seem to be accepted
40  "-v",
41  "-w-",
42  nullptr
43 };
44 
46 {
47  "-lm",
48  "-l",
49  "-n",
50  "-o",
51  "-b",
52  "-s",
53  "-t",
54  nullptr
55 };
56 
57 bool as86_cmdlinet::parse(int argc, const char **argv)
58 {
59  assert(argc>0);
60  add_arg(argv[0]);
61 
62  for(int i=1; i<argc; i++)
63  {
64  std::string argv_i=argv[i];
65 
66  // file?
67  if(argv_i=="-" || !has_prefix(argv_i, "-"))
68  {
69  add_infile_arg(argv_i);
70  continue;
71  }
72 
73  bool found=false;
74 
75  // separated only, and also allow concatenation with "="
76  for(const char **o=goto_as86_options_with_argument;
77  *o!=nullptr && !found;
78  ++o)
79  {
80  std::string os(*o);
81 
82  if(argv_i==os) // separated
83  {
84  found=true;
85  if(i!=argc-1)
86  {
87  set(argv_i, argv[i+1]);
88  ++i;
89  }
90  else
91  set(argv_i, "");
92  }
93  else if(has_prefix(argv_i, os+"=")) // concatenated with "="
94  {
95  found=true;
96  set(os, argv_i.substr(os.size()+1));
97  }
98  }
99 
100  // goto-as86-only command line argument found
101  if(found)
102  continue;
103 
104  // add to new_argv
105  add_arg(argv_i);
106 
107  // without argument; also store in cmdlinet
108  if(in_list(argv_i.c_str(), as86_options_without_argument))
109  {
110  set(argv_i);
111  continue;
112  }
113 
114  for(const char **o=as86_options_with_argument;
115  *o!=nullptr && !found;
116  ++o)
117  {
118  std::string os(*o);
119 
120  if(argv_i==os) // separated
121  {
122  found=true;
123  if(i!=argc-1)
124  {
125  set(argv_i, argv[i+1]);
126  add_arg(argv[i+1]);
127  ++i;
128  }
129  else
130  set(argv_i, "");
131  }
132  else if(has_prefix(argv_i, os))
133  {
134  found=true;
135  set(os, argv[i]+os.size());
136  }
137  }
138 
139  if(!found)
140  {
141  // unrecognized option
142  std::cerr << "Warning: uninterpreted as86 option '" << argv_i
143  << "'\n";
144  }
145  }
146 
147  return false;
148 }
goto_cc_cmdlinet::set
void set(const std::string &opt, const char *value) override
Set option option to value.
Definition: goto_cc_cmdline.h:33
prefix.h
as86_options_without_argument
const char * as86_options_without_argument[]
Definition: as86_cmdline.cpp:28
as86_options_with_argument
const char * as86_options_with_argument[]
Definition: as86_cmdline.cpp:45
has_prefix
bool has_prefix(const std::string &s, const std::string &prefix)
Definition: converter.cpp:13
goto_cc_cmdlinet::add_infile_arg
void add_infile_arg(const std::string &arg)
Definition: goto_cc_cmdline.cpp:102
goto_cc_cmdlinet::add_arg
void add_arg(const std::string &arg)
Definition: goto_cc_cmdline.h:71
as86_cmdline.h
as86_cmdlinet::parse
virtual bool parse(int, const char **)
Definition: as86_cmdline.cpp:57
goto_cc_cmdlinet::in_list
static bool in_list(const char *option, const char **list)
Definition: goto_cc_cmdline.cpp:38
goto_as86_options_with_argument
const char * goto_as86_options_with_argument[]
Definition: as86_cmdline.cpp:19