Skip to content

Commit 9af0a1c

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 7f29b62 commit 9af0a1c

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

@@ -534,7 +552,8 @@ int cbmc_parse_optionst::doit()
534552
return CPROVER_EXIT_SUCCESS;
535553
}
536554

537-
int get_goto_program_ret=get_goto_program(options);
555+
int get_goto_program_ret =
556+
get_goto_program(goto_model, options, cmdline, *this, ui_message_handler);
538557

539558
if(get_goto_program_ret!=-1)
540559
return get_goto_program_ret;
@@ -587,25 +606,29 @@ bool cbmc_parse_optionst::set_properties()
587606
}
588607

589608
int cbmc_parse_optionst::get_goto_program(
590-
const optionst &options)
609+
goto_modelt &goto_model,
610+
const optionst &options,
611+
const cmdlinet &cmdline,
612+
messaget &log,
613+
ui_message_handlert &ui_message_handler)
591614
{
592615
if(cmdline.args.empty())
593616
{
594-
error() << "Please provide a program to verify" << eom;
617+
log.error() << "Please provide a program to verify" << log.eom;
595618
return CPROVER_EXIT_INCORRECT_TASK;
596619
}
597620

598621
try
599622
{
600-
goto_model=initialize_goto_model(cmdline, get_message_handler());
623+
goto_model = initialize_goto_model(cmdline, ui_message_handler);
601624

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

608-
if(process_goto_program(options))
631+
if(cbmc_parse_optionst::process_goto_program(goto_model, options, log))
609632
return CPROVER_EXIT_INTERNAL_ERROR;
610633

611634
// show it?
@@ -622,36 +645,36 @@ int cbmc_parse_optionst::get_goto_program(
622645
{
623646
show_goto_functions(
624647
goto_model,
625-
get_message_handler(),
648+
ui_message_handler,
626649
ui_message_handler.get_ui(),
627650
cmdline.isset("list-goto-functions"));
628651
return CPROVER_EXIT_SUCCESS;
629652
}
630653

631-
status() << config.object_bits_info() << eom;
654+
log.status() << config.object_bits_info() << log.eom;
632655
}
633656

634657
catch(const char *e)
635658
{
636-
error() << e << eom;
659+
log.error() << e << log.eom;
637660
return CPROVER_EXIT_EXCEPTION;
638661
}
639662

640663
catch(const std::string &e)
641664
{
642-
error() << e << eom;
665+
log.error() << e << log.eom;
643666
return CPROVER_EXIT_EXCEPTION;
644667
}
645668

646669
catch(int e)
647670
{
648-
error() << "Numeric exception : " << e << eom;
671+
log.error() << "Numeric exception : " << e << log.eom;
649672
return CPROVER_EXIT_EXCEPTION;
650673
}
651674

652675
catch(const std::bad_alloc &)
653676
{
654-
error() << "Out of memory" << eom;
677+
log.error() << "Out of memory" << log.eom;
655678
return CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY;
656679
}
657680

@@ -716,7 +739,9 @@ void cbmc_parse_optionst::preprocessing()
716739
}
717740

718741
bool cbmc_parse_optionst::process_goto_program(
719-
const optionst &options)
742+
goto_modelt &goto_model,
743+
const optionst &options,
744+
messaget &log)
720745
{
721746
try
722747
{
@@ -725,17 +750,17 @@ bool cbmc_parse_optionst::process_goto_program(
725750
remove_asm(goto_model);
726751

727752
// add the library
728-
link_to_library(goto_model, get_message_handler());
753+
link_to_library(goto_model, log.get_message_handler());
729754

730-
if(cmdline.isset("string-abstraction"))
731-
string_instrumentation(goto_model, get_message_handler());
755+
if(options.get_bool_option("string-abstraction"))
756+
string_instrumentation(goto_model, log.get_message_handler());
732757

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

@@ -751,27 +776,26 @@ bool cbmc_parse_optionst::process_goto_program(
751776
rewrite_union(goto_model);
752777

753778
// add generic checks
754-
status() << "Generic Property Instrumentation" << eom;
779+
log.status() << "Generic Property Instrumentation" << eom;
755780
goto_check(options, goto_model);
756781

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

760785
// ignore default/user-specified initialization
761786
// of variables with static lifetime
762-
if(cmdline.isset("nondet-static"))
787+
if(options.get_bool_option("nondet-static"))
763788
{
764-
status() << "Adding nondeterministic initialization "
765-
"of static/global variables" << eom;
789+
log.status() << "Adding nondeterministic initialization "
790+
"of static/global variables"
791+
<< eom;
766792
nondet_static(goto_model);
767793
}
768794

769-
if(cmdline.isset("string-abstraction"))
795+
if(options.get_bool_option("string-abstraction"))
770796
{
771-
status() << "String Abstraction" << eom;
772-
string_abstraction(
773-
goto_model,
774-
get_message_handler());
797+
log.status() << "String Abstraction" << eom;
798+
string_abstraction(goto_model, log.get_message_handler());
775799
}
776800

777801
// add failed symbols
@@ -784,21 +808,21 @@ bool cbmc_parse_optionst::process_goto_program(
784808
// add loop ids
785809
goto_model.goto_functions.compute_loop_numbers();
786810

787-
if(cmdline.isset("drop-unused-functions"))
811+
if(options.get_bool_option("drop-unused-functions"))
788812
{
789813
// Entry point will have been set before and function pointers removed
790-
status() << "Removing unused functions" << eom;
791-
remove_unused_functions(goto_model, get_message_handler());
814+
log.status() << "Removing unused functions" << eom;
815+
remove_unused_functions(goto_model, log.get_message_handler());
792816
}
793817

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

798822
// instrument cover goals
799-
if(cmdline.isset("cover"))
823+
if(options.is_set("cover"))
800824
{
801-
if(instrument_cover_goals(options, goto_model, get_message_handler()))
825+
if(instrument_cover_goals(options, goto_model, log.get_message_handler()))
802826
return true;
803827
}
804828

@@ -810,37 +834,39 @@ bool cbmc_parse_optionst::process_goto_program(
810834
label_properties(goto_model);
811835

812836
// reachability slice?
813-
if(cmdline.isset("reachability-slice-fb"))
837+
if(options.get_bool_option("reachability-slice-fb"))
814838
{
815-
if(cmdline.isset("reachability-slice"))
839+
if(options.get_bool_option("reachability-slice"))
816840
{
817-
error() << "--reachability-slice and --reachability-slice-fb "
818-
<< "must not be given together" << eom;
841+
log.error() << "--reachability-slice and --reachability-slice-fb "
842+
<< "must not be given together" << eom;
819843
return true;
820844
}
821845

822-
status() << "Performing a forwards-backwards reachability slice" << eom;
823-
if(cmdline.isset("property"))
824-
reachability_slicer(goto_model, cmdline.get_values("property"), true);
846+
log.status() << "Performing a forwards-backwards reachability slice"
847+
<< eom;
848+
if(options.is_set("property"))
849+
reachability_slicer(
850+
goto_model, options.get_list_option("property"), true);
825851
else
826852
reachability_slicer(goto_model, true);
827853
}
828854

829-
if(cmdline.isset("reachability-slice"))
855+
if(options.get_bool_option("reachability-slice"))
830856
{
831-
status() << "Performing a reachability slice" << eom;
832-
if(cmdline.isset("property"))
833-
reachability_slicer(goto_model, cmdline.get_values("property"));
857+
log.status() << "Performing a reachability slice" << eom;
858+
if(options.is_set("property"))
859+
reachability_slicer(goto_model, options.get_list_option("property"));
834860
else
835861
reachability_slicer(goto_model);
836862
}
837863

838864
// full slice?
839-
if(cmdline.isset("full-slice"))
865+
if(options.get_bool_option("full-slice"))
840866
{
841-
status() << "Performing a full slice" << eom;
842-
if(cmdline.isset("property"))
843-
property_slicer(goto_model, cmdline.get_values("property"));
867+
log.status() << "Performing a full slice" << eom;
868+
if(options.is_set("property"))
869+
property_slicer(goto_model, options.get_list_option("property"));
844870
else
845871
full_slicer(goto_model);
846872
}
@@ -851,25 +877,25 @@ bool cbmc_parse_optionst::process_goto_program(
851877

852878
catch(const char *e)
853879
{
854-
error() << e << eom;
880+
log.error() << e << eom;
855881
return true;
856882
}
857883

858884
catch(const std::string &e)
859885
{
860-
error() << e << eom;
886+
log.error() << e << eom;
861887
return true;
862888
}
863889

864890
catch(int e)
865891
{
866-
error() << "Numeric exception : " << e << eom;
892+
log.error() << "Numeric exception : " << e << eom;
867893
return true;
868894
}
869895

870896
catch(const std::bad_alloc &)
871897
{
872-
error() << "Out of memory" << eom;
898+
log.error() << "Out of memory" << eom;
873899
exit(CPROVER_EXIT_INTERNAL_OUT_OF_MEMORY);
874900
return true;
875901
}

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)