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