cprover
armcc_cmdline.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: A special command line object to mimic ARM's armcc
4 
5 Author: Daniel Kroening
6 
7 \*******************************************************************/
8 
11 
12 #include "armcc_cmdline.h"
13 
14 #include <util/optional.h>
15 #include <util/prefix.h>
16 
17 #include <algorithm>
18 #include <cstring>
19 #include <iostream>
20 #include <string>
21 #include <vector>
22 
26 // see
27 // http://infocenter.arm.com/help/topic/com.arm.doc.dui0472c/Cchbggjb.html
28 
29 static const char *options_no_arg[]=
30 {
31  // goto-cc-specific
32  "--show-symbol-table",
33  "--show-function-table",
34  "--16",
35  "--32",
36  "--64",
37  "--little-endian",
38  "--big-endian",
39  "--unsigned-char",
40  "--ppc-macos",
41  "--i386-macos",
42  "--i386-linux",
43  "--i386-win32",
44  "--no-arch",
45  "--no-library",
46  "--string-abstraction",
47 
48  // armcc
49  "--help",
50  "--show_cmdline",
51  "--version_number",
52  "--vsn",
53  "--c90",
54  "--c99",
55  "--compile_all_input",
56  "--no_compile_all_input",
57  "--cpp",
58  "--gnu",
59  "--strict",
60  "--no_strict",
61  "--strict_warnings",
62  "--kandr_include",
63  "--reduce_paths",
64  "--no_reduce_paths",
65  "--sys_include",
66  "--no-project",
67  "--reinitialize_workdir",
68  "--pch",
69  "--pch_messages",
70  "--no_pch_messages",
71  "--pch_verbose",
72  "--no_pch_verbose",
73  "-C",
74  "--code_gen",
75  "--no_code_gen",
76  "-E",
77  "-M",
78  "--anachronisms",
79  "--no_anachronisms",
80  "--dep_name",
81  "--no_dep_name",
82  "--export_all_vtbl",
83  "--no_export_all_vtbl",
84  "--force_new_nothrow",
85  "--no_force_new_nothrow",
86  "--friend_injection",
87  "--no_friend_injection",
88  "--guiding_decls",
89  "--no_guiding_decls",
90  "--implicit_include",
91  "--no_implicit_include",
92  "--implicit_include_searches",
93  "--no_implicit_include_searches",
94  "--implicit_typename",
95  "--no_implicit_typename",
96  "--nonstd_qualifier_deduction",
97  "--no_nonstd_qualifier_deduction",
98  "--old_specializations",
99  "--no_old_specializations",
100  "--parse_templates",
101  "--no_parse_templates",
102  "--rtti",
103  "--no_rtti",
104  "--using_std",
105  "--no_using_std",
106  "--vfe",
107  "--no_vf",
108  "--asm",
109  "-c",
110  "--depend_system_headers",
111  "--no_depend_system_headers",
112  "--interleave",
113  "--list",
114  "--md",
115  "-S",
116  "--split_sections",
117  "--arm",
118  "--thumb",
119  "--debug",
120  "--no_debug",
121  "--debug_macros",
122  "--no_debug_macros",
123  "--dwarf2",
124  "--dwarf3",
125  "-g",
126  "--remove_unneeded_entities",
127  "--no_remove_unneeded_entities",
128  "--alternative_tokens",
129  "--no_alternative_tokens",
130  "--bigend",
131  "--dllexpot_all",
132  "--no_dllexpot_all",
133  "--dollar",
134  "--no_dollar",
135  "--enum_is_int",
136  "--exceptions",
137  "--no_exceptions",
138  "--exceptions_unwind",
139  "--no_exceptions_unwind",
140  "--export_all_vtbl",
141  "--no_export_all_vtbl",
142  "--export_defs_implicitly",
143  "--no_export_defs_implicitly",
144  "--extend_initializers",
145  "--no_extend_initializers",
146  "--hide_all",
147  "--no_hide_all",
148  "--littleend",
149  "--loose_implicit_cast",
150  "--multibyte_chars",
151  "--no_multibyte_chars",
152  "--narrow_volatile_bitfields",
153  "--restrict",
154  "--no_restrict",
155  "--signed_bitfields",
156  "--unsigned_bitfields",
157  "--signed_chars",
158  "--unsigned_chars",
159  "--split_ldm",
160  "--unaligned_access",
161  "--no_unaligned_access",
162  "--vectorize",
163  "--no_vectorize",
164  "--vla",
165  "--no_vla",
166  "--wchar16",
167  "--wchar32",
168  "--autoinline",
169  "--no_autoinline",
170  "--data_reorder",
171  "--no_data_reorder",
172  "--forceinline",
173  "--inline",
174  "--no_inline",
175  "--lower_ropi",
176  "--no_lower_ropi",
177  "--lower_rwpi",
178  "--no_lower_rwpi",
179  "--ltcg",
180  "--multifile",
181  "--no_multifile",
182  "-Ospace",
183  "-Otime",
184  "-O1",
185  "-O2",
186  "-O3",
187  "-O4",
188  "--brief_diagnostics",
189  "--no_brief_diagnostics",
190  "--remarks",
191  "--wrap_diagnostics",
192  "--no_wrap_diagnostics",
193  "--arm_linux",
194  "--arm_linux_configure",
195  "--arm_linux_paths",
196  "--shared",
197  "--translate_g++",
198  "--translate_gcc",
199  "--translate_gld",
200  "-W",
201  nullptr
202 };
203 
204 // clang-format off
205 static const std::vector<std::string> options_with_prefix
206 {
207  "--project=",
208  "--workdir=",
209  "--create_pch=",
210  "--pch_dir=",
211  "--use_pch=",
212  "--pending_instantiations=",
213  "--errors=",
214  "--default_extension=",
215  "--depend=",
216  "--depend_format=",
217  "--info=",
218  "--compatible=",
219  "--entry=",
220  "--scatter=",
221  "--fpu=",
222  "--fp16_format=",
223  "--fpmode=",
224  "--fpu=",
225  "--bss_threshold=",
226  "--keep=",
227  "--locale=",
228  "--message_locale=",
229  "--min_array_alignment=",
230  "--pointer_alignment=",
231  "--fpmode=",
232  "--library_interface=",
233  "--library_type=",
234  "--retain=",
235  "--diag_error=",
236  "--diag_remark=",
237  "--diag_style=",
238  "--diag_suppress=",
239  "--diag_warning=",
240  "--preinclude=",
241  "--via=",
242  "--feedback=",
243  "--profile=",
244  "--apcs=",
245  "--arm_linux_config_file=",
246  "--configure_gcc=",
247  "--configure_gld=",
248  "--configure_sysroot=",
249  "--configure_cpp_headers=",
250  "--configure_extra_includes=",
251  "--configure_extra_libraries="
252 };
253 
254 static const std::vector<std::string> options_with_arg
255 {
256  // goto-cc specific
257  "--verbosity",
258  "--function",
259 
260  // armcc-specific
261  "-D",
262  "-U",
263  "-A",
264  "-L",
265  "-I",
266  "-J",
267  "-Warmcc,",
268  "-o",
269  "--cpu",
270  "--apcs"
271 };
272 // clang-format on
273 
275 prefix_in_list(const std::string &option, const std::vector<std::string> &list)
276 {
277  const auto found =
278  std::find_if(list.cbegin(), list.cend(), [&](const std::string &argument) {
279  return has_prefix(argument, option);
280  });
281  if(found == list.cend())
282  return {};
283  return {*found};
284 }
285 
286 bool armcc_cmdlinet::parse(int argc, const char **argv)
287 {
288  for(int i=1; i<argc; i++)
289  {
290  if(strcmp(argv[i], "-")==0 ||
291  argv[i][0]!='-')
292  {
293  args.push_back(argv[i]);
294  continue;
295  }
296 
297  // it starts with - and it isn't "-"
298  optionalt<std::string> prefix;
299 
300  if(in_list(argv[i], options_no_arg))
301  {
302  // options that don't have any arguments
303  set(argv[i]);
304  }
305  else if((prefix = prefix_in_list(argv[i], options_with_arg)))
306  {
307  // options that have a separated _or_ concatenated argument
308  if(strlen(argv[i]) > prefix->size()) // Concatenated.
309  set(*prefix, std::string(argv[i], prefix->size(), std::string::npos));
310  else
311  {
312  // Separated.
313  if(i!=argc-1) // Guard against end of command line.
314  {
315  set(*prefix, argv[i + 1]);
316  i++;
317  }
318  else
319  set(*prefix, "");
320  }
321  }
322  else if((prefix = prefix_in_list(argv[i], options_with_prefix)))
323  {
324  // options that have a concatenated argument
325  set(*prefix, std::string(argv[i], prefix->size(), std::string::npos));
326  }
327  else
328  { // unrecognized option
329  std::cout << "Warning: uninterpreted armcc option '"
330  << argv[i] << "'\n";
331  }
332  }
333 
334  return false;
335 }
cmdlinet::args
argst args
Definition: cmdline.h:91
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_in_list
optionalt< std::string > prefix_in_list(const std::string &option, const std::vector< std::string > &list)
Definition: armcc_cmdline.cpp:275
optional.h
prefix.h
options_with_arg
static const std::vector< std::string > options_with_arg
Definition: armcc_cmdline.cpp:255
optionalt
nonstd::optional< T > optionalt
Definition: optional.h:35
goto_cc_cmdlinet::parse
virtual bool parse(int argc, const char **argv, const char *optstring)
Definition: cmdline.cpp:154
options_with_prefix
static const std::vector< std::string > options_with_prefix
Definition: armcc_cmdline.cpp:206
armcc_cmdline.h
A special command line object to mimic ARM's armcc.
options_no_arg
static const char * options_no_arg[]
parses the command line options into a cmdlinet
Definition: armcc_cmdline.cpp:29
goto_cc_cmdlinet::in_list
static bool in_list(const char *option, const char **list)
Definition: goto_cc_cmdline.cpp:39