1 // -*- mode: C++ -*-
2 //
3 // Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 The University of Utah
4 // All rights reserved.
5 //
6 // This file is part of `csmith', a random generator of C programs.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // * Redistributions of source code must retain the above copyright notice,
12 // this list of conditions and the following disclaimer.
13 //
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
29
30 //
31 // This file was derived from a random program generator written by Bryan
32 // Turner. The attributions in that file was:
33 //
34 // Random Program Generator
35 // Bryan Turner (bryan.turner@pobox.com)
36 // July, 2005
37 //
38 // Contributions and bug fixes by:
39 // Jan-2007 : Mat Hostetter - Explicit "return 0" for main()
40 //
41
42 /*
43 Random C/C++ Program Generator
44 ------------------------------
45 1) Create a set of random types to be used throughout the program
46 2) Create the main func.
47 3) Generate a random block of statements with maximum control & expression nesting depths.
48 4) If new functions were defined in #3, then loop back to fill in its body.
49 5) When a maximum number of functions is reached, stop generating new functions and finish off the bodies of the remaining funcs.
50 6) Output generated program.
51
52 GOALS:
53 - Locate basic errors in compiler front-ends (crashes, etc).
54 - Ferret out correctness errors in optimization passes.
55 - Support the design of tools to search for improved optimization paths (partial exection, etc).
56
57 TODO:
58 - Protect back links with a global DEPTH, don't call if DEPTH is too high (avoid infinite recursion)
59 - Main function generates hash of global state as output of program - use to locate optimization errors.
60 - Compile in Debug mode vs. Optimized mode, compare hash value at program termination.
61 - Improve hash function; use stronger hashing (ARCFOUR) and perform hashing at random points in the graph.
62 - Output only after successful program termination.
63
64 FUTURE:
65 - Complex types
66 - Type-correct expressions
67 - Some substitutions allowed
68 - int, char, short, long, float, double - all interchangeable to some degree (use appropriate casts)
69 - array <--> pointer
70 - pointer promotion (ie: passing the pointer to a local var, or droping the pointer to pass by value)
71 - Memory Allocation & Manipulation?
72 - Choose random functions to perform allocations
73 - Choose random children/ancestors to perform deallocations
74 - Work from leaves to root
75 - If node uses pointer or array, it is potential heap store allocated.
76 */
77
78 #if HAVE_CONFIG_H
79 # include <config.h>
80 #endif
81
82 #ifdef WIN32
83 #pragma warning(disable : 4786) /* Disable annoying warning messages */
84 #endif
85
86 #include <ostream>
87 #include <fstream>
88 #include <cstring>
89 #include <cstdio>
90
91 #include "Common.h"
92
93 #include "CGOptions.h"
94 #include "AbsProgramGenerator.h"
95
96 #include "git_version.h"
97 #include "platform.h"
98 #include "random.h"
99
100 using namespace std;
101
102 //#define PACKAGE_STRING "csmith 1.1.1"
103 ///////////////////////////////////////////////////////////////////////////////
104
105 // ----------------------------------------------------------------------------
106 // Globals
107
108 // Program seed - allow user to regenerate the same program on different
109 // platforms.
110 static unsigned long g_Seed = 0;
111
112 // ----------------------------------------------------------------------------
113 static void
print_version(void)114 print_version(void)
115 {
116 cout << PACKAGE_STRING << endl;
117 cout << "Git version: " << git_version << endl;
118 // XXX print copyright, contact info, etc.?
119 }
120
121 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
parse_string_arg(const char * arg,string & s)123 bool parse_string_arg(const char *arg, string &s)
124 {
125 s.assign(arg);
126 return ((!s.empty()) &&
127 (s.compare(0, 2, "--")));
128 }
129
130 static bool
parse_int_arg(char * arg,unsigned long * ret)131 parse_int_arg(char *arg, unsigned long *ret)
132 {
133 int res;
134 res = sscanf (arg, "%lu", ret);
135
136 if (res == 0) {
137 cout << "expected integer at arg position " << endl;
138 return false;
139 }
140 return true;
141 }
142
print_help()143 static void print_help()
144 {
145 cout << "Command line options: " << endl << endl;
146 // most common options
147 cout << " --help or -h: print this information." << endl << endl;
148 cout << " -hh: describe extra options probably useful only for Csmith developers." << endl << endl;
149 cout << " --version or -v: print the version of Csmith." << endl << endl;
150 cout << " --seed <seed> or -s <seed>: use <seed> instead of a random seed generated by Csmith." << endl << endl;
151 cout << " --output <filename> or -o <filename>: specify the output file name." << endl << endl;
152
153 // enabling/disabling options
154 cout << " --argc | --no-argc: genereate main function with/without argv and argc being passed (enabled by default)." << endl << endl;
155 cout << " --arrays | --no-arrays: enable | disable arrays (enabled by default)." << endl << endl;
156 cout << " --bitfields | --no-bitfields: enable | disable full-bitfields structs (enabled by default)." << endl << endl;
157 cout << " --checksum | --no-checksum: enable | disable checksum calculation (enabled by default)." << endl << endl;
158 cout << " --comma-operators | --no-comma-operators: enable | disable comma operators (enabled by default)." << endl << endl;
159 cout << " --compound-assignment | --no-compound-assignment: enable | disable compound assignments (enabled by default)." << endl << endl;
160 cout << " --concise: generated programs with minimal comments (disabled by default)." << endl << endl;
161 cout << " --consts | --no-consts: enable | disable const qualifier (enabled by default)." << endl << endl;
162 cout << " --divs | --no-divs: enable | disable divisions (enabled by default)." << endl << endl;
163 cout << " --embedded-assigns | --no-embedded-assigns: enable | disable embedded assignments as sub-expressions (enabled by default)." << endl << endl;
164 cout << " --pre-incr-operator | --no-pre-incr-operator: enable | disable pre ++ operator (enabled by default)." << endl << endl;
165 cout << " --pre-decr-operator | --no-pre-decr-operator: enable | disable pre -- operator (enabled by default)." << endl << endl;
166 cout << " --post-incr-operator | --no-post-incr-operator: enable | disable post ++ operator (enabled by default)." << endl << endl;
167 cout << " --post-decr-operator | --no-post-decr-operator: enable | disable post -- operator (enabled by default)." << endl << endl;
168 cout << " --unary-plus-operator | --no-unary-plus-operator: enable | disable + operator (enabled by default)." << endl << endl;
169 cout << " --jumps | --no-jumps: enable | disable jumps (enabled by default)." << endl << endl;
170 cout << " --longlong| --no-longlong: enable | disable long long (enabled by default)." << endl << endl;
171 cout << " --int8 | --no-int8: enable | disable int8_t (enabled by default)." << endl << endl;
172 cout << " --uint8 | --no-uint8: enable | disable uint8_t (enabled by default)." << endl << endl;
173 cout << " --float | --no-float: enable | disable float (disabled by default)." << endl << endl;
174 cout << " --main | --nomain: enable | disable to generate main function (enabled by default)." << endl << endl;
175 cout << " --math64 | --no-math64: enable | disable 64-bit math ops (enabled by default)." << endl << endl;
176 cout << " --inline-function | --no-inline-function: enable | disable inline attributes on generated functions." << endl << endl;
177 cout << " --inline-function-prob <num>: set the probability of each function being marked as inline (default is 50)." << endl << endl;
178
179 // numbered controls
180 cout << " --max-array-dim <num>: limit array dimensions to <num>. (default 3)" << endl << endl;
181 cout << " --max-array-len-per-dim <num>: limit array length per dimension to <num> (default 10)." << endl << endl;
182 cout << " --max-block-depth <num>: limit depth of nested blocks to <num> (default 5)." << endl << endl;
183 cout << " --max-block-size <size>: limit the number of non-return statements in a block to <size> (default 4)." << endl << endl;
184 cout << " --max-expr-complexity <num>: limit expression complexities to <num> (default 10)." << endl << endl;
185 cout << " --max-funcs <num>: limit the number of functions (besides main) to <num> (default 10)." << endl << endl;
186 cout << " --max-pointer-depth <depth>: limit the indirect depth of pointers to <depth> (default 2)." << endl << endl;
187 cout << " --max-struct-fields <num>: limit the number of struct fields to <num> (default 10). " << endl << endl;
188 cout << " --max-union-fields <num>: limit the number of union fields to <num> (default 5). " << endl << endl;
189
190 cout << " --muls | --no-muls: enable | disable multiplications (enabled by default)." << endl << endl;
191 cout << " --safe-math | --no-safe-math: Emit safe math wrapper functions (enabled by default)." << endl << endl;
192 cout << " --packed-struct | --no-packed-struct: enable | disable packed structs by adding #pragma pack(1) before struct definition (enabled by default)." << endl << endl;
193 cout << " --paranoid | --no-paranoid: enable | disable pointer-related assertions (disabled by default)." << endl << endl;
194 cout << " --pointers | --no-pointers: enable | disable pointers (enabled by default)." << endl << endl;
195 cout << " --quiet: generate programs with less comments (disabled by default)." << endl << endl;
196 cout << " --structs | --no-structs: enable | disable to generate structs (enable by default)." << endl << endl;
197 cout << " --unions | --no-unions: enable | disable to generate unions (enable by default)." << endl << endl;
198 cout << " --volatiles | --no-volatiles: enable | disable volatiles (enabled by default)." << endl << endl;
199 cout << " --volatile-pointers | --no-volatile-pointers: enable | disable volatile pointers (enabled by default)." << endl << endl;
200 cout << " --const-pointers | --no-const-pointers: enable | disable const pointers (enabled by default)." << endl << endl;
201 cout << " --global-variables | --no-global-variables: enable | disable global variables (enabled by default)." << endl << endl;
202
203 cout << " --builtins | --no-builtins: enable | disable to generate builtin functions (disabled by default)." << endl << endl;
204 cout << " --enable-builtin-kinds k1,k2 | --disable-builtin-kinds k1,k2: enable | disable certain kinds of builtin functions." << endl << endl;
205 cout << " --builtin-function-prob <num>: set the probability of choosing a builtin function (default is 20)." << endl << endl;
206
207 // language options
208 cout << " --lang-cpp : generate C++ code (C by default)." << endl << endl;
209 cout << " --cpp11 : generate C++11 code (C++03 by default). Works if lang-cpp is enabled." << endl << endl;
210
211 }
212
print_advanced_help()213 static void print_advanced_help()
214 {
215 cout << "'Advanced' command line options that are probably only useful for Csmith's" << endl;
216 cout << "original developers:" << endl << endl;
217 // file split options
218 cout << " --max-split-files <num>: evenly split a generated program into <num> different files(default 0)." << endl << endl;
219 cout << " --split-files-dir <dir>: generate split-files into <dir> (default ./output)." << endl << endl;
220
221 // dfs-exhaustive mode options
222 cout << " --dfs-exhaustive: enable depth first exhaustive random generation (disabled by default)." << endl << endl;
223 cout << " --expand-struct: enable the expansion of struct in the exhaustive mode. ";
224 cout << "Only works in the exhaustive mode and cannot used with --no-structs." << endl << endl;
225
226 cout << " --compact-output: print generated programs in compact way. ";
227 cout << "Only works in the exhaustive mode." << endl << endl;
228
229 cout << " --max-nested-struct-level <num>: limit maximum nested level of structs to <num>(default 0). ";
230 cout << "Only works in the exhaustive mode." << endl << endl;
231
232 cout << " --struct-output <file>: dump structs declarations to <file>. ";
233 cout << "Only works in the exhaustive mode." << endl << endl;
234
235 cout << " --prefix-name: prefix names of global functions and variables with increasing numbers. ";
236 cout << "Only works in the exhaustive mode." << endl << endl;
237
238 cout << " --sequence-name-prefix: prefix names of global functions and variables with sequence numbers.";
239 cout << "Only works in the exhaustive mode." << endl << endl;
240
241 cout << " --compatible-check: disallow trivial code such as i = i in random programs. ";
242 cout << "Only works in the exhaustive mode." << endl << endl;
243
244 // target platforms
245 cout << " --msp: enable certain msp related features " << endl << endl;
246 cout << " --ccomp: generate compcert-compatible code" << endl << endl;
247
248 // symblic excutions
249 cout << " --splat: enable splat extension" << endl << endl;
250 cout << " --klee: enable klee extension" << endl << endl;
251 cout << " --crest: enable crest extension" << endl << endl;
252
253 // coverage test options
254 cout << " --coverage-test: enable coverage-test extension" << endl << endl;
255 cout << " --coverage-test-size <num>: specify size (default 500) of the array generated to test coverage. ";
256 cout << "Can only be used with --coverage-test." << endl << endl;
257
258 cout << " --func1_max_params <num>: specify the number of symbolic variables passed to func_1 (default 3). ";
259 cout << "Only used when --splat | --crest | --klee | --coverage-test is enabled." << endl << endl;
260
261 // struct/union related options
262 cout << " --fixed-struct-fields: fix the size of struct fields to max-struct-fields (default 10)." << endl << endl;
263 cout << " --return-structs | --no-return-structs: enable | disable return structs from a function (enabled by default)." << endl << endl;
264 cout << " --arg-structs | --no-arg-structs: enable | disable structs being used as args (enabled by default)." << endl << endl;
265 cout << " --return-unions | --no-return-unions: enable | disable return unions from a function (enabled by default)." << endl << endl;
266 cout << " --arg-unions | --no-arg-unions: enable | disable unions being used as args (enabled by default)." << endl << endl;
267 cout << " --take-union-field-addr | --take-no-union-field-addr: allow | disallow addresses of union fields to be taken (allowed by default)." << endl << endl;
268 cout << " --vol-struct-union-fields | --no-vol-struct-union-fields: enable | disable volatile struct/union fields (enabled by default)" << endl << endl;
269 cout << " --const-struct-union-fields | --no-const-struct-union-fields: enable | disable const struct/union fields (enabled by default)" << endl << endl;
270
271 // delta related options
272 cout << " --delta-monitor [simple]: specify the type of delta monitor. Only [simple] type is supported now." << endl << endl;
273 cout << " --delta-input [file]: specify the file for delta input." << endl << endl;
274 cout << " --delta-output [file]: specify the file for delta output (default to <delta-input>)." << endl << endl;
275 cout << " --go-delta [simple]: run delta reduction on <delta-input>." << endl << endl;
276 cout << " --no-delta-reduction: output the same program as <delta-input>. ";
277 cout << "Only works with --go-delta option." << endl << endl;
278
279 // probability options
280 cout << " --dump-default-probabilities <file>: dump the default probability settings into <file>" << endl << endl;
281 cout << " --dump-random-probabilities <file>: dump the randomized probabilities into <file>" << endl << endl;
282 cout << " --probability-configuration <file>: use probability configuration <file>" << endl << endl;
283 cout << " --random-random: enable random probabilities." << endl << endl;
284
285 // volatile checking options
286 cout << " --enable-access-once: enable testing access once macro." << endl << endl;
287 cout << " --strict-volatile-rule: make sure only one volatile access between any pair of sequence points. " << endl << endl;
288
289 cout << " --addr-taken-of-locals: enable addr-taken of local vars. [default]" << endl << endl;
290 cout << " --no-addr-taken-of-locals: disable addr-taken of local vars. " << endl << endl;
291
292 cout << " --fresh-array-ctrl-var-names: create fresh names [i1,i2,i3...] for array control vars rather than use unique names such as i, j, k." << endl << endl;
293
294 // other options
295 cout << " --math-notmp: make csmith generate code for safe_math_macros_notmp." << endl << endl;
296
297 cout << " --strict-const-arrays: restrict array elements to constants." << endl << endl;
298
299 cout << " --partial-expand <assignment[,for[,block[,if-else[,invoke[,return]]]]]: ";
300 cout <<"partial-expand controls which what kind of statements should be generated first. ";
301 cout <<"For example, it could make Csmith start to generate if-else without go over assignment or for." << endl << endl;
302
303 cout << " --dangling-global-pointers | --no-dangling-global-pointers: enable | disable to reset all dangling global pointers to null at the end of main. (enabled by default)" << endl << endl;
304
305 cout << " --check-global: print the values of all integer global variables." << endl << endl;
306
307 cout << " --monitor-funcs <name1,name2...>: dump the checksums after each statement in the monitored functions." << endl << endl;
308
309 cout << " --step-hash-by-stmt: dump the checksum after each statement. It is applied to all functions unless --monitor-funcs is specified." << endl << endl;
310
311 cout << " --stop-by-stmt <num>: try to stop generating statements after the statement with id <num>." << endl << endl;
312
313 cout << " --const-as-condition: enable const to be conditions of if-statements. " << endl << endl;
314
315 cout << " --match-exact-qualifiers: match exact const/volatile qualifiers for LHS and RHS of assignments." << endl << endl;
316
317 cout << " --reduce <file>: reduce random program under the direction of the configuration file." << endl << endl;
318
319 cout << " --return-dead-pointer | --no-return-dead-pointer: allow | disallow functions from returning dangling pointers (disallowed by default)." << endl << endl;
320
321 cout << " --identify-wrappers: assign ids to used safe math wrappers." << endl << endl;
322
323 cout << " --safe-math-wrappers <id1,id2...>: specifiy ids of wrapper functions that are necessary to avoid undefined behaviors, use 0 to specify none." << endl << endl;
324
325 cout << " --mark-mutable-const: mark constants that can be mutated with parentheses (disabled by default)." << endl << endl;
326
327 cout << " --force-non-uniform-arrays | --no-force-non-uniform-arrays: force integer arrays to be initialized with multiple values (enabled by default)." << endl << endl;
328
329 cout << " --null-ptr-deref-prob <N>: allow null pointers to be dereferenced with probability N% (0 by default)." << endl << endl;
330
331 cout << " --dangling-ptr-deref-prob <N>: allow dangling pointers to be dereferenced with probability N% (0 by default)." << endl << endl;
332
333 cout << " --union-read-type-sensitive | --no-union-read-type-sensitive: allow | disallow reading an union field when there is no risk of "
334 << "reading padding bits (enabled by default)." << endl << endl;
335
336 cout << " --max-struct-nested-level: controls the max depth of nested structs (default is 3)." << endl << endl;
337 cout << " --no-hash-value-printf: do not emit printf on the index of an array" << endl << endl;
338 cout << " --no-signed-char-index: do not allow a var of type char to be used as array index" << endl << endl;
339 cout << " --strict-float: do not allow assignments between floats and integers" << endl << endl;
340 }
341
arg_check(int argc,int i)342 void arg_check(int argc, int i)
343 {
344 if (i >= argc) {
345 cout << "expect arg at pos " << i << std::endl;
346 exit(-1);
347 }
348 }
349
350 // ----------------------------------------------------------------------------
351 int
main(int argc,char ** argv)352 main(int argc, char **argv)
353 {
354 g_Seed = platform_gen_seed();
355
356 CGOptions::set_default_settings();
357
358 for (int i=1; i<argc; i++) {
359
360 if (strcmp (argv[i], "--help") == 0 ||
361 strcmp (argv[i], "-h") == 0) {
362 print_help();
363 return 0;
364 }
365
366 if (strcmp (argv[i], "-hh") == 0) {
367 print_advanced_help();
368 return 0;
369 }
370
371 if (strcmp (argv[i], "--version") == 0 ||
372 strcmp (argv[i], "-v") == 0) {
373 print_version();
374 return 0;
375 }
376
377 if (strcmp (argv[i], "--seed") == 0 ||
378 strcmp (argv[i], "-s") == 0) {
379 i++;
380 arg_check(argc, i);
381
382 if (!parse_int_arg(argv[i], &g_Seed))
383 exit(-1);
384 continue;
385 }
386
387 if (strcmp (argv[i], "--max-block-size") == 0) {
388 unsigned long size = 0;
389 i++;
390 arg_check(argc, i);
391 if (!parse_int_arg(argv[i], &size))
392 exit(-1);
393 CGOptions::max_block_size(size);
394 continue;
395 }
396
397 if (strcmp (argv[i], "--max-funcs") == 0) {
398 unsigned long size = 0;
399 i++;
400 arg_check(argc, i);
401 if (!parse_int_arg(argv[i], &size))
402 exit(-1);
403 CGOptions::max_funcs(size);
404 continue;
405 }
406
407 if (strcmp (argv[i], "--func1_max_params") == 0) {
408 unsigned long num = 0;
409 i++;
410 arg_check(argc, i);
411 if (!parse_int_arg(argv[i], &num))
412 exit(-1);
413 CGOptions::func1_max_params(num);
414 continue;
415 }
416
417 if (strcmp (argv[i], "--splat") == 0) {
418 CGOptions::splat(true);
419 continue;
420 }
421
422 if (strcmp (argv[i], "--klee") == 0) {
423 CGOptions::klee(true);
424 continue;
425 }
426
427 if (strcmp (argv[i], "--crest") == 0) {
428 CGOptions::crest(true);
429 continue;
430 }
431
432 if (strcmp (argv[i], "--ccomp") == 0) {
433 CGOptions::ccomp(true);
434 continue;
435 }
436
437 if (strcmp (argv[i], "--coverage-test") == 0) {
438 CGOptions::coverage_test(true);
439 continue;
440 }
441
442 if (strcmp (argv[i], "--coverage-test-size") == 0) {
443 unsigned long size = 0;
444 i++;
445 arg_check(argc, i);
446 if (!parse_int_arg(argv[i], &size))
447 exit(-1);
448 CGOptions::coverage_test_size(size);
449 continue;
450 }
451
452 if (strcmp (argv[i], "--max-split-files") == 0) {
453 unsigned long size = 0;
454 i++;
455 arg_check(argc, i);
456 if (!parse_int_arg(argv[i], &size))
457 exit(-1);
458 CGOptions::max_split_files(size);
459 continue;
460 }
461
462 if (strcmp (argv[i], "--split-files-dir") == 0) {
463 string dir;
464 i++;
465 arg_check(argc, i);
466 if (!parse_string_arg(argv[i], dir)) {
467 cout << "please specify <dir>" << std::endl;
468 exit(-1);
469 }
470 CGOptions::split_files_dir(dir);
471 continue;
472 }
473
474 if (strcmp (argv[i], "--dfs-exhaustive") == 0) {
475 CGOptions::dfs_exhaustive(true);
476 CGOptions::random_based(false);
477 continue;
478 }
479
480 if (strcmp (argv[i], "--compact-output") == 0) {
481 CGOptions::compact_output(true);
482 continue;
483 }
484
485 if (strcmp (argv[i], "--msp") == 0) {
486 CGOptions::msp(true);
487 continue;
488 }
489
490 if (strcmp (argv[i], "--packed-struct") == 0) {
491 CGOptions::packed_struct(true);
492 continue;
493 }
494
495 if (strcmp (argv[i], "--no-packed-struct") == 0) {
496 CGOptions::packed_struct(false);
497 continue;
498 }
499
500 if (strcmp (argv[i], "--bitfields") == 0) {
501 CGOptions::bitfields(true);
502 continue;
503 }
504
505 if (strcmp (argv[i], "--no-bitfields") == 0) {
506 CGOptions::bitfields(false);
507 continue;
508 }
509
510 if (strcmp (argv[i], "--prefix-name") == 0) {
511 CGOptions::prefix_name(true);
512 continue;
513 }
514
515 if (strcmp (argv[i], "--sequence-name-prefix") == 0) {
516 CGOptions::sequence_name_prefix(true);
517 continue;
518 }
519
520 if (strcmp (argv[i], "--compatible-check") == 0) {
521 CGOptions::compatible_check(true);
522 continue;
523 }
524
525 if (strcmp (argv[i], "--partial-expand") == 0) {
526 string s;
527 i++;
528 arg_check(argc, i);
529 if (!parse_string_arg(argv[i], s)) {
530 cout << "--partial-expand needs options" << std::endl;
531 exit(-1);
532 }
533 CGOptions::partial_expand(s);
534 continue;
535 }
536
537 if (strcmp (argv[i], "--paranoid") == 0) {
538 CGOptions::paranoid(true);
539 continue;
540 }
541 if (strcmp (argv[i], "--no-paranoid") == 0) {
542 CGOptions::paranoid(false);
543 continue;
544 }
545
546 if (strcmp (argv[i], "--quiet") == 0) {
547 CGOptions::quiet(true);
548 continue;
549 }
550
551 if (strcmp (argv[i], "--main") == 0) {
552 CGOptions::nomain(false);
553 continue;
554 }
555
556 if (strcmp (argv[i], "--nomain") == 0) {
557 CGOptions::nomain(true);
558 continue;
559 }
560
561 if (strcmp (argv[i], "--compound-assignment") == 0) {
562 CGOptions::compound_assignment(true);
563 continue;
564 }
565
566 if (strcmp (argv[i], "--no-compound-assignment") == 0) {
567 CGOptions::compound_assignment(false);
568 continue;
569 }
570
571 if (strcmp (argv[i], "--structs") == 0) {
572 CGOptions::use_struct(true);
573 continue;
574 }
575
576 if (strcmp (argv[i], "--no-structs") == 0) {
577 CGOptions::use_struct(false);
578 continue;
579 }
580
581 if (strcmp (argv[i], "--unions") == 0) {
582 CGOptions::use_union(true);
583 continue;
584 }
585
586 if (strcmp (argv[i], "--no-unions") == 0) {
587 CGOptions::use_union(false);
588 continue;
589 }
590
591 if (strcmp (argv[i], "--argc") == 0) {
592 CGOptions::accept_argc(true);
593 continue;
594 }
595
596 if (strcmp (argv[i], "--no-argc") == 0) {
597 CGOptions::accept_argc(false);
598 continue;
599 }
600
601 if (strcmp (argv[i], "--expand-struct") == 0) {
602 CGOptions::expand_struct(true);
603 continue;
604 }
605
606 if (strcmp (argv[i], "--fixed-struct-fields") == 0) {
607 CGOptions::fixed_struct_fields(true);
608 continue;
609 }
610
611 if (strcmp (argv[i], "--max-struct-fields") ==0 ) {
612 unsigned long ret;
613 i++;
614 arg_check(argc, i);
615 if (!parse_int_arg(argv[i], &ret))
616 exit(-1);
617 CGOptions::max_struct_fields(ret);
618 continue;
619 }
620
621 if (strcmp (argv[i], "--max-union-fields") ==0 ) {
622 unsigned long ret;
623 i++;
624 arg_check(argc, i);
625 if (!parse_int_arg(argv[i], &ret))
626 exit(-1);
627 CGOptions::max_union_fields(ret);
628 continue;
629 }
630
631 if (strcmp (argv[i], "--max-nested-struct-level") ==0 ) {
632 unsigned long ret;
633 i++;
634 arg_check(argc, i);
635 if (!parse_int_arg(argv[i], &ret))
636 exit(-1);
637 CGOptions::max_nested_struct_level(ret);
638 continue;
639 }
640
641 if (strcmp (argv[i], "--struct-output") == 0) {
642 string s;
643 i++;
644 arg_check(argc, i);
645 if (!parse_string_arg(argv[i], s))
646 exit(-1);
647 CGOptions::struct_output(s);
648 continue;
649 }
650
651 if (strcmp (argv[i], "--dfs-debug-sequence") == 0) {
652 string s;
653 i++;
654 arg_check(argc, i);
655 if (!parse_string_arg(argv[i], s))
656 exit(-1);
657 CGOptions::dfs_debug_sequence(s);
658 continue;
659 }
660
661 if (strcmp (argv[i], "--max-exhaustive-depth") ==0 ) {
662 unsigned long ret;
663 i++;
664 arg_check(argc, i);
665 if (!parse_int_arg(argv[i], &ret))
666 exit(-1);
667 CGOptions::max_exhaustive_depth(ret);
668 continue;
669 }
670
671 if (strcmp (argv[i], "--max-pointer-depth") ==0 ) {
672 unsigned long ret;
673 i++;
674 arg_check(argc, i);
675 if (!parse_int_arg(argv[i], &ret))
676 exit(-1);
677 CGOptions::max_indirect_level(ret);
678 continue;
679 }
680
681 if (strcmp (argv[i], "--output") == 0 ||
682 strcmp (argv[i], "-o") == 0) {
683 string o_file;
684 i++;
685 arg_check(argc, i);
686 if (!parse_string_arg(argv[i], o_file))
687 exit(-1);
688 CGOptions::output_file(o_file);
689 continue;
690 }
691
692 if (strcmp (argv[i], "--delta-monitor") == 0) {
693 string monitor;
694 i++;
695 arg_check(argc, i);
696 if (!parse_string_arg(argv[i], monitor)) {
697 cout<< "please specify one delta monitor!" << std::endl;
698 exit(-1);
699 }
700 CGOptions::delta_monitor(monitor);
701 continue;
702 }
703
704 if (strcmp (argv[i], "--delta-output") == 0) {
705 string o_file;
706 i++;
707 arg_check(argc, i);
708 if (!parse_string_arg(argv[i], o_file)) {
709 cout<< "please specify delta output file!" << std::endl;
710 exit(-1);
711 }
712 CGOptions::delta_output(o_file);
713 continue;
714 }
715
716 if (strcmp (argv[i], "--go-delta") == 0) {
717 string monitor;
718 i++;
719 arg_check(argc, i);
720 if (!parse_string_arg(argv[i], monitor)) {
721 cout<< "please specify one delta type!" << std::endl;
722 exit(-1);
723 }
724 CGOptions::go_delta(monitor);
725 continue;
726 }
727
728 if (strcmp (argv[i], "--no-delta-reduction") == 0) {
729 CGOptions::no_delta_reduction(true);
730 continue;
731 }
732
733 if (strcmp (argv[i], "--math-notmp") == 0) {
734 CGOptions::math_notmp(true);
735 continue;
736 }
737
738 if (strcmp (argv[i], "--math64") == 0) {
739 CGOptions::math64(true);
740 continue;
741 }
742
743 if (strcmp (argv[i], "--no-math64") == 0) {
744 CGOptions::math64(false);
745 continue;
746 }
747
748 if (strcmp (argv[i], "--inline-function") == 0) {
749 CGOptions::inline_function(true);
750 continue;
751 }
752
753 if (strcmp (argv[i], "--no-inline-function") == 0) {
754 CGOptions::inline_function(false);
755 continue;
756 }
757
758 if (strcmp (argv[i], "--longlong") == 0) {
759 CGOptions::longlong(true);
760 continue;
761 }
762
763 if (strcmp (argv[i], "--no-longlong") == 0) {
764 CGOptions::longlong(false);
765 continue;
766 }
767
768 if (strcmp (argv[i], "--int8") == 0) {
769 CGOptions::int8(true);
770 continue;
771 }
772
773 if (strcmp (argv[i], "--no-int8") == 0) {
774 CGOptions::int8(false);
775 continue;
776 }
777
778 if (strcmp (argv[i], "--uint8") == 0) {
779 CGOptions::uint8(true);
780 continue;
781 }
782
783 if (strcmp (argv[i], "--no-uint8") == 0) {
784 CGOptions::uint8(false);
785 continue;
786 }
787
788 if (strcmp (argv[i], "--float") == 0) {
789 CGOptions::enable_float(true);
790 continue;
791 }
792
793 if (strcmp (argv[i], "--no-float") == 0) {
794 CGOptions::enable_float(false);
795 continue;
796 }
797
798 if (strcmp (argv[i], "--strict-float") == 0) {
799 CGOptions::strict_float(true);
800 continue;
801 }
802
803 if (strcmp (argv[i], "--pointers") == 0) {
804 CGOptions::pointers(true);
805 continue;
806 }
807
808 if (strcmp (argv[i], "--no-pointers") == 0) {
809 CGOptions::pointers(false);
810 continue;
811 }
812
813 if (strcmp (argv[i], "--max-array-dim") ==0 ) {
814 unsigned long dim;
815 i++;
816 arg_check(argc, i);
817 if (!parse_int_arg(argv[i], &dim))
818 exit(-1);
819 CGOptions::max_array_dimensions(dim);
820 continue;
821 }
822
823 if (strcmp (argv[i], "--max-array-len-per-dim") ==0 ) {
824 unsigned long length;
825 i++;
826 arg_check(argc, i);
827 if (!parse_int_arg(argv[i], &length))
828 exit(-1);
829 CGOptions::max_array_length_per_dimension(length);
830 continue;
831 }
832
833 if (strcmp (argv[i], "--arrays") == 0) {
834 CGOptions::arrays(true);
835 continue;
836 }
837
838 if (strcmp (argv[i], "--no-arrays") == 0) {
839 CGOptions::arrays(false);
840 continue;
841 }
842
843 if (strcmp (argv[i], "--strict-const-arrays") == 0) {
844 CGOptions::strict_const_arrays(true);
845 continue;
846 }
847
848 if (strcmp (argv[i], "--jumps") == 0) {
849 CGOptions::jumps(true);
850 continue;
851 }
852
853 if (strcmp (argv[i], "--no-jumps") == 0) {
854 CGOptions::jumps(false);
855 continue;
856 }
857
858 if (strcmp (argv[i], "--return-structs") == 0) {
859 CGOptions::return_structs(true);
860 continue;
861 }
862
863 if (strcmp (argv[i], "--no-return-structs") == 0) {
864 CGOptions::return_structs(false);
865 continue;
866 }
867
868 if (strcmp (argv[i], "--arg-structs") == 0) {
869 CGOptions::arg_structs(true);
870 continue;
871 }
872
873 if (strcmp (argv[i], "--no-arg-structs") == 0) {
874 CGOptions::arg_structs(false);
875 continue;
876 }
877
878 if (strcmp (argv[i], "--return-unions") == 0) {
879 CGOptions::return_unions(true);
880 continue;
881 }
882
883 if (strcmp (argv[i], "--no-return-unions") == 0) {
884 CGOptions::return_unions(false);
885 continue;
886 }
887
888 if (strcmp (argv[i], "--arg-unions") == 0) {
889 CGOptions::arg_unions(true);
890 continue;
891 }
892
893 if (strcmp (argv[i], "--no-arg-unions") == 0) {
894 CGOptions::arg_unions(false);
895 continue;
896 }
897
898 if (strcmp (argv[i], "--volatiles") == 0) {
899 CGOptions::volatiles(true);
900 continue;
901 }
902
903 if (strcmp (argv[i], "--no-volatiles") == 0) {
904 CGOptions::volatiles(false);
905 continue;
906 }
907
908 if (strcmp (argv[i], "--volatile-pointers") == 0) {
909 CGOptions::volatile_pointers(true);
910 continue;
911 }
912
913 if (strcmp (argv[i], "--no-volatile-pointers") == 0) {
914 CGOptions::volatile_pointers(false);
915 continue;
916 }
917
918 if (strcmp (argv[i], "--const-pointers") == 0) {
919 CGOptions::const_pointers(true);
920 continue;
921 }
922
923 if (strcmp (argv[i], "--no-const-pointers") == 0) {
924 CGOptions::const_pointers(false);
925 continue;
926 }
927
928 if (strcmp (argv[i], "--global-variabless") == 0) {
929 CGOptions::global_variables(true);
930 continue;
931 }
932
933 if (strcmp (argv[i], "--no-global-variables") == 0) {
934 CGOptions::global_variables(false);
935 continue;
936 }
937
938 if (strcmp (argv[i], "--enable-access-once") == 0) {
939 CGOptions::access_once(true);
940 continue;
941 }
942
943 if (strcmp (argv[i], "--strict-volatile-rule") == 0) {
944 CGOptions::strict_volatile_rule(true);
945 continue;
946 }
947
948 if (strcmp (argv[i], "--addr-taken-of-locals") == 0) {
949 CGOptions::addr_taken_of_locals(true);
950 continue;
951 }
952
953 if (strcmp (argv[i], "--no-addr-taken-of-locals") == 0) {
954 CGOptions::addr_taken_of_locals(false);
955 continue;
956 }
957
958 if (strcmp (argv[i], "--fresh-array-ctrl-var-names") == 0) {
959 CGOptions::fresh_array_ctrl_var_names(true);
960 continue;
961 }
962
963 if (strcmp (argv[i], "--consts") == 0) {
964 CGOptions::consts(true);
965 continue;
966 }
967
968 if (strcmp (argv[i], "--no-consts") == 0) {
969 CGOptions::consts(false);
970 continue;
971 }
972
973 if (strcmp (argv[i], "--dangling-global-pointers") == 0) {
974 CGOptions::dangling_global_ptrs(true);
975 continue;
976 }
977
978 if (strcmp (argv[i], "--no-dangling-global-pointers") == 0) {
979 CGOptions::dangling_global_ptrs(false);
980 continue;
981 }
982
983 if (strcmp (argv[i], "--divs") == 0) {
984 CGOptions::divs(true);
985 continue;
986 }
987
988 if (strcmp (argv[i], "--no-divs") == 0) {
989 CGOptions::divs(false);
990 continue;
991 }
992
993 if (strcmp (argv[i], "--muls") == 0) {
994 CGOptions::muls(true);
995 continue;
996 }
997
998 if (strcmp (argv[i], "--no-muls") == 0) {
999 CGOptions::muls(false);
1000 continue;
1001 }
1002
1003 if (strcmp (argv[i], "--checksum") == 0) {
1004 CGOptions::compute_hash(true);
1005 continue;
1006 }
1007
1008 if (strcmp (argv[i], "--no-checksum") == 0) {
1009 CGOptions::compute_hash(false);
1010 continue;
1011 }
1012
1013 if (strcmp (argv[i], "--builtins") == 0) {
1014 CGOptions::builtins(true);
1015 continue;
1016 }
1017
1018 if (strcmp (argv[i], "--no-builtins") == 0) {
1019 CGOptions::builtins(false);
1020 continue;
1021 }
1022
1023 if (strcmp (argv[i], "--random-random") == 0) {
1024 CGOptions::random_random(true);
1025 continue;
1026 }
1027
1028 if (strcmp (argv[i], "--check-global") == 0) {
1029 CGOptions::blind_check_global(true);
1030 continue;
1031 }
1032
1033 if (strcmp (argv[i], "--step-hash-by-stmt") == 0) {
1034 CGOptions::step_hash_by_stmt(true);
1035 continue;
1036 }
1037
1038 if (strcmp (argv[i], "--stop-by-stmt") ==0 ) {
1039 unsigned long num;
1040 i++;
1041 arg_check(argc, i);
1042 if (!parse_int_arg(argv[i], &num))
1043 exit(-1);
1044 CGOptions::stop_by_stmt(num);
1045 continue;
1046 }
1047
1048 if (strcmp (argv[i], "--monitor-funcs") == 0) {
1049 string vname;
1050 i++;
1051 arg_check(argc, i);
1052 if (!parse_string_arg(argv[i], vname)) {
1053 cout<< "please specify name(s) of the func(s) you want to monitor" << std::endl;
1054 exit(-1);
1055 }
1056 CGOptions::monitored_funcs(vname);
1057 continue;
1058 }
1059
1060 if (strcmp (argv[i], "--delta-input") == 0) {
1061 string filename;
1062 i++;
1063 arg_check(argc, i);
1064 if (!parse_string_arg(argv[i], filename)) {
1065 cout<< "please specify delta output file!" << std::endl;
1066 exit(-1);
1067 }
1068 CGOptions::delta_input(filename);
1069 continue;
1070 }
1071
1072 if (strcmp (argv[i], "--dump-default-probabilities") == 0) {
1073 string filename;
1074 i++;
1075 arg_check(argc, i);
1076 if (!parse_string_arg(argv[i], filename)) {
1077 cout<< "please pass probability configuration output file!" << std::endl;
1078 exit(-1);
1079 }
1080 CGOptions::dump_default_probabilities(filename);
1081 continue;
1082 }
1083
1084 if (strcmp (argv[i], "--dump-random-probabilities") == 0) {
1085 string filename;
1086 i++;
1087 arg_check(argc, i);
1088 if (!parse_string_arg(argv[i], filename)) {
1089 cout<< "please pass probability configuration output file!" << std::endl;
1090 exit(-1);
1091 }
1092 CGOptions::dump_random_probabilities(filename);
1093 continue;
1094 }
1095
1096 if (strcmp (argv[i], "--probability-configuration") == 0) {
1097 string filename;
1098 i++;
1099 arg_check(argc, i);
1100 if (!parse_string_arg(argv[i], filename)) {
1101 cout<< "please probability configuration file!" << std::endl;
1102 exit(-1);
1103 }
1104 CGOptions::probability_configuration(filename);
1105 continue;
1106 }
1107
1108 if (strcmp (argv[i], "--const-as-condition") == 0) {
1109 CGOptions::const_as_condition(true);
1110 continue;
1111 }
1112
1113 if (strcmp (argv[i], "--match-exact-qualifiers") == 0) {
1114 CGOptions::match_exact_qualifiers(true);
1115 continue;
1116 }
1117
1118 if (strcmp (argv[i], "--no-return-dead-pointer") == 0) {
1119 CGOptions::no_return_dead_ptr(true);
1120 continue;
1121 }
1122
1123 if (strcmp (argv[i], "--return-dead-pointer") == 0) {
1124 CGOptions::no_return_dead_ptr(false);
1125 continue;
1126 }
1127
1128 if (strcmp (argv[i], "--concise") == 0) {
1129 //CGOptions::quiet(true);
1130 //CGOptions::paranoid(false);
1131 CGOptions::concise(true);
1132 continue;
1133 }
1134
1135 if (strcmp (argv[i], "--identify-wrappers") == 0) {
1136 CGOptions::identify_wrappers(true);
1137 continue;
1138 }
1139
1140 if (strcmp (argv[i], "--safe-math-wrappers") == 0) {
1141 string ids;
1142 i++;
1143 arg_check(argc, i);
1144 if (!parse_string_arg(argv[i], ids)) {
1145 cout<< "please specify safe math wrappers in the form of id1,id2..." << std::endl;
1146 exit(-1);
1147 }
1148 CGOptions::safe_math_wrapper(ids);
1149 continue;
1150 }
1151
1152 if (strcmp (argv[i], "--mark-mutable-const") == 0) {
1153 CGOptions::mark_mutable_const(true);
1154 continue;
1155 }
1156
1157 if (strcmp (argv[i], "--force-globals-static") == 0) {
1158 CGOptions::force_globals_static(true);
1159 continue;
1160 }
1161
1162 if (strcmp (argv[i], "--force-non-uniform-arrays") == 0) {
1163 CGOptions::force_non_uniform_array_init(true);
1164 continue;
1165 }
1166
1167 if (strcmp (argv[i], "--no-force-non-uniform-arrays") == 0) {
1168 CGOptions::force_non_uniform_array_init(false);
1169 continue;
1170 }
1171
1172 if (strcmp (argv[i], "--inline-function-prob") == 0 ) {
1173 unsigned long prob;
1174 i++;
1175 arg_check(argc, i);
1176 if (!parse_int_arg(argv[i], &prob))
1177 exit(-1);
1178 CGOptions::inline_function_prob(prob);
1179 continue;
1180 }
1181
1182 if (strcmp (argv[i], "--builtin-function-prob") == 0 ) {
1183 unsigned long prob;
1184 i++;
1185 arg_check(argc, i);
1186 if (!parse_int_arg(argv[i], &prob))
1187 exit(-1);
1188 CGOptions::builtin_function_prob(prob);
1189 continue;
1190 }
1191
1192 if (strcmp (argv[i], "--enable-builtin-kinds") == 0) {
1193 string kinds;
1194 i++;
1195 arg_check(argc, i);
1196 if (!parse_string_arg(argv[i], kinds)) {
1197 cout<< "please specify enabled builtin kinds in the form of k1,k2..." << std::endl;
1198 exit(-1);
1199 }
1200 CGOptions::enable_builtin_kinds(kinds);
1201 continue;
1202 }
1203
1204 if (strcmp (argv[i], "--disable-builtin-kinds") == 0) {
1205 string kinds;
1206 i++;
1207 arg_check(argc, i);
1208 if (!parse_string_arg(argv[i], kinds)) {
1209 cout<< "please specify disabled builtin kinds in the form of k1,k2..." << std::endl;
1210 exit(-1);
1211 }
1212 CGOptions::disable_builtin_kinds(kinds);
1213 continue;
1214 }
1215
1216 if (strcmp (argv[i], "--null-ptr-deref-prob") == 0 ) {
1217 unsigned long prob;
1218 i++;
1219 arg_check(argc, i);
1220 if (!parse_int_arg(argv[i], &prob))
1221 exit(-1);
1222 CGOptions::null_pointer_dereference_prob(prob);
1223 continue;
1224 }
1225
1226 if (strcmp (argv[i], "--dangling-ptr-deref-prob") == 0 ) {
1227 unsigned long prob;
1228 i++;
1229 arg_check(argc, i);
1230 if (!parse_int_arg(argv[i], &prob))
1231 exit(-1);
1232 CGOptions::dead_pointer_dereference_prob(prob);
1233 continue;
1234 }
1235
1236 if (strcmp (argv[i], "--max-expr-complexity") == 0 ) {
1237 unsigned long comp;
1238 i++;
1239 arg_check(argc, i);
1240 if (!parse_int_arg(argv[i], &comp))
1241 exit(-1);
1242 CGOptions::max_expr_depth(comp);
1243 continue;
1244 }
1245
1246 if (strcmp (argv[i], "--max-block-depth") == 0 ) {
1247 unsigned long depth;
1248 i++;
1249 arg_check(argc, i);
1250 if (!parse_int_arg(argv[i], &depth))
1251 exit(-1);
1252 CGOptions::max_blk_depth(depth);
1253 continue;
1254 }
1255
1256 if (strcmp (argv[i], "--max-struct-nested-level") == 0 ) {
1257 unsigned long depth;
1258 i++;
1259 arg_check(argc, i);
1260 if (!parse_int_arg(argv[i], &depth))
1261 exit(-1);
1262 CGOptions::max_nested_struct_level(depth);
1263 continue;
1264 }
1265
1266 if (strcmp (argv[i], "--union-read-type-sensitive") == 0) {
1267 CGOptions::union_read_type_sensitive(true);
1268 continue;
1269 }
1270
1271 if (strcmp (argv[i], "--no-union-read-type-sensitive") == 0) {
1272 CGOptions::union_read_type_sensitive(false);
1273 continue;
1274 }
1275
1276 if (strcmp (argv[i], "--pre-incr-operator") == 0) {
1277 CGOptions::pre_incr_operator(true);
1278 continue;
1279 }
1280
1281 if (strcmp (argv[i], "--no-pre-incr-operator") == 0) {
1282 CGOptions::pre_incr_operator(false);
1283 continue;
1284 }
1285
1286 if (strcmp (argv[i], "--pre-decr-operator") == 0) {
1287 CGOptions::pre_decr_operator(true);
1288 continue;
1289 }
1290
1291 if (strcmp (argv[i], "--no-pre-decr-operator") == 0) {
1292 CGOptions::pre_decr_operator(false);
1293 continue;
1294 }
1295
1296 if (strcmp (argv[i], "--post-incr-operator") == 0) {
1297 CGOptions::post_incr_operator(true);
1298 continue;
1299 }
1300
1301 if (strcmp (argv[i], "--no-post-incr-operator") == 0) {
1302 CGOptions::post_incr_operator(false);
1303 continue;
1304 }
1305
1306 if (strcmp (argv[i], "--post-decr-operator") == 0) {
1307 CGOptions::post_decr_operator(true);
1308 continue;
1309 }
1310
1311 if (strcmp (argv[i], "--no-post-decr-operator") == 0) {
1312 CGOptions::post_decr_operator(false);
1313 continue;
1314 }
1315
1316 if (strcmp (argv[i], "--unary-plus-operator") == 0) {
1317 CGOptions::unary_plus_operator(true);
1318 continue;
1319 }
1320
1321 if (strcmp (argv[i], "--no-unary-plus-operator") == 0) {
1322 CGOptions::unary_plus_operator(false);
1323 continue;
1324 }
1325
1326 if (strcmp (argv[i], "--embedded-assigns") == 0) {
1327 CGOptions::use_embedded_assigns(true);
1328 continue;
1329 }
1330
1331 if (strcmp (argv[i], "--no-safe-math") == 0){
1332 CGOptions::avoid_signed_overflow(false);
1333 continue;
1334 }
1335
1336 if (strcmp (argv[i], "--safe-math") == 0){
1337 CGOptions::avoid_signed_overflow(true);
1338 continue;
1339 }
1340
1341 if (strcmp (argv[i], "--no-embedded-assigns") == 0) {
1342 CGOptions::use_embedded_assigns(false);
1343 continue;
1344 }
1345
1346 if (strcmp (argv[i], "--comma-operators") == 0) {
1347 CGOptions::use_comma_exprs(true);
1348 continue;
1349 }
1350
1351 if (strcmp (argv[i], "--no-comma-operators") == 0) {
1352 CGOptions::use_comma_exprs(false);
1353 continue;
1354 }
1355
1356 if (strcmp (argv[i], "--take-no-union-field-addr") == 0) {
1357 CGOptions::take_union_field_addr(false);
1358 continue;
1359 }
1360
1361 if (strcmp (argv[i], "--take-union-field-addr") == 0) {
1362 CGOptions::take_union_field_addr(true);
1363 continue;
1364 }
1365
1366 if (strcmp (argv[i], "--vol-struct-union-fields") == 0) {
1367 CGOptions::vol_struct_union_fields(true);
1368 continue;
1369 }
1370
1371 if (strcmp (argv[i], "--no-vol-struct-union-fields") == 0) {
1372 CGOptions::vol_struct_union_fields(false);
1373 continue;
1374 }
1375
1376 if (strcmp(argv[i], "--const-struct-union-fields") == 0) {
1377 CGOptions::const_struct_union_fields(true);
1378 continue;
1379 }
1380
1381 if (strcmp(argv[i], "--no-const-struct-union-fields") == 0) {
1382 CGOptions::const_struct_union_fields(false);
1383 continue;
1384 }
1385
1386 if (strcmp (argv[i], "--no-hash-value-printf") == 0) {
1387 CGOptions::hash_value_printf(false);
1388 continue;
1389 }
1390
1391 if (strcmp (argv[i], "--no-signed-char-index") == 0) {
1392 CGOptions::signed_char_index(false);
1393 continue;
1394 }
1395
1396 if (strcmp (argv[i], "--lang-cpp") == 0) {
1397 CGOptions::lang_cpp(true);
1398 continue;
1399 }
1400
1401 if (strcmp(argv[i], "--cpp11") == 0) {
1402 CGOptions::cpp11(true);
1403 continue;
1404 }
1405
1406 if (strcmp (argv[i], "--reduce") == 0) {
1407 string filename;
1408 i++;
1409 arg_check(argc, i);
1410 if (!parse_string_arg(argv[i], filename)) {
1411 cout<< "please specify reduction directive file!" << std::endl;
1412 exit(-1);
1413 }
1414 ifstream conf(filename.c_str());
1415 if (conf.fail()) {
1416 cout<< "can't read reduction directive file " << filename << "!" << std::endl;
1417 exit(-1);
1418 }
1419 CGOptions::init_reducer(filename);
1420 continue;
1421 }
1422
1423 if (strcmp(argv[i], "--fast-execution") == 0) {
1424 CGOptions::lang_cpp(true);
1425 // jumps can easily cause infinite loops. Just disable them
1426 CGOptions::jumps(false);
1427 // large arrays are also reported to cause slow execution
1428 CGOptions::max_array_length_per_dimension(5);
1429 continue;
1430 }
1431 // OMIT help
1432
1433 // OMIT compute-hash
1434
1435 // OMIT depth-protect
1436
1437 // OMIT wrap-volatiles
1438
1439 // OMIT allow-const-volatile
1440
1441 // OMIT allow-int64
1442
1443 // OMIT avoid-signed-overflow
1444
1445 // FIXME-- we should parse all options and then this should be
1446 // an error
1447
1448 cout << "invalid option " << argv[i] << " at: "
1449 << i
1450 << endl;
1451 exit(-1);
1452 }
1453
1454 if (CGOptions::lang_cpp()) {
1455 CGOptions::fix_options_for_cpp();
1456 }
1457
1458 if (CGOptions::has_conflict()) {
1459 cout << "error: options conflict - " << CGOptions::conflict_msg() << std::endl;
1460 exit(-1);
1461 }
1462
1463 AbsProgramGenerator *generator = AbsProgramGenerator::CreateInstance(argc, argv, g_Seed);
1464 if (!generator) {
1465 cout << "error: can't create generator!" << std::endl;
1466 exit(-1);
1467 }
1468 generator->goGenerator();
1469 delete generator;
1470
1471 // file.close();
1472 return 0;
1473 }
1474
1475 ///////////////////////////////////////////////////////////////////////////////
1476
1477 // Local Variables:
1478 // c-basic-offset: 4
1479 // tab-width: 4
1480 // End:
1481
1482 // End of file.
1483