Skip to content

Commit b7b9ad9

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 b7b9ad9

File tree

2 files changed

+86
-53
lines changed

2 files changed

+86
-53
lines changed

src/cbmc/cbmc_parse_options.cpp

Lines changed: 77 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
165165
if(cmdline.isset("cpp11"))
166166
config.cpp.set_cpp11();
167167

168+
if(cmdline.isset("property"))
169+
options.set_option("property", cmdline.get_values("property"));
170+
171+
if(cmdline.isset("reachability-slice-fb"))
172+
options.set_option("reachability-slice-fb", true);
173+
174+
if(cmdline.isset("reachability-slice"))
175+
options.set_option("reachability-slice", true);
176+
177+
if(cmdline.isset("bounds-check"))
178+
options.set_option("bounds-check", true);
179+
180+
if(cmdline.isset("pointer-check"))
181+
options.set_option("pointer-check", true);
182+
183+
if(cmdline.isset("nondet-static"))
184+
options.set_option("nondet-static", true);
185+
168186
if(cmdline.isset("no-simplify"))
169187
options.set_option("simplify", false);
170188

@@ -532,7 +550,8 @@ int cbmc_parse_optionst::doit()
532550
return CPROVER_EXIT_SUCCESS;
533551
}
534552

535-
int get_goto_program_ret=get_goto_program(options);
553+
int get_goto_program_ret =
554+
get_goto_program(goto_model, options, cmdline, *this, ui_message_handler);
536555

537556
if(get_goto_program_ret!=-1)
538557
return get_goto_program_ret;
@@ -585,25 +604,29 @@ bool cbmc_parse_optionst::set_properties()
585604
}
586605

587606
int cbmc_parse_optionst::get_goto_program(
588-
const optionst &options)
607+
goto_modelt &goto_model,
608+
const optionst &options,
609+
const cmdlinet &cmdline,
610+
messaget &log,
611+
ui_message_handlert &ui_message_handler)
589612
{
590613
if(cmdline.args.empty())
591614
{
592-
error() << "Please provide a program to verify" << eom;
615+
log.error() << "Please provide a program to verify" << log.eom;
593616
return CPROVER_EXIT_INCORRECT_TASK;
594617
}
595618

596619
try
597620
{
598-
goto_model=initialize_goto_model(cmdline, get_message_handler());
621+
goto_model = initialize_goto_model(cmdline, ui_message_handler);
599622

600623
if(cmdline.isset("show-symbol-table"))
601624
{
602625
show_symbol_table(goto_model, ui_message_handler.get_ui());
603626
return CPROVER_EXIT_SUCCESS;
604627
}
605628

606-
if(process_goto_program(options))
629+
if(cbmc_parse_optionst::process_goto_program(goto_model, options, log))
607630
return CPROVER_EXIT_INTERNAL_ERROR;
608631

609632
// show it?
@@ -620,36 +643,36 @@ int cbmc_parse_optionst::get_goto_program(
620643
{
621644
show_goto_functions(
622645
goto_model,
623-
get_message_handler(),
646+
ui_message_handler,
624647
ui_message_handler.get_ui(),
625648
cmdline.isset("list-goto-functions"));
626649
return CPROVER_EXIT_SUCCESS;
627650
}
628651

629-
status() << config.object_bits_info() << eom;
652+
log.status() << config.object_bits_info() << log.eom;
630653
}
631654

632655
catch(const char *e)
633656
{
634-
error() << e << eom;
657+
log.error() << e << log.eom;
635658
return CPROVER_EXIT_EXCEPTION;
636659
}
637660

638661
catch(const std::string &e)
639662
{
640-
error() << e << eom;
663+
log.error() << e << log.eom;
641664
return CPROVER_EXIT_EXCEPTION;
642665
}
643666

644667
catch(int e)
645668
{
646-
error() << "Numeric exception : " << e << eom;
669+
log.error() << "Numeric exception : " << e << log.eom;
647670
return CPROVER_EXIT_EXCEPTION;
648671
}
649672

650673
catch(const std::bad_alloc &)
651674
{
652-
error() << "Out of memory" << eom;
675+
log.error() << "Out of memory" << log.eom;
653676
return CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY;
654677
}
655678

@@ -714,7 +737,9 @@ void cbmc_parse_optionst::preprocessing()
714737
}
715738

716739
bool cbmc_parse_optionst::process_goto_program(
717-
const optionst &options)
740+
goto_modelt &goto_model,
741+
const optionst &options,
742+
messaget &log)
718743
{
719744
try
720745
{
@@ -723,17 +748,17 @@ bool cbmc_parse_optionst::process_goto_program(
723748
remove_asm(goto_model);
724749

725750
// add the library
726-
link_to_library(goto_model, get_message_handler());
751+
link_to_library(goto_model, log.get_message_handler());
727752

728-
if(cmdline.isset("string-abstraction"))
729-
string_instrumentation(goto_model, get_message_handler());
753+
if(options.get_bool_option("string-abstraction"))
754+
string_instrumentation(goto_model, log.get_message_handler());
730755

731756
// remove function pointers
732-
status() << "Removal of function pointers and virtual functions" << eom;
757+
log.status() << "Removal of function pointers and virtual functions" << eom;
733758
remove_function_pointers(
734-
get_message_handler(),
759+
log.get_message_handler(),
735760
goto_model,
736-
cmdline.isset("pointer-check"));
761+
options.get_bool_option("pointer-check"));
737762
// remove catch and throw (introduces instanceof)
738763
remove_exceptions(goto_model);
739764

@@ -749,27 +774,26 @@ bool cbmc_parse_optionst::process_goto_program(
749774
rewrite_union(goto_model);
750775

751776
// add generic checks
752-
status() << "Generic Property Instrumentation" << eom;
777+
log.status() << "Generic Property Instrumentation" << eom;
753778
goto_check(options, goto_model);
754779

755780
// checks don't know about adjusted float expressions
756781
adjust_float_expressions(goto_model);
757782

758783
// ignore default/user-specified initialization
759784
// of variables with static lifetime
760-
if(cmdline.isset("nondet-static"))
785+
if(options.get_bool_option("nondet-static"))
761786
{
762-
status() << "Adding nondeterministic initialization "
763-
"of static/global variables" << eom;
787+
log.status() << "Adding nondeterministic initialization "
788+
"of static/global variables"
789+
<< eom;
764790
nondet_static(goto_model);
765791
}
766792

767-
if(cmdline.isset("string-abstraction"))
793+
if(options.get_bool_option("string-abstraction"))
768794
{
769-
status() << "String Abstraction" << eom;
770-
string_abstraction(
771-
goto_model,
772-
get_message_handler());
795+
log.status() << "String Abstraction" << eom;
796+
string_abstraction(goto_model, log.get_message_handler());
773797
}
774798

775799
// add failed symbols
@@ -782,21 +806,21 @@ bool cbmc_parse_optionst::process_goto_program(
782806
// add loop ids
783807
goto_model.goto_functions.compute_loop_numbers();
784808

785-
if(cmdline.isset("drop-unused-functions"))
809+
if(options.get_bool_option("drop-unused-functions"))
786810
{
787811
// 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());
812+
log.status() << "Removing unused functions" << eom;
813+
remove_unused_functions(goto_model, log.get_message_handler());
790814
}
791815

792816
// remove skips such that trivial GOTOs are deleted and not considered
793817
// for coverage annotation:
794818
remove_skip(goto_model);
795819

796820
// instrument cover goals
797-
if(cmdline.isset("cover"))
821+
if(options.is_set("cover"))
798822
{
799-
if(instrument_cover_goals(options, goto_model, get_message_handler()))
823+
if(instrument_cover_goals(options, goto_model, log.get_message_handler()))
800824
return true;
801825
}
802826

@@ -808,37 +832,39 @@ bool cbmc_parse_optionst::process_goto_program(
808832
label_properties(goto_model);
809833

810834
// reachability slice?
811-
if(cmdline.isset("reachability-slice-fb"))
835+
if(options.get_bool_option("reachability-slice-fb"))
812836
{
813-
if(cmdline.isset("reachability-slice"))
837+
if(options.get_bool_option("reachability-slice"))
814838
{
815-
error() << "--reachability-slice and --reachability-slice-fb "
816-
<< "must not be given together" << eom;
839+
log.error() << "--reachability-slice and --reachability-slice-fb "
840+
<< "must not be given together" << eom;
817841
return true;
818842
}
819843

820-
status() << "Performing a forwards-backwards reachability slice" << eom;
821-
if(cmdline.isset("property"))
822-
reachability_slicer(goto_model, cmdline.get_values("property"), true);
844+
log.status() << "Performing a forwards-backwards reachability slice"
845+
<< eom;
846+
if(options.is_set("property"))
847+
reachability_slicer(
848+
goto_model, options.get_list_option("property"), true);
823849
else
824850
reachability_slicer(goto_model, true);
825851
}
826852

827-
if(cmdline.isset("reachability-slice"))
853+
if(options.get_bool_option("reachability-slice"))
828854
{
829-
status() << "Performing a reachability slice" << eom;
830-
if(cmdline.isset("property"))
831-
reachability_slicer(goto_model, cmdline.get_values("property"));
855+
log.status() << "Performing a reachability slice" << eom;
856+
if(options.is_set("property"))
857+
reachability_slicer(goto_model, options.get_list_option("property"));
832858
else
833859
reachability_slicer(goto_model);
834860
}
835861

836862
// full slice?
837-
if(cmdline.isset("full-slice"))
863+
if(options.get_bool_option("full-slice"))
838864
{
839-
status() << "Performing a full slice" << eom;
840-
if(cmdline.isset("property"))
841-
property_slicer(goto_model, cmdline.get_values("property"));
865+
log.status() << "Performing a full slice" << eom;
866+
if(options.is_set("property"))
867+
property_slicer(goto_model, options.get_list_option("property"));
842868
else
843869
full_slicer(goto_model);
844870
}
@@ -849,25 +875,25 @@ bool cbmc_parse_optionst::process_goto_program(
849875

850876
catch(const char *e)
851877
{
852-
error() << e << eom;
878+
log.error() << e << eom;
853879
return true;
854880
}
855881

856882
catch(const std::string &e)
857883
{
858-
error() << e << eom;
884+
log.error() << e << eom;
859885
return true;
860886
}
861887

862888
catch(int e)
863889
{
864-
error() << "Numeric exception : " << e << eom;
890+
log.error() << "Numeric exception : " << e << eom;
865891
return true;
866892
}
867893

868894
catch(const std::bad_alloc &)
869895
{
870-
error() << "Out of memory" << eom;
896+
log.error() << "Out of memory" << eom;
871897
exit(CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY);
872898
return true;
873899
}

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)