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