cprover
Loading...
Searching...
No Matches
bcc_cmdline.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: A special command line object for Bruce's C Compiler
4
5Author: Michael Tautschnig
6
7\*******************************************************************/
8
11
12#include "bcc_cmdline.h"
13
14#include <iostream>
15
16#include <util/prefix.h>
17
18// non-bcc options
20{
21 "--verbosity",
22 "--function",
23 "--native-compiler",
24 "--native-linker",
25 "--print-rejected-preprocessed-source",
26 nullptr
27};
28
30{
31 "-0",
32 "-3",
33 "-E",
34 "-G",
35 "-N",
36 "-O",
37 "-P",
38 "-S",
39 "-V",
40 "-c",
41 "-e",
42 "-g",
43 "-v",
44 "-w",
45 "-x",
46 "-W",
47 "-ansi",
48 nullptr
49};
50
52{
53 "-A",
54 "-B",
55 "-D",
56 "-U",
57 "-M",
58 "-o",
59 "-C",
60 "-P",
61 "-I",
62 "-L",
63 "-T",
64 "-Q",
65 "-t",
66 nullptr
67};
68
69bool bcc_cmdlinet::parse(int argc, const char **argv)
70{
71 assert(argc>0);
72 add_arg(argv[0]);
73
74 for(int i=1; i<argc; i++)
75 {
76 std::string argv_i=argv[i];
77
78 // file?
79 if(argv_i=="-" || !has_prefix(argv_i, "-"))
80 {
82 continue;
83 }
84
85 bool found=false;
86
87 // separated only, and also allow concatenation with "="
88 for(const char **o=goto_bcc_options_with_argument;
89 *o!=nullptr && !found;
90 ++o)
91 {
92 std::string os(*o);
93
94 if(argv_i==os) // separated
95 {
96 found=true;
97 if(i!=argc-1)
98 {
99 set(argv_i, argv[i+1]);
100 ++i;
101 }
102 else
103 set(argv_i, "");
104 }
105 else if(has_prefix(argv_i, os+"=")) // concatenated with "="
106 {
107 found=true;
108 set(os, argv_i.substr(os.size()+1));
109 }
110 }
111
112 // goto-bcc-only command line argument found
113 if(found)
114 continue;
115
116 // add to new_argv
118
119 // without argument; also store in cmdlinet
121 {
122 set(argv_i);
123 continue;
124 }
125
126 for(const char **o=bcc_options_with_argument;
127 *o!=nullptr && !found;
128 ++o)
129 {
130 std::string os(*o);
131
132 if(argv_i==os) // separated
133 {
134 found=true;
135 if(i!=argc-1)
136 {
137 set(argv_i, argv[i+1]);
138 add_arg(argv[i+1]);
139 ++i;
140 }
141 else
142 set(argv_i, "");
143 }
144 else if(has_prefix(argv_i, os))
145 {
146 found=true;
147 set(os, argv[i]+os.size());
148 }
149 }
150
151 if(!found)
152 {
153 // unrecognized option
154 std::cerr << "Warning: uninterpreted bcc option '" << argv_i
155 << "'\n";
156 }
157 }
158
159 return false;
160}
const char * goto_bcc_options_with_argument[]
const char * bcc_options_with_argument[]
const char * bcc_options_without_argument[]
A special command line object for Bruce's C Compiler Author: Michael Tautschnig Date: July 2016.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:564
virtual bool parse(int, const char **)
void set(const std::string &opt, const char *value) override
Set option option to value.
void add_infile_arg(const std::string &arg)
static bool in_list(const char *option, const char **list)
void add_arg(const std::string &arg)
bool has_prefix(const std::string &s, const std::string &prefix)
Definition converter.cpp:13