/
2ls_parse_options.cpp
1595 lines (1358 loc) · 41.5 KB
/
2ls_parse_options.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************\
Module: 2LS Command Line Options Processing
Author: Daniel Kroening, Peter Schrammel
\*******************************************************************/
/// \file
/// 2LS Command Line Options Processing
#include <memory>
#include <iostream>
#include <fstream>
#include <climits>
#include <util/string2int.h>
#include <util/config.h>
#include <util/language.h>
#include <util/options.h>
#include <util/memory_info.h>
#include <ansi-c/ansi_c_language.h>
#include <cpp/cpp_language.h>
#include <goto-programs/goto_convert_functions.h>
#include <goto-programs/show_properties.h>
#include <goto-programs/set_properties.h>
#include <goto-programs/remove_function_pointers.h>
#include <goto-programs/read_goto_binary.h>
#include <goto-programs/loop_ids.h>
#include <goto-programs/link_to_library.h>
#include <goto-programs/goto_inline.h>
#include <goto-programs/goto_inline_class.h>
#include <goto-programs/goto_functions.h>
#include <goto-programs/xml_goto_trace.h>
#include <goto-programs/json_goto_trace.h>
#include <goto-programs/remove_returns.h>
#include <goto-programs/remove_skip.h>
#include <analyses/goto_check.h>
#include <langapi/mode.h>
#include <cbmc/version.h>
#include "version.h"
#include <ssa/malloc_ssa.h>
#include "graphml_witness_ext.h"
#include <solver/summary_db.h>
#include <ssa/dynobj_instance_analysis.h>
#include "2ls_parse_options.h"
#include "summary_checker_ai.h"
#include "summary_checker_bmc.h"
#include "summary_checker_kind.h"
#include "summary_checker_nonterm.h"
#include "show.h"
#include "horn_encoding.h"
#define UNWIND_GOTO_INTO_LOOP 0
#define REMOVE_MULTIPLE_DEREFERENCES 1
#define IGNORE_RECURSION 1
#define IGNORE_THREADS 1
#define EXPLICIT_NONDET_LOCALS 0
#define FILTER_ASSERTIONS 1
twols_parse_optionst::twols_parse_optionst(int argc, const char **argv):
parse_options_baset(TWOLS_OPTIONS, argc, argv),
language_uit(cmdline, ui_message_handler),
ui_message_handler(cmdline, "2LS " TWOLS_VERSION),
recursion_detected(false),
threads_detected(false),
dynamic_memory_detected(false)
{
}
void twols_parse_optionst::eval_verbosity()
{
// this is our default verbosity
int v=messaget::M_STATISTICS;
if(cmdline.isset("verbosity"))
{
v=unsafe_string2int(cmdline.get_value("verbosity"));
if(v<0)
v=0;
else if(v>10)
v=10;
}
ui_message_handler.set_verbosity(v);
}
void twols_parse_optionst::get_command_line_options(optionst &options)
{
if(config.set(cmdline))
{
usage_error();
exit(1);
}
if(cmdline.isset("xml-ui"))
options.set_option("xml-ui", true);
if(cmdline.isset("debug-level"))
options.set_option("debug-level", cmdline.get_value("debug-level"));
if(cmdline.isset("unwindset"))
options.set_option("unwindset", cmdline.get_value("unwindset"));
if(cmdline.isset("unwind"))
options.set_option("unwind", cmdline.get_value("unwind"));
if(cmdline.isset("inline-partial"))
options.set_option("inline-partial", cmdline.get_value("inline-partial"));
if(cmdline.isset("inline"))
options.set_option("inline", true);
if(cmdline.isset("slice") && cmdline.isset("inline"))
options.set_option("slice", true);
else
options.set_option("slice", false);
// all checks supported by goto_check
GOTO_CHECK_PARSE_OPTIONS(cmdline, options);
// check assertions
if(cmdline.isset("no-assertions"))
options.set_option("assertions", false);
else
options.set_option("assertions", true);
// use assumptions
if(cmdline.isset("no-assumptions"))
options.set_option("assumptions", false);
else
options.set_option("assumptions", true);
// use arithmetic refinements
if(cmdline.isset("refine"))
options.set_option("refine", true);
else
options.set_option("refine", false);
// compute standard invariants (include value at loop entry)
if(cmdline.isset("std-invariants"))
options.set_option("std-invariants", true);
else
options.set_option("std-invariants", false);
if(cmdline.isset("no-propagation"))
options.set_option("constant-propagation", false);
else
options.set_option("constant-propagation", true);
// magic error label
if(cmdline.isset("error-label"))
options.set_option("error-label", cmdline.get_value("error-label"));
if(cmdline.isset("havoc"))
options.set_option("havoc", true);
else
{
// Options for using simple domains
optionst::value_listt simple_domains;
if(cmdline.isset("equalities"))
{
options.set_option("equalities", true);
options.set_option("std-invariants", true);
simple_domains.push_back("equalities");
}
if(cmdline.isset("heap"))
{
options.set_option("heap", true);
simple_domains.push_back("heap");
}
// Choose only a single value domain
if(cmdline.isset("values-refine"))
{
options.set_option("values-refine", true);
options.set_option("intervals", true);
simple_domains.push_back("intervals");
}
else if(cmdline.isset("zones"))
{
options.set_option("zones", true);
simple_domains.push_back("zones");
}
else if(cmdline.isset("qzones"))
{
options.set_option("qzones", true);
simple_domains.push_back("qzones");
}
else if(cmdline.isset("octagons"))
{
options.set_option("octagons", true);
simple_domains.push_back("octagons");
}
else if(cmdline.isset("intervals"))
{
options.set_option("intervals", true);
simple_domains.push_back("intervals");
}
// If no simple domains are specified, use intervals
if(simple_domains.empty())
{
options.set_option("intervals", true);
simple_domains.push_back("intervals");
}
// TODO: due to various modifications of options during verification
// (e.g. in summary_checker_ait or in handle_special_functions), it is not
// possible to rely on the content of this option.
options.set_option("simple-domains", simple_domains);
if(options.get_bool_option("values-refine") ||
options.get_bool_option("zones") ||
options.get_bool_option("qzones") ||
options.get_bool_option("octagons") ||
options.get_bool_option("intervals"))
{
// Choose solver for numerical domains
if(cmdline.isset("enum-solver"))
options.set_option("enum-solver", true);
else // if(cmdline.isset("binsearch-solver")) // default
options.set_option("binsearch-solver", true);
}
}
// Heap domain requires full program inlining and usage of symbolic paths
if(cmdline.isset("heap"))
{
options.set_option("inline", true);
options.set_option("sympath", true);
}
// use incremental assertion checks
if(cmdline.isset("non-incremental"))
options.set_option("incremental", false);
else
options.set_option("incremental", true);
// compute preconditions
if(cmdline.isset("preconditions"))
options.set_option("preconditions", true);
// compute necessary/sufficient preconditions
if(cmdline.isset("sufficient"))
options.set_option("sufficient", true);
// compute ranking functions
if(cmdline.isset("termination"))
{
options.set_option("termination", true);
options.set_option("sufficient", true);
options.set_option("std-invariants", true);
}
if(cmdline.isset("monolithic-ranking-function"))
{
options.set_option("monolithic-ranking-function", true);
}
else
options.set_option("monolithic-ranking-function", false);
if(cmdline.isset("lexicographic-ranking-function"))
{
options.set_option(
"lexicographic-ranking-function",
cmdline.get_value("lexicographic-ranking-function"));
}
else
options.set_option("lexicographic-ranking-function", 5);
if(cmdline.isset("max-inner-ranking-iterations"))
{
options.set_option(
"max-inner-ranking-iterations",
cmdline.get_value("max-inner-ranking-iterations"));
}
else
options.set_option("max-inner-ranking-iterations", 50);
// do k-induction refinement
if(cmdline.isset("k-induction"))
{
options.set_option("std-invariants", true);
options.set_option("k-induction", true);
options.set_option("inline", true);
if(!cmdline.isset("unwind"))
options.set_option("unwind", std::numeric_limits<unsigned>::max());
}
// compute singleton recurrence set - simple nontermination
if(cmdline.isset("nontermination"))
{
options.set_option("nontermination", true);
options.set_option("all-properties", true);
options.set_option("inline", true);
if(!cmdline.isset("unwind"))
options.set_option("unwind", std::numeric_limits<unsigned>::max());
}
// do incremental bmc
if(cmdline.isset("incremental-bmc"))
{
options.set_option("incremental-bmc", true);
options.set_option("inline", true);
options.set_option("havoc", true);
if(!cmdline.isset("unwind"))
options.set_option("unwind", std::numeric_limits<unsigned>::max());
}
// check for spuriousness of assertion failures
if(cmdline.isset("no-spurious-check"))
options.set_option("spurious-check", false);
else
options.set_option("spurious-check", true);
// all properties (default)
if(cmdline.isset("stop-on-fail"))
options.set_option("all-properties", false);
else
options.set_option("all-properties", true);
// no all functions (default)
if(cmdline.isset("all-functions"))
options.set_option("all-functions", true);
else
options.set_option("all-functions", false);
// competition mode
if(cmdline.isset("competition-mode"))
{
options.set_option("competition-mode", true);
options.set_option("all-properties", false);
options.set_option("inline", true);
options.set_option("give-up-invariants", "2");
}
// instrumentation / output
if(cmdline.isset("instrument-output"))
options.set_option(
"instrument-output",
cmdline.get_value("instrument-output"));
#ifdef SHOW_CALLING_CONTEXTS
if(cmdline.isset("show-calling-contexts"))
{
if(!options.get_bool_option("intervals"))
throw "--show-calling-contexts only possible with --intervals";
options.set_option("show-calling-contexts", true);
options.set_option(
"do-not-analyze-functions",
cmdline.get_value("show-calling-contexts"));
}
#endif
if(cmdline.isset("trace"))
options.set_option("trace", true);
if(cmdline.isset("graphml-witness"))
options.set_option("graphml-witness", cmdline.get_value("graphml-witness"));
if(cmdline.isset("json-cex"))
options.set_option("json-cex", cmdline.get_value("json-cex"));
}
/// invoke main modules
int twols_parse_optionst::doit()
{
if(cmdline.isset("version"))
{
std::cout << TWOLS_VERSION << std::endl;
return 0;
}
//
// command line options
//
optionst options;
get_command_line_options(options);
eval_verbosity();
//
// Print a banner
//
status() << "2LS version " TWOLS_VERSION " (based on CBMC " CBMC_VERSION ")"
<< eom;
goto_modelt goto_model;
register_languages();
if(get_goto_program(options, goto_model))
return 6;
const namespacet ns(goto_model.symbol_table);
if(cmdline.isset("show-stats"))
{
show_stats(goto_model, std::cout);
return 7;
}
// options for various debug outputs
if(cmdline.isset("show-ssa"))
{
bool simplify=!cmdline.isset("no-simplify");
irep_idt function=cmdline.get_value("function");
show_ssa(
goto_model,
options,
function,
simplify,
std::cout,
ui_message_handler);
return 7;
}
if(cmdline.isset("show-defs"))
{
irep_idt function=cmdline.get_value("function");
show_defs(goto_model, function, options, std::cout, ui_message_handler);
return 7;
}
if(cmdline.isset("show-assignments"))
{
irep_idt function=cmdline.get_value("function");
show_assignments(
goto_model, function, options, std::cout, ui_message_handler);
return 7;
}
if(cmdline.isset("show-guards"))
{
irep_idt function=cmdline.get_value("function");
show_guards(goto_model, function, std::cout, ui_message_handler);
return 7;
}
if(cmdline.isset("show-value-sets"))
{
irep_idt function=cmdline.get_value("function");
show_value_sets(
goto_model, function, options, std::cout, ui_message_handler);
return 7;
}
if(cmdline.isset("show-invariants"))
{
options.set_option("show-invariants", true);
}
if(cmdline.isset("nontermination"))
{
// turn assertions (from generic checks) into assumptions
Forall_goto_functions(f_it, goto_model.goto_functions)
{
goto_programt &body=f_it->second.body;
Forall_goto_program_instructions(i_it, body)
{
if(i_it->is_assert())
i_it->type=goto_program_instruction_typet::ASSUME;
}
}
}
#if IGNORE_RECURSION
if(recursion_detected)
{
status() << "Recursion not supported" << eom;
report_unknown();
return 5;
}
#endif
#if IGNORE_THREADS
if(threads_detected)
{
status() << "Threads not supported" << eom;
report_unknown();
return 5;
}
#endif
if(cmdline.isset("context-sensitive"))
{
options.set_option("context-sensitive", true);
status() << "Context-sensitive analysis from " <<
goto_model.goto_functions.entry_point() << eom;
}
if(cmdline.isset("arrays"))
{
options.set_option("arrays", true);
status() << "Do not ignore array contents" << eom;
}
// TODO: check option inconsistencies, ignored options etc
if(options.get_bool_option("havoc"))
status() << "Havocking loops and function calls" << eom;
else if(options.get_bool_option("equalities"))
status() << "Using (dis)equalities domain" << eom;
else if(options.get_bool_option("heap"))
status() << "Using heap domain" << eom;
else if(options.get_bool_option("heap-interval"))
status() << "Using heap domain with interval domain for values" << eom;
else if(options.get_bool_option("heap-zones"))
status() << "Using heap domain with zones domain for values" << eom;
else
{
if(options.get_bool_option("intervals"))
status() << "Using intervals domain";
else if(options.get_bool_option("zones"))
status() << "Using zones domain";
else if(options.get_bool_option("octagons"))
status() << "Using octagons domain";
else
assert(false);
if(options.get_bool_option("enum-solver"))
status() << " with enumeration solver";
else if(options.get_bool_option("binsearch-solver"))
status() << " with binary search solver";
else
assert(false);
status() << eom;
}
// don't use k-induction with dynamic memory
if(options.get_bool_option("competition-mode") &&
options.get_bool_option("k-induction") &&
dynamic_memory_detected)
{
options.set_option("k-induction", false);
options.set_option("std-invariants", false);
options.set_option("incremental-bmc", false);
options.set_option("unwind", 0);
}
// don't do nontermination with dynamic memory
if(options.get_bool_option("competition-mode") &&
(options.get_bool_option("termination") ||
options.get_bool_option("nontermination")) &&
dynamic_memory_detected)
{
error() << "Termination analysis does not support "
<< "dynamic memory allocation" << eom;
report_unknown();
return 5;
}
try
{
std::unique_ptr<summary_checker_baset> checker;
if(!options.get_bool_option("k-induction") &&
!options.get_bool_option("incremental-bmc"))
checker=std::unique_ptr<summary_checker_baset>(
new summary_checker_ait(options));
if(options.get_bool_option("k-induction") &&
!options.get_bool_option("incremental-bmc"))
checker=std::unique_ptr<summary_checker_baset>(
new summary_checker_kindt(options));
if(!options.get_bool_option("k-induction") &&
options.get_bool_option("incremental-bmc"))
checker=std::unique_ptr<summary_checker_baset>(
new summary_checker_bmct(options));
if(options.get_bool_option("nontermination"))
checker=std::unique_ptr<summary_checker_baset>(
new summary_checker_nontermt(options));
checker->set_message_handler(get_message_handler());
checker->simplify=!cmdline.isset("no-simplify");
checker->fixed_point=!cmdline.isset("no-fixed-point");
int retval;
if(cmdline.isset("show-vcc"))
{
std::cout << "VERIFICATION CONDITIONS:\n\n";
checker->show_vcc=true;
(*checker)(goto_model);
return 0;
}
if(cmdline.isset("horn-encoding"))
{
status() << "Horn-clause encoding" << eom;
namespacet ns(symbol_table);
std::string out_file=cmdline.get_value("horn-encoding");
if(out_file=="-")
{
horn_encoding(goto_model, options, std::cout);
}
else
{
#ifdef _MSC_VER
std::ofstream out(widen(out_file).c_str());
#else
std::ofstream out(out_file.c_str());
#endif
if(!out)
{
error() << "Failed to open output file "
<< out_file << eom;
return 1;
}
horn_encoding(goto_model, options, out);
}
return 0;
}
bool report_assertions=
!options.get_bool_option("preconditions") &&
!options.get_bool_option("termination") &&
!options.get_bool_option("nontermination");
// do actual analysis
switch((*checker)(goto_model))
{
case property_checkert::PASS:
if(report_assertions)
report_properties(options, goto_model, checker->property_map);
report_success();
if(cmdline.isset("graphml-witness"))
output_graphml_proof(options, goto_model, *checker);
retval=0;
break;
case property_checkert::FAIL:
{
if(report_assertions)
report_properties(options, goto_model, checker->property_map);
// validate trace
bool trace_valid=false;
for(const auto &p : checker->property_map)
{
if(p.second.result!=property_checkert::FAIL)
continue;
if(options.get_bool_option("trace"))
show_counterexample(goto_model, p.second.error_trace);
trace_valid=
!p.second.error_trace.steps.empty() &&
(options.get_bool_option("nontermination") ||
p.second.error_trace.steps.back().is_assert());
break;
}
if(cmdline.isset("graphml-witness"))
{
#if 1
if(!trace_valid)
{
retval=5;
error() << "Internal witness validation failed" << eom;
report_unknown();
break;
}
#endif
output_graphml_cex(options, goto_model, *checker);
}
report_failure();
retval=10;
break;
}
case property_checkert::UNKNOWN:
if(report_assertions)
report_properties(options, goto_model, checker->property_map);
retval=5;
report_unknown();
break;
default:
assert(false);
}
if(cmdline.isset("instrument-output"))
{
checker->instrument_and_output(goto_model);
}
return retval;
}
catch(const std::string error_msg)
{
error() << error_msg << messaget::eom;
return 8;
}
catch(const char *error_msg)
{
error() << error_msg << messaget::eom;
return 8;
}
#if 0
// let's log some more statistics
debug() << "Memory consumption:" << messaget::endl;
memory_info(debug());
debug() << eom;
#endif
}
void twols_parse_optionst::type_stats_rec(
const typet &type,
expr_statst &stats,
const namespacet &ns)
{
if(type.id()==ID_symbol)
type_stats_rec(ns.follow(type), stats, ns);
if(type.id()==ID_pointer || type.id()==ID_array)
{
stats.has_array=true;
const typet &subtype=ns.follow(type.subtype());
if(subtype.id()==ID_signedbv ||
subtype.id()==ID_unsignedbv)
{
stats.has_string=
(to_bitvector_type(subtype).get_width()==config.ansi_c.char_width);
}
}
if(type.has_subtypes())
{
forall_subtypes(it, type)
{
type_stats_rec(*it, stats, ns);
}
}
}
void twols_parse_optionst::expr_stats_rec(
const exprt &expr,
expr_statst &stats)
{
if(expr.id()==ID_side_effect)
{
const side_effect_exprt &side_effect_expr=to_side_effect_expr(expr);
const irep_idt &statement=side_effect_expr.get_statement();
if(statement==ID_malloc)
{
stats.has_malloc=true;
}
else if(statement==ID_nondet)
{
// done in statet:instantiate_rec
}
}
if(expr.has_operands())
{
forall_operands(it, expr)
{
expr_stats_rec(*it, stats);
}
}
}
void twols_parse_optionst::show_stats(
const goto_modelt &goto_model,
std::ostream &out)
{
const namespacet ns(goto_model.symbol_table);
expr_statst stats;
unsigned nr_instructions=0;
unsigned nr_functions=0;
unsigned nr_loops=0;
// analyze all the functions
forall_goto_functions(f_it, goto_model.goto_functions)
{
if(!f_it->second.body_available())
continue;
++nr_functions;
const goto_programt &goto_program=f_it->second.body;
#if 0
statistics() << "function size of " << f_it->first << ": "
<< goto_program.instructions.size() << eom;
#endif
for(goto_programt::instructionst::const_iterator
i_it=goto_program.instructions.begin();
i_it!=goto_program.instructions.end();
i_it++)
{
nr_instructions++;
const goto_programt::instructiont &instruction=*i_it;
if(i_it->is_backwards_goto())
nr_loops++;
switch(instruction.type)
{
case ASSIGN:
{
const code_assignt &assign=to_code_assign(instruction.code);
expr_stats_rec(assign.lhs(), stats);
expr_stats_rec(assign.rhs(), stats);
break;
}
case ASSUME:
expr_stats_rec(instruction.guard, stats);
break;
case ASSERT:
expr_stats_rec(instruction.guard, stats);
break;
case GOTO:
expr_stats_rec(instruction.guard, stats);
break;
case DECL:
// someone declaring an array
type_stats_rec(
to_code_decl(instruction.code).symbol().type(), stats, ns);
break;
default:
// skip
break;
} // switch
} // forall instructions
} // forall functions
out << "=============== STATS=============== " << std::endl;
out << " nr of instructions: " << nr_instructions << std::endl;
out << " nr of functions: " << nr_functions << std::endl;
out << " nr of loops: " << nr_loops << std::endl;
out << " malloc: " << (stats.has_malloc ? "YES" : "NO") << std::endl;
out << " arrays: " << (stats.has_array ? "YES" : "NO") << std::endl;
out << " strings: " << (stats.has_string ? "YES" : "NO") << std::endl;
}
bool twols_parse_optionst::set_properties(goto_modelt &goto_model)
{
try
{
if(cmdline.isset("property"))
::set_properties(goto_model, cmdline.get_values("property"));
}
catch(const char *e)
{
error() << e << eom;
return true;
}
catch(const std::string e)
{
error() << e << eom;
return true;
}
catch(int)
{
return true;
}
return false;
}
void twols_parse_optionst::require_entry(
const goto_modelt &goto_model)
{
irep_idt entry_point=goto_model.goto_functions.entry_point();
if(goto_model.symbol_table.symbols.find(entry_point)==
symbol_table.symbols.end())
throw "the program has no entry point; please complete linking";
}
bool twols_parse_optionst::get_goto_program(
const optionst &options,
goto_modelt &goto_model)
{
if(cmdline.args.size()==0)
{
error() << "Please provide a program to verify" << eom;
return true;
}
try
{
if(cmdline.args.size()==1 &&
is_goto_binary(cmdline.args[0]))
{
status() << "Reading GOTO program from file" << eom;
if(read_goto_binary(
cmdline.args[0], goto_model, get_message_handler()))
return true;
config.set_from_symbol_table(goto_model.symbol_table);
if(cmdline.isset("show-symbol-table"))
{
show_symbol_table();
return true;
}
}
else if(cmdline.isset("show-parse-tree"))
{
if(cmdline.args.size()!=1)
{
error() << "Please give one source file only" << eom;
return true;
}
std::string filename=cmdline.args[0];
#ifdef _MSC_VER
std::ifstream infile(widen(filename).c_str());
#else
std::ifstream infile(filename.c_str());
#endif
if(!infile)
{
error() << "failed to open input file `" << filename << "'" << eom;
return true;
}
languaget *language=get_language_from_filename(filename);
if(language==NULL)
{
error() << "failed to figure out type of file `" << filename << "'"
<< eom;
return true;
}
language->set_message_handler(get_message_handler());
status("Parsing", filename);
if(language->parse(infile, filename))
{
error() << "PARSING ERROR" << eom;
return true;
}
language->show_parse(std::cout);
return true;
}
else
{
if(parse())
return true;
if(typecheck())
return true;
if(final())
return true;
// we no longer need any parse trees or language files
clear_parse();
if(cmdline.isset("show-symbol-table"))
{
show_symbol_table();
return true;
}
#if 0
irep_idt entry_point=goto_model.goto_functions.entry_point();
if(symbol_table.symbols.find(entry_point)==symbol_table.symbols.end())
{
error() << "No entry point; please provide a main function" << eom;
return true;
}
#endif
status() << "Generating GOTO Program" << eom;