Skip to content

Commit 8aa1ea1

Browse files
committed
Factor out getting & processing goto-model
CBMC's methods for getting a goto-model from a source file, and processing that goto-model to be ready for bounded model checking, are now static so that they can be called from clients that wish to set up a goto-model the same way that CBMC does.
1 parent 751a882 commit 8aa1ea1

File tree

3 files changed

+110
-69
lines changed

3 files changed

+110
-69
lines changed

src/cbmc/bmc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ class path_explorert : public bmct
321321
" (use --show-loops to get the loop IDs)\n" \
322322
" --show-vcc show the verification conditions\n" \
323323
" --slice-formula remove assignments unrelated to property\n" \
324-
" --unwinding-assertions generate unwinding assertions\n" \
324+
" --unwinding-assertions generate unwinding assertions (cannot be\n" \
325+
" used with --cover or --partial-loops)\n" \
325326
" --partial-loops permit paths with partial loops\n" \
326327
" --no-pretty-names do not simplify identifiers\n" \
327328
" --graphml-witness filename write the witness in GraphML format to " \

src/cbmc/cbmc_parse_options.cpp

Lines changed: 99 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,28 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
132132

133133
cbmc_parse_optionst::set_default_options(options);
134134

135+
if(cmdline.isset("cover") && cmdline.isset("unwinding-assertions"))
136+
{
137+
error() << "--cover and --unwinding-assertions must not be given together"
138+
<< eom;
139+
exit(CPROVER_EXIT_USAGE_ERROR);
140+
}
141+
142+
if(cmdline.isset("partial-loops") && cmdline.isset("unwinding-assertions"))
143+
{
144+
error() << "--partial-loops and --unwinding-assertions must not be given "
145+
<< "together" << eom;
146+
exit(CPROVER_EXIT_USAGE_ERROR);
147+
}
148+
149+
if(cmdline.isset("reachability-slice") &&
150+
cmdline.isset("reachability-slice-fb"))
151+
{
152+
error() << "--reachability-slice and --reachability-slice-fb must not be "
153+
<< "given together" << eom;
154+
exit(CPROVER_EXIT_USAGE_ERROR);
155+
}
156+
135157
if(cmdline.isset("paths"))
136158
options.set_option("paths", true);
137159

@@ -165,6 +187,24 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
165187
if(cmdline.isset("cpp11"))
166188
config.cpp.set_cpp11();
167189

190+
if(cmdline.isset("property"))
191+
options.set_option("property", cmdline.get_values("property"));
192+
193+
if(cmdline.isset("drop-unused-functions"))
194+
options.set_option("drop-unused-functions", true);
195+
196+
if(cmdline.isset("string-abstraction"))
197+
options.set_option("string-abstraction", true);
198+
199+
if(cmdline.isset("reachability-slice-fb"))
200+
options.set_option("reachability-slice-fb", true);
201+
202+
if(cmdline.isset("reachability-slice"))
203+
options.set_option("reachability-slice", true);
204+
205+
if(cmdline.isset("nondet-static"))
206+
options.set_option("nondet-static", true);
207+
168208
if(cmdline.isset("no-simplify"))
169209
options.set_option("simplify", false);
170210

@@ -227,21 +267,6 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
227267
if(cmdline.isset("partial-loops"))
228268
options.set_option("partial-loops", true);
229269

230-
if(options.is_set("cover") && options.get_bool_option("unwinding-assertions"))
231-
{
232-
error() << "--cover and --unwinding-assertions "
233-
<< "must not be given together" << eom;
234-
exit(CPROVER_EXIT_USAGE_ERROR);
235-
}
236-
237-
if(options.get_bool_option("partial-loops") &&
238-
options.get_bool_option("unwinding-assertions"))
239-
{
240-
error() << "--partial-loops and --unwinding-assertions "
241-
<< "must not be given together" << eom;
242-
exit(CPROVER_EXIT_USAGE_ERROR);
243-
}
244-
245270
// remove unused equations
246271
if(cmdline.isset("slice-formula"))
247272
options.set_option("slice-formula", true);
@@ -532,7 +557,8 @@ int cbmc_parse_optionst::doit()
532557
return CPROVER_EXIT_SUCCESS;
533558
}
534559

535-
int get_goto_program_ret=get_goto_program(options);
560+
int get_goto_program_ret =
561+
get_goto_program(goto_model, options, cmdline, *this, ui_message_handler);
536562

537563
if(get_goto_program_ret!=-1)
538564
return get_goto_program_ret;
@@ -585,25 +611,29 @@ bool cbmc_parse_optionst::set_properties()
585611
}
586612

587613
int cbmc_parse_optionst::get_goto_program(
588-
const optionst &options)
614+
goto_modelt &goto_model,
615+
const optionst &options,
616+
const cmdlinet &cmdline,
617+
messaget &log,
618+
ui_message_handlert &ui_message_handler)
589619
{
590620
if(cmdline.args.empty())
591621
{
592-
error() << "Please provide a program to verify" << eom;
622+
log.error() << "Please provide a program to verify" << log.eom;
593623
return CPROVER_EXIT_INCORRECT_TASK;
594624
}
595625

596626
try
597627
{
598-
goto_model=initialize_goto_model(cmdline, get_message_handler());
628+
goto_model = initialize_goto_model(cmdline, ui_message_handler);
599629

600630
if(cmdline.isset("show-symbol-table"))
601631
{
602632
show_symbol_table(goto_model, ui_message_handler.get_ui());
603633
return CPROVER_EXIT_SUCCESS;
604634
}
605635

606-
if(process_goto_program(options))
636+
if(cbmc_parse_optionst::process_goto_program(goto_model, options, log))
607637
return CPROVER_EXIT_INTERNAL_ERROR;
608638

609639
// show it?
@@ -620,36 +650,36 @@ int cbmc_parse_optionst::get_goto_program(
620650
{
621651
show_goto_functions(
622652
goto_model,
623-
get_message_handler(),
653+
ui_message_handler,
624654
ui_message_handler.get_ui(),
625655
cmdline.isset("list-goto-functions"));
626656
return CPROVER_EXIT_SUCCESS;
627657
}
628658

629-
status() << config.object_bits_info() << eom;
659+
log.status() << config.object_bits_info() << log.eom;
630660
}
631661

632662
catch(const char *e)
633663
{
634-
error() << e << eom;
664+
log.error() << e << log.eom;
635665
return CPROVER_EXIT_EXCEPTION;
636666
}
637667

638668
catch(const std::string &e)
639669
{
640-
error() << e << eom;
670+
log.error() << e << log.eom;
641671
return CPROVER_EXIT_EXCEPTION;
642672
}
643673

644674
catch(int e)
645675
{
646-
error() << "Numeric exception : " << e << eom;
676+
log.error() << "Numeric exception : " << e << log.eom;
647677
return CPROVER_EXIT_EXCEPTION;
648678
}
649679

650680
catch(const std::bad_alloc &)
651681
{
652-
error() << "Out of memory" << eom;
682+
log.error() << "Out of memory" << log.eom;
653683
return CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY;
654684
}
655685

@@ -714,7 +744,9 @@ void cbmc_parse_optionst::preprocessing()
714744
}
715745

716746
bool cbmc_parse_optionst::process_goto_program(
717-
const optionst &options)
747+
goto_modelt &goto_model,
748+
const optionst &options,
749+
messaget &log)
718750
{
719751
try
720752
{
@@ -723,17 +755,17 @@ bool cbmc_parse_optionst::process_goto_program(
723755
remove_asm(goto_model);
724756

725757
// add the library
726-
link_to_library(goto_model, get_message_handler());
758+
link_to_library(goto_model, log.get_message_handler());
727759

728-
if(cmdline.isset("string-abstraction"))
729-
string_instrumentation(goto_model, get_message_handler());
760+
if(options.get_bool_option("string-abstraction"))
761+
string_instrumentation(goto_model, log.get_message_handler());
730762

731763
// remove function pointers
732-
status() << "Removal of function pointers and virtual functions" << eom;
764+
log.status() << "Removal of function pointers and virtual functions" << eom;
733765
remove_function_pointers(
734-
get_message_handler(),
766+
log.get_message_handler(),
735767
goto_model,
736-
cmdline.isset("pointer-check"));
768+
options.get_bool_option("pointer-check"));
737769
// remove catch and throw (introduces instanceof)
738770
remove_exceptions(goto_model);
739771

@@ -749,27 +781,26 @@ bool cbmc_parse_optionst::process_goto_program(
749781
rewrite_union(goto_model);
750782

751783
// add generic checks
752-
status() << "Generic Property Instrumentation" << eom;
784+
log.status() << "Generic Property Instrumentation" << eom;
753785
goto_check(options, goto_model);
754786

755787
// checks don't know about adjusted float expressions
756788
adjust_float_expressions(goto_model);
757789

758790
// ignore default/user-specified initialization
759791
// of variables with static lifetime
760-
if(cmdline.isset("nondet-static"))
792+
if(options.get_bool_option("nondet-static"))
761793
{
762-
status() << "Adding nondeterministic initialization "
763-
"of static/global variables" << eom;
794+
log.status() << "Adding nondeterministic initialization "
795+
"of static/global variables"
796+
<< eom;
764797
nondet_static(goto_model);
765798
}
766799

767-
if(cmdline.isset("string-abstraction"))
800+
if(options.get_bool_option("string-abstraction"))
768801
{
769-
status() << "String Abstraction" << eom;
770-
string_abstraction(
771-
goto_model,
772-
get_message_handler());
802+
log.status() << "String Abstraction" << eom;
803+
string_abstraction(goto_model, log.get_message_handler());
773804
}
774805

775806
// add failed symbols
@@ -782,21 +813,21 @@ bool cbmc_parse_optionst::process_goto_program(
782813
// add loop ids
783814
goto_model.goto_functions.compute_loop_numbers();
784815

785-
if(cmdline.isset("drop-unused-functions"))
816+
if(options.get_bool_option("drop-unused-functions"))
786817
{
787818
// Entry point will have been set before and function pointers removed
788-
status() << "Removing unused functions" << eom;
789-
remove_unused_functions(goto_model, get_message_handler());
819+
log.status() << "Removing unused functions" << eom;
820+
remove_unused_functions(goto_model, log.get_message_handler());
790821
}
791822

792823
// remove skips such that trivial GOTOs are deleted and not considered
793824
// for coverage annotation:
794825
remove_skip(goto_model);
795826

796827
// instrument cover goals
797-
if(cmdline.isset("cover"))
828+
if(options.is_set("cover"))
798829
{
799-
if(instrument_cover_goals(options, goto_model, get_message_handler()))
830+
if(instrument_cover_goals(options, goto_model, log.get_message_handler()))
800831
return true;
801832
}
802833

@@ -808,37 +839,39 @@ bool cbmc_parse_optionst::process_goto_program(
808839
label_properties(goto_model);
809840

810841
// reachability slice?
811-
if(cmdline.isset("reachability-slice-fb"))
842+
if(options.get_bool_option("reachability-slice-fb"))
812843
{
813-
if(cmdline.isset("reachability-slice"))
844+
if(options.get_bool_option("reachability-slice"))
814845
{
815-
error() << "--reachability-slice and --reachability-slice-fb "
816-
<< "must not be given together" << eom;
846+
log.error() << "--reachability-slice and --reachability-slice-fb "
847+
<< "must not be given together" << eom;
817848
return true;
818849
}
819850

820-
status() << "Performing a forwards-backwards reachability slice" << eom;
821-
if(cmdline.isset("property"))
822-
reachability_slicer(goto_model, cmdline.get_values("property"), true);
851+
log.status() << "Performing a forwards-backwards reachability slice"
852+
<< eom;
853+
if(options.is_set("property"))
854+
reachability_slicer(
855+
goto_model, options.get_list_option("property"), true);
823856
else
824857
reachability_slicer(goto_model, true);
825858
}
826859

827-
if(cmdline.isset("reachability-slice"))
860+
if(options.get_bool_option("reachability-slice"))
828861
{
829-
status() << "Performing a reachability slice" << eom;
830-
if(cmdline.isset("property"))
831-
reachability_slicer(goto_model, cmdline.get_values("property"));
862+
log.status() << "Performing a reachability slice" << eom;
863+
if(options.is_set("property"))
864+
reachability_slicer(goto_model, options.get_list_option("property"));
832865
else
833866
reachability_slicer(goto_model);
834867
}
835868

836869
// full slice?
837-
if(cmdline.isset("full-slice"))
870+
if(options.get_bool_option("full-slice"))
838871
{
839-
status() << "Performing a full slice" << eom;
840-
if(cmdline.isset("property"))
841-
property_slicer(goto_model, cmdline.get_values("property"));
872+
log.status() << "Performing a full slice" << eom;
873+
if(options.is_set("property"))
874+
property_slicer(goto_model, options.get_list_option("property"));
842875
else
843876
full_slicer(goto_model);
844877
}
@@ -849,25 +882,25 @@ bool cbmc_parse_optionst::process_goto_program(
849882

850883
catch(const char *e)
851884
{
852-
error() << e << eom;
885+
log.error() << e << eom;
853886
return true;
854887
}
855888

856889
catch(const std::string &e)
857890
{
858-
error() << e << eom;
891+
log.error() << e << eom;
859892
return true;
860893
}
861894

862895
catch(int e)
863896
{
864-
error() << "Numeric exception : " << e << eom;
897+
log.error() << "Numeric exception : " << e << eom;
865898
return true;
866899
}
867900

868901
catch(const std::bad_alloc &)
869902
{
870-
error() << "Out of memory" << eom;
903+
log.error() << "Out of memory" << eom;
871904
exit(CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY);
872905
return true;
873906
}

src/cbmc/cbmc_parse_options.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ class cbmc_parse_optionst:
9797
/// default behaviour, for example unit tests.
9898
static void set_default_options(optionst &);
9999

100+
static bool process_goto_program(goto_modelt &, const optionst &, messaget &);
101+
102+
static int get_goto_program(
103+
goto_modelt &,
104+
const optionst &,
105+
const cmdlinet &,
106+
messaget &,
107+
ui_message_handlert &);
108+
100109
protected:
101110
goto_modelt goto_model;
102111
ui_message_handlert ui_message_handler;
@@ -105,8 +114,6 @@ class cbmc_parse_optionst:
105114
void register_languages();
106115
void get_command_line_options(optionst &);
107116
void preprocessing();
108-
int get_goto_program(const optionst &);
109-
bool process_goto_program(const optionst &);
110117
bool set_properties();
111118
};
112119

0 commit comments

Comments
 (0)