CBMC
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#ifndef CPROVER_UTIL_CONFIG_H
10#define CPROVER_UTIL_CONFIG_H
11
12#include "ieee_float.h"
13#include "irep.h"
14
15#include <list>
16#include <optional>
17
18class cmdlinet;
20
21// Configt is the one place beyond *_parse_options where options are ... parsed.
22// Options that are handled by configt are documented here.
23
24#define OPT_CONFIG_C_CPP \
25 "D:I:(include)(function)" \
26 "(c89)(c99)(c11)(c17)(c23)(cpp98)(cpp03)(cpp11)" \
27 "(unsigned-char)" \
28 "(round-to-even)(round-to-nearest)" \
29 "(round-to-plus-inf)(round-to-minus-inf)(round-to-zero)" \
30 "(no-library)"
31
32#define HELP_CONFIG_C_CPP \
33 " {y-I} {upath} \t set include path (C/C++)\n" \
34 " {y--include} {ufile} \t set include file (C/C++)\n" \
35 " {y-D} {umacro} \t define preprocessor macro (C/C++)\n" \
36 " {y--c89}, {y--c99}, {y--c11},\n {y--c17}, {y--c23} \t " \
37 "set C language standard (default: " + \
38 std::string( \
39 configt::ansi_ct::default_c_standard() == \
40 configt::ansi_ct::c_standardt::C89 \
41 ? "c89" \
42 : configt::ansi_ct::default_c_standard() == \
43 configt::ansi_ct::c_standardt::C99 \
44 ? "c99" \
45 : configt::ansi_ct::default_c_standard() == \
46 configt::ansi_ct::c_standardt::C11 \
47 ? "c11" \
48 : configt::ansi_ct::default_c_standard() == \
49 configt::ansi_ct::c_standardt::C17 \
50 ? "c17" \
51 : configt::ansi_ct::default_c_standard() == \
52 configt::ansi_ct::c_standardt::C23 \
53 ? "c23" \
54 : "") + \
55 ")\n" \
56 " {y--cpp98}, {y--cpp03}, {y--cpp11} \t " \
57 "set C++ language standard (default: " + \
58 std::string( \
59 configt::cppt::default_cpp_standard() == \
60 configt::cppt::cpp_standardt::CPP98 \
61 ? "cpp98" \
62 : configt::cppt::default_cpp_standard() == \
63 configt::cppt::cpp_standardt::CPP03 \
64 ? "cpp03" \
65 : configt::cppt::default_cpp_standard() == \
66 configt::cppt::cpp_standardt::CPP11 \
67 ? "cpp11" \
68 : "") + \
69 ")\n" \
70 " {y--unsigned-char} \t make \"char\" unsigned by default\n" \
71 " {y--round-to-nearest}, {y--round-to-even} \t " \
72 "rounding towards nearest even (default)\n" \
73 " {y--round-to-plus-inf} \t rounding towards plus infinity\n" \
74 " {y--round-to-minus-inf} \t rounding towards minus infinity\n" \
75 " {y--round-to-zero} \t rounding towards zero\n" \
76 " {y--no-library} \t disable built-in abstract C library\n"
77
78#define OPT_CONFIG_LIBRARY \
79 "(malloc-fail-assert)(malloc-fail-null)(malloc-may-fail)" \
80 "(no-malloc-may-fail)" \
81 "(string-abstraction)" \
82 "(dfcc-debug-lib)" \
83 "(dfcc-simple-invalid-pointer-model)"
84
85#define HELP_CONFIG_LIBRARY \
86 " {y--malloc-may-fail} \t allow malloc calls to return a null pointer\n" \
87 " {y--no-malloc-may-fail} \t disable potential malloc failure\n" \
88 " {y--malloc-fail-assert} \t " \
89 "set malloc failure mode to assert-then-assume\n" \
90 " {y--malloc-fail-null} \t set malloc failure mode to return null\n" \
91 " {y--string-abstraction} \t track C string lengths and zero-termination\n" \
92 " {y--dfcc-debug-lib} \t enable debug assertions in the cprover contracts " \
93 "library\n" \
94 " {y--dfcc-simple-invalid-pointer-model} \t use simplified invalid pointer " \
95 "model in the cprover contracts library (faster, unsound)\n"
96
97#define OPT_CONFIG_JAVA "(classpath)(cp)(main-class)"
98
99#define OPT_CONFIG_PLATFORM \
100 "(arch):(os):" \
101 "(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \
102 "(little-endian)(big-endian)" \
103 "(i386-linux)" \
104 "(i386-win32)(win32)(winx64)" \
105 "(i386-macos)(ppc-macos)" \
106 "(gcc)"
107
108#define HELP_CONFIG_PLATFORM \
109 " {y--arch} {uarch_name} \t " \
110 "set architecture (default: " + \
111 id2string(configt::this_architecture()) + \
112 ") to one of: {yalpha}, {yarm}, {yarm64}, {yarmel}, {yarmhf}, {yhppa}, " \
113 "{yi386}, {yia64}, {ymips}, {ymips64}, {ymips64el}, {ymipsel}, " \
114 "{ymipsn32}, " \
115 "{ymipsn32el}, {ypowerpc}, {yppc64}, {yppc64le}, {yriscv64}, {ys390}, " \
116 "{ys390x}, {ysh4}, {ysparc}, {ysparc64}, {yv850}, {yx32}, {yx86_64}, or " \
117 "{ynone}\n" \
118 " {y--os} {uos_name} \t " \
119 "set operating system (default: " + \
120 id2string(configt::this_operating_system()) + \
121 ") to one of: {yfreebsd}, {ylinux}, {ymacos}, {ynetbsd}, {yopenbsd}, " \
122 "{ysolaris}, {yhurd}, or {ywindows}\n" \
123 " {y--i386-linux}, {y--i386-win32}, {y--i386-macos}, {y--ppc-macos}, " \
124 "{y--win32}, {y--winx64} \t " \
125 "set architecture and operating system\n" \
126 " {y--LP64}, {y--ILP64}, {y--LLP64}, {y--ILP32}, {y--LP32} \t " \
127 "set width of int, long and pointers, but don't override default " \
128 "architecture and operating system\n" \
129 " {y--16}, {y--32}, {y--64} \t " \
130 "equivalent to {y--LP32}, {y--ILP32}, {y--LP64} (on Windows: " \
131 "{y--LLP64})\n" \
132 " {y--little-endian} \t allow little-endian word-byte conversions\n" \
133 " {y--big-endian} \t allow big-endian word-byte conversions\n" \
134 " {y--gcc} \t use GCC as preprocessor\n"
135
136#define OPT_CONFIG_BACKEND "(object-bits):"
137
138#define HELP_CONFIG_BACKEND \
139 " {y--object-bits} {un} \t number of bits used for object addresses\n"
140
144{
145public:
146 struct ansi_ct
147 {
148 // for ANSI-C
149 std::size_t int_width;
150 std::size_t long_int_width;
151 std::size_t bool_width;
152 std::size_t char_width;
153 std::size_t short_int_width;
155 std::size_t pointer_width;
156 std::size_t single_width;
157 std::size_t double_width;
158 std::size_t long_double_width;
159 std::size_t wchar_t_width;
160
161 // various language options
164 bool ts_18661_3_Floatn_types; // ISO/IEC TS 18661-3:2015
165 bool gcc__float128_type; // __float128, a gcc extension since 4.3/4.5
166 bool __float128_is_keyword; // __float128 as a keyword (and not typedef)
167 bool float16_type; // _Float16 (Clang >= 15, GCC >= 12)
168 bool bf16_type; // __bf16 (Clang >= 15, GCC >= 13)
169 bool fp16_type; // __fp16 (GCC >= 4.5 on ARM, Clang >= 6)
171 bool allow_anonymous_struct_embedding; // -fms-extensions (partial)
172 enum class c_standardt
173 {
174 C89,
175 C99,
176 C11,
177 C17,
178 C23
181
182 void set_c89()
183 {
185 for_has_scope = false;
186 }
187 void set_c99()
188 {
190 for_has_scope = true;
191 }
192 void set_c11()
193 {
195 for_has_scope = true;
196 }
197 void set_c17()
198 {
200 for_has_scope = true;
201 }
202 void set_c23()
203 {
205 for_has_scope = true;
206 }
207
209
210 void set_16();
211 void set_32();
212 void set_64();
213
214 // http://www.unix.org/version2/whatsnew/lp64_wp.html
215 void set_LP64(); // int=32, long=64, pointer=64
216 void set_ILP64(); // int=64, long=64, pointer=64
217 void set_LLP64(); // int=32, long=32, pointer=64
218 void set_ILP32(); // int=32, long=32, pointer=32
219 void set_LP32(); // int=16, long=32, pointer=32
220
221 // minimum alignment (in structs) measured in bytes
222 std::size_t alignment;
223
224 // maximum minimum size of the operands for a machine
225 // instruction (in bytes)
227
228 enum class endiannesst
229 {
233 };
235
236 // Order in which compilers evaluate the arguments of a function call.
237 // The C and C++ standards leave this order unspecified, but any given
238 // compiler/architecture combination uses a fixed order, which is
239 // observable when argument expressions have side effects. Empirically
240 // confirmed (test programs on native and cross-compiled targets, and
241 // via Compiler Explorer): GCC evaluates right-to-left on the x86 family
242 // (i386, x86_64, x32) and left-to-right on all other architectures
243 // tested (arm64, arm, riscv64, ppc64le, mips64el, s390x, sparc64);
244 // Visual Studio evaluates right-to-left on all architectures tested
245 // (x86, x64, arm64); Clang evaluates left-to-right on all architectures
246 // tested (x86_64, arm64).
253
254 // whether the architecture set via one of the set_arch_spec_* functions
255 // is a member of the x86 family (i386, x86_64, x32); used to compute
256 // argument_evaluation_order, including when the compiler flavour changes
257 // after the architecture has been configured
258 bool arch_is_x86_family = false;
259
261
262 enum class ost
263 {
264 NO_OS,
265 OS_LINUX,
266 OS_MACOS,
267 OS_WIN
268 };
270
271 static std::string os_to_string(ost);
272 static ost string_to_os(const std::string &);
273
275
276 // architecture-specific integer value of null pointer constant
278
279 void set_arch_spec_i386();
283 void set_arch_spec_alpha();
286 void set_arch_spec_s390();
287 void set_arch_spec_s390x();
289 void set_arch_spec_ia64();
290 void set_arch_spec_x32();
291 void set_arch_spec_v850();
292 void set_arch_spec_hppa();
293 void set_arch_spec_sh4();
296
297 enum class flavourt
298 {
299 NONE,
300 ANSI,
301 GCC,
302 ARM,
303 CLANG,
306 };
307 flavourt mode; // the syntax of source files
308
309 enum class preprocessort
310 {
311 NONE,
312 GCC,
313 CLANG,
316 ARM
317 };
318 preprocessort preprocessor; // the preprocessor to use
319
320 std::list<std::string> defines;
321 std::list<std::string> undefines;
322 std::list<std::string> preprocessor_options;
323 std::list<std::string> include_paths;
324 std::list<std::string> include_files;
325
326 enum class libt
327 {
328 LIB_NONE,
330 };
332
334 bool malloc_may_fail = true;
335
337 bool dfcc_debug_lib = false;
338
341
348
350
351 static const std::size_t default_object_bits = 8;
352
356 std::optional<mp_integer> max_argc;
358
359 struct cppt
360 {
361 enum class cpp_standardt
362 {
363 CPP98,
364 CPP03,
365 CPP11,
366 CPP14,
367 CPP17
370
372 {
374 }
376 {
378 }
380 {
382 }
384 {
386 }
388 {
390 }
391
392 static const std::size_t default_object_bits = 8;
394
395 struct verilogt
396 {
397 std::list<std::string> include_paths;
399
400 struct javat
401 {
402 typedef std::list<std::string> classpatht;
405
406 static const std::size_t default_object_bits = 16;
408
410 {
411 // number of bits to encode heap object addresses
412 std::size_t object_bits = 8;
415
416 // this is the function to start executing
417 std::optional<std::string> main;
418
419 void set_arch(const irep_idt &);
420
422
423 bool set(const cmdlinet &cmdline);
424
426 std::string object_bits_info();
428
431
432private:
433 void set_classpath(const std::string &cp);
434};
435
436extern configt config;
437
438#endif // CPROVER_UTIL_CONFIG_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
Globally accessible architectural configuration.
Definition config.h:144
void set_object_bits_from_symbol_table(const symbol_table_baset &)
Sets the number of bits used for object addresses.
Definition config.cpp:1494
void set_arch(const irep_idt &)
Definition config.cpp:816
struct configt::bv_encodingt bv_encoding
bool set(const cmdlinet &cmdline)
Definition config.cpp:918
struct configt::verilogt verilog
std::string object_bits_info()
Definition config.cpp:1519
void set_classpath(const std::string &cp)
Definition config.cpp:1618
mp_integer max_malloc_size() const
The maximum allocation size is determined by the number of bits that are left in the pointer of width...
Definition config.cpp:1675
void set_from_symbol_table(const symbol_table_baset &)
Definition config.cpp:1419
static irep_idt this_architecture()
Definition config.cpp:1530
std::optional< std::string > main
Definition config.h:417
struct configt::javat java
struct configt::cppt cpp
static irep_idt this_operating_system()
Definition config.cpp:1634
struct configt::ansi_ct ansi_c
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
The symbol table base class interface.
configt config
Definition config.cpp:25
std::size_t long_double_width
Definition config.h:158
std::list< std::string > include_paths
Definition config.h:323
bool for_has_scope
Definition config.h:163
void set_arch_spec_x32()
Definition config.cpp:601
enum configt::ansi_ct::c_standardt c_standard
void set_arch_spec_riscv64()
Definition config.cpp:437
void set_c23()
Definition config.h:202
endiannesst endianness
Definition config.h:234
bool float16_type
Definition config.h:167
void set_arch_spec_sh4()
Definition config.cpp:695
void set_arch_spec_loongarch64()
Definition config.cpp:727
void set_ILP32()
int=32, long=32, pointer=32
Definition config.cpp:111
bool ts_18661_3_Floatn_types
Definition config.h:164
void set_arch_spec_v850()
Sets up the widths of variables for the Renesas V850.
Definition config.cpp:639
bool wchar_t_is_unsigned
Definition config.h:162
argument_evaluation_ordert argument_evaluation_order
Definition config.h:252
void set_arch_spec_hppa()
Definition config.cpp:664
static std::string os_to_string(ost)
Definition config.cpp:1340
bool arch_is_x86_family
Definition config.h:258
std::size_t pointer_width
Definition config.h:155
bool gcc__float128_type
Definition config.h:165
std::optional< mp_integer > max_argc
Maximum value of argc, which is operating-systems dependent: Windows limits the number of characters ...
Definition config.h:356
void set_c89()
Definition config.h:182
std::list< std::string > include_files
Definition config.h:324
void set_ILP64()
int=64, long=64, pointer=64
Definition config.cpp:71
irep_idt arch
Definition config.h:274
std::list< std::string > undefines
Definition config.h:321
ieee_floatt::rounding_modet rounding_mode
Definition config.h:208
bool __float128_is_keyword
Definition config.h:166
std::list< std::string > preprocessor_options
Definition config.h:322
void set_arch_spec_sparc(const irep_idt &subarch)
Definition config.cpp:526
static ost string_to_os(const std::string &)
Definition config.cpp:1355
std::list< std::string > defines
Definition config.h:320
void set_c99()
Definition config.h:187
void set_argument_evaluation_order()
Sets the architectural parameter recording the order in which compilers evaluate the arguments of a f...
Definition config.cpp:157
bool single_precision_constant
Definition config.h:170
bool allow_anonymous_struct_embedding
Definition config.h:171
void set_LLP64()
int=32, long=32, pointer=64
Definition config.cpp:91
void set_arch_spec_arm(const irep_idt &subarch)
Definition config.cpp:306
std::size_t wchar_t_width
Definition config.h:159
bool simple_invalid_pointer_model
use simplified invalid pointer model in cprover_contracts library
Definition config.h:340
preprocessort preprocessor
Definition config.h:318
@ malloc_failure_mode_return_null
Definition config.h:345
@ malloc_failure_mode_none
Definition config.h:344
@ malloc_failure_mode_assert_then_assume
Definition config.h:346
bool dfcc_debug_lib
enable debug code in cprover_contracts library
Definition config.h:337
std::size_t double_width
Definition config.h:157
bool malloc_may_fail
Definition config.h:334
bool char_is_unsigned
Definition config.h:162
static c_standardt default_c_standard()
Definition config.cpp:789
void set_arch_spec_alpha()
Definition config.cpp:354
void set_c17()
Definition config.h:197
std::size_t alignment
Definition config.h:222
void set_arch_spec_power(const irep_idt &subarch)
Definition config.cpp:243
std::size_t bool_width
Definition config.h:151
bool string_abstraction
Definition config.h:333
void set_arch_spec_s390()
Definition config.cpp:465
void set_LP64()
int=32, long=64, pointer=64
Definition config.cpp:47
void set_arch_spec_x86_64()
Definition config.cpp:203
void set_LP32()
int=16, long=32, pointer=32
Definition config.cpp:131
std::size_t memory_operand_size
Definition config.h:226
std::size_t long_long_int_width
Definition config.h:154
void set_arch_spec_s390x()
Definition config.cpp:496
bool NULL_is_zero
Definition config.h:277
std::size_t long_int_width
Definition config.h:150
void set_arch_spec_mips(const irep_idt &subarch)
Definition config.cpp:385
std::size_t single_width
Definition config.h:156
void set_arch_spec_i386()
Definition config.cpp:169
std::size_t short_int_width
Definition config.h:153
std::size_t char_width
Definition config.h:152
void set_c11()
Definition config.h:192
static const std::size_t default_object_bits
Definition config.h:351
flavourt mode
Definition config.h:307
std::size_t int_width
Definition config.h:149
malloc_failure_modet malloc_failure_mode
Definition config.h:349
void set_arch_spec_ia64()
Definition config.cpp:568
void set_arch_spec_emscripten()
Definition config.cpp:758
bool is_object_bits_default
Definition config.h:413
std::size_t object_bits
Definition config.h:412
void set_cpp14()
Definition config.h:383
enum configt::cppt::cpp_standardt cpp_standard
void set_cpp11()
Definition config.h:379
static const std::size_t default_object_bits
Definition config.h:392
void set_cpp17()
Definition config.h:387
void set_cpp03()
Definition config.h:375
static cpp_standardt default_cpp_standard()
Definition config.cpp:804
void set_cpp98()
Definition config.h:371
classpatht classpath
Definition config.h:403
std::list< std::string > classpatht
Definition config.h:402
irep_idt main_class
Definition config.h:404
static const std::size_t default_object_bits
Definition config.h:406
std::list< std::string > include_paths
Definition config.h:397