Skip to content

Commit 1a33c87

Browse files
committed
refactoring bmc.cpp
bmct::run is now split into: bmct::setup bmct::get_memory_model bmct::slice bmct::execute bmct::show This change is necessary for incremental checking
1 parent 1821b1a commit 1a33c87

File tree

2 files changed

+92
-76
lines changed

2 files changed

+92
-76
lines changed

src/cbmc/bmc.cpp

+84-75
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,10 @@ void bmct::show_program()
305305
}
306306
}
307307

308-
safety_checkert::resultt bmct::run(
309-
const goto_functionst &goto_functions)
308+
309+
void bmct::get_memory_model()
310310
{
311311
const std::string mm=options.get_option("mm");
312-
std::unique_ptr<memory_model_baset> memory_model;
313312

314313
if(mm.empty() || mm=="sc")
315314
memory_model=util_make_unique<memory_model_sct>(ns);
@@ -321,9 +320,13 @@ safety_checkert::resultt bmct::run(
321320
{
322321
error() << "Invalid memory model " << mm
323322
<< " -- use one of sc, tso, pso" << eom;
324-
return safety_checkert::resultt::ERROR;
323+
throw "invalid memory model";
325324
}
325+
}
326326

327+
void bmct::setup()
328+
{
329+
get_memory_model();
327330
symex.set_message_handler(get_message_handler());
328331
symex.options=options;
329332

@@ -337,11 +340,13 @@ safety_checkert::resultt bmct::run(
337340

338341
symex.last_source_location.make_nil();
339342

340-
try
341-
{
342-
// get unwinding info
343343
setup_unwind();
344+
}
344345

346+
safety_checkert::resultt bmct::execute(const goto_functionst &goto_functions)
347+
{
348+
try
349+
{
345350
// perform symbolic execution
346351
symex(goto_functions);
347352

@@ -351,77 +356,12 @@ safety_checkert::resultt bmct::run(
351356
memory_model->set_message_handler(get_message_handler());
352357
(*memory_model)(equation);
353358
}
354-
}
355-
356-
catch(const std::string &error_str)
357-
{
358-
messaget message(get_message_handler());
359-
message.error().source_location=symex.last_source_location;
360-
message.error() << error_str << messaget::eom;
361-
362-
return safety_checkert::resultt::ERROR;
363-
}
364-
365-
catch(const char *error_str)
366-
{
367-
messaget message(get_message_handler());
368-
message.error().source_location=symex.last_source_location;
369-
message.error() << error_str << messaget::eom;
370-
371-
return safety_checkert::resultt::ERROR;
372-
}
373-
374-
catch(const std::bad_alloc &)
375-
{
376-
error() << "Out of memory" << eom;
377-
return safety_checkert::resultt::ERROR;
378-
}
379359

380360
statistics() << "size of program expression: "
381361
<< equation.SSA_steps.size()
382362
<< " steps" << eom;
383363

384-
try
385-
{
386-
if(options.get_option("slice-by-trace")!="")
387-
{
388-
symex_slice_by_tracet symex_slice_by_trace(ns);
389-
390-
symex_slice_by_trace.slice_by_trace
391-
(options.get_option("slice-by-trace"), equation);
392-
}
393-
394-
if(equation.has_threads())
395-
{
396-
// we should build a thread-aware SSA slicer
397-
statistics() << "no slicing due to threads" << eom;
398-
}
399-
else
400-
{
401-
if(options.get_bool_option("slice-formula"))
402-
{
403-
slice(equation);
404-
statistics() << "slicing removed "
405-
<< equation.count_ignored_SSA_steps()
406-
<< " assignments" << eom;
407-
}
408-
else
409-
{
410-
if(options.get_list_option("cover").empty())
411-
{
412-
simple_slice(equation);
413-
statistics() << "simple slicing removed "
414-
<< equation.count_ignored_SSA_steps()
415-
<< " assignments" << eom;
416-
}
417-
}
418-
}
419-
420-
{
421-
statistics() << "Generated " << symex.total_vccs
422-
<< " VCC(s), " << symex.remaining_vccs
423-
<< " remaining after simplification" << eom;
424-
}
364+
slice();
425365

426366
// coverage report
427367
std::string cov_out=options.get_option("symex-coverage-report");
@@ -473,13 +413,19 @@ safety_checkert::resultt bmct::run(
473413

474414
catch(const std::string &error_str)
475415
{
476-
error() << error_str << eom;
416+
messaget message(get_message_handler());
417+
message.error().source_location=symex.last_source_location;
418+
message.error() << error_str << messaget::eom;
419+
477420
return safety_checkert::resultt::ERROR;
478421
}
479422

480423
catch(const char *error_str)
481424
{
482-
error() << error_str << eom;
425+
messaget message(get_message_handler());
426+
message.error().source_location=symex.last_source_location;
427+
message.error() << error_str << messaget::eom;
428+
483429
return safety_checkert::resultt::ERROR;
484430
}
485431

@@ -490,6 +436,56 @@ safety_checkert::resultt bmct::run(
490436
}
491437
}
492438

439+
void bmct::slice()
440+
{
441+
if(options.get_option("slice-by-trace")!="")
442+
{
443+
symex_slice_by_tracet symex_slice_by_trace(ns);
444+
445+
symex_slice_by_trace.slice_by_trace
446+
(options.get_option("slice-by-trace"),
447+
equation);
448+
}
449+
// any properties to check at all?
450+
if(equation.has_threads())
451+
{
452+
// we should build a thread-aware SSA slicer
453+
statistics() << "no slicing due to threads" << eom;
454+
}
455+
else
456+
{
457+
if(options.get_bool_option("slice-formula"))
458+
{
459+
::slice(equation);
460+
statistics() << "slicing removed "
461+
<< equation.count_ignored_SSA_steps()
462+
<< " assignments"<<eom;
463+
}
464+
else
465+
{
466+
if(options.get_list_option("cover").empty())
467+
{
468+
simple_slice(equation);
469+
statistics() << "simple slicing removed "
470+
<< equation.count_ignored_SSA_steps()
471+
<< " assignments"<<eom;
472+
}
473+
}
474+
}
475+
statistics() << "Generated "
476+
<< symex.total_vccs<<" VCC(s), "
477+
<< symex.remaining_vccs
478+
<< " remaining after simplification" << eom;
479+
}
480+
481+
safety_checkert::resultt bmct::run(
482+
const goto_functionst &goto_functions)
483+
{
484+
setup();
485+
486+
return execute(goto_functions);
487+
}
488+
493489
safety_checkert::resultt bmct::decide(
494490
const goto_functionst &goto_functions,
495491
prop_convt &prop_conv)
@@ -502,6 +498,19 @@ safety_checkert::resultt bmct::decide(
502498
return all_properties(goto_functions, prop_conv);
503499
}
504500

501+
void bmct::show(const goto_functionst &goto_functions)
502+
{
503+
if(options.get_bool_option("show-vcc"))
504+
{
505+
show_vcc();
506+
}
507+
508+
if(options.get_bool_option("program-only"))
509+
{
510+
show_program();
511+
}
512+
}
513+
505514
safety_checkert::resultt bmct::stop_on_fail(
506515
const goto_functionst &goto_functions,
507516
prop_convt &prop_conv)

src/cbmc/bmc.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Author: Daniel Kroening, [email protected]
2727

2828
#include <goto-symex/symex_target_equation.h>
2929
#include <goto-programs/safety_checker.h>
30+
#include <goto-symex/memory_model.h>
3031

3132
#include "symex_bmc.h"
3233

@@ -52,6 +53,8 @@ class bmct:public safety_checkert
5253
}
5354

5455
virtual resultt run(const goto_functionst &goto_functions);
56+
void setup();
57+
safety_checkert::resultt execute(const goto_functionst &);
5558
virtual ~bmct() { }
5659

5760
// additional stuff
@@ -73,7 +76,7 @@ class bmct:public safety_checkert
7376
symex_target_equationt equation;
7477
symex_bmct symex;
7578
prop_convt &prop_conv;
76-
79+
std::unique_ptr<memory_model_baset> memory_model;
7780
// use gui format
7881
ui_message_handlert::uit ui;
7982

@@ -108,6 +111,10 @@ class bmct:public safety_checkert
108111
resultt result,
109112
const goto_functionst &goto_functions);
110113

114+
void get_memory_model();
115+
void slice();
116+
void show(const goto_functionst &);
117+
111118
bool cover(
112119
const goto_functionst &goto_functions,
113120
const optionst::value_listt &criteria);

0 commit comments

Comments
 (0)