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