Skip to content

Commit da41ae8

Browse files
authored
Merge pull request #643 from diffblue/property_checker
extract `property_checker` function
2 parents bbdb0b1 + 9babcdb commit da41ae8

File tree

7 files changed

+153
-96
lines changed

7 files changed

+153
-96
lines changed

src/ebmc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SRC = \
2222
neural_liveness.cpp \
2323
output_file.cpp \
2424
output_verilog.cpp \
25+
property_checker.cpp \
2526
random_traces.cpp \
2627
ranking_function.cpp \
2728
report_results.cpp \

src/ebmc/ebmc_base.cpp

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Author: Daniel Kroening, [email protected]
2323
#include <trans-word-level/trans_trace_word_level.h>
2424
#include <trans-word-level/unwind.h>
2525

26-
#include "bmc.h"
2726
#include "dimacs_writer.h"
2827
#include "ebmc_error.h"
2928
#include "ebmc_solver_factory.h"
@@ -470,95 +469,3 @@ int ebmc_baset::do_compute_ct()
470469

471470
return 0;
472471
}
473-
474-
/*******************************************************************\
475-
476-
Function: ebmc_baset::do_word_level_bmc
477-
478-
Inputs:
479-
480-
Outputs:
481-
482-
Purpose:
483-
484-
\*******************************************************************/
485-
486-
int ebmc_baset::do_word_level_bmc()
487-
{
488-
auto solver_factory = ebmc_solver_factory(cmdline);
489-
490-
bool convert_only = cmdline.isset("smt2") || cmdline.isset("outfile") ||
491-
cmdline.isset("show-formula");
492-
493-
int result = 0;
494-
495-
try
496-
{
497-
if(cmdline.isset("max-bound"))
498-
{
499-
if(convert_only)
500-
throw "please set a specific bound";
501-
502-
const std::size_t max_bound =
503-
unsafe_string2size_t(cmdline.get_value("max-bound"));
504-
505-
for(bound = 1; bound <= max_bound; bound++)
506-
{
507-
message.status() << "Doing BMC with bound " << bound << messaget::eom;
508-
509-
#if 0
510-
const namespacet ns(transition_system.symbol_table);
511-
CHECK_RETURN(trans_expr.has_value());
512-
::unwind(*trans_expr, *message_handler, solver, bound+1, ns, true);
513-
result=finish_word_level_bmc(solver);
514-
#endif
515-
}
516-
517-
const namespacet ns(transition_system.symbol_table);
518-
report_results(cmdline, properties, ns, message.get_message_handler());
519-
}
520-
else
521-
{
522-
if(get_bound())
523-
return 1;
524-
525-
if(!convert_only)
526-
if(properties.properties.empty())
527-
throw "no properties";
528-
529-
bmc(
530-
bound,
531-
convert_only,
532-
transition_system,
533-
properties,
534-
solver_factory,
535-
message.get_message_handler());
536-
537-
if(!convert_only)
538-
{
539-
const namespacet ns(transition_system.symbol_table);
540-
report_results(cmdline, properties, ns, message.get_message_handler());
541-
result = properties.exit_code();
542-
}
543-
}
544-
}
545-
546-
catch(const char *e)
547-
{
548-
message.error() << e << messaget::eom;
549-
return 10;
550-
}
551-
552-
catch(const std::string &e)
553-
{
554-
message.error() << e << messaget::eom;
555-
return 10;
556-
}
557-
558-
catch(int)
559-
{
560-
return 10;
561-
}
562-
563-
return result;
564-
}

src/ebmc/ebmc_base.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class ebmc_baset
6464
public:
6565
int do_compute_ct();
6666
int do_bit_level_bmc();
67-
int do_word_level_bmc();
6867
};
6968

7069
#endif

src/ebmc/ebmc_parse_options.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Author: Daniel Kroening, [email protected]
2222
#include "k_induction.h"
2323
#include "liveness_to_safety.h"
2424
#include "neural_liveness.h"
25+
#include "property_checker.h"
2526
#include "random_traces.h"
2627
#include "ranking_function.h"
2728
#include "show_trans.h"
@@ -306,7 +307,11 @@ int ebmc_parse_optionst::doit()
306307
if(cmdline.isset("aig") || cmdline.isset("dimacs"))
307308
return ebmc_base.do_bit_level_bmc();
308309
else
309-
return ebmc_base.do_word_level_bmc(); // default
310+
return property_checker(
311+
cmdline,
312+
ebmc_base.transition_system,
313+
ebmc_base.properties,
314+
ui_message_handler);
310315
}
311316
}
312317
catch(const ebmc_errort &ebmc_error)

src/ebmc/ebmc_solver_factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <solvers/decision_procedure.h>
1717
#include <solvers/prop/prop.h>
1818

19-
#include <iosfwd>
19+
#include <fstream>
2020
#include <memory>
2121

2222
class ebmc_solvert final

src/ebmc/property_checker.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*******************************************************************\
2+
3+
Module: EBMC Property Checker
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include "property_checker.h"
10+
11+
#include <util/string2int.h>
12+
13+
#include "bmc.h"
14+
#include "ebmc_error.h"
15+
#include "ebmc_solver_factory.h"
16+
#include "report_results.h"
17+
18+
int word_level_bmc(
19+
const cmdlinet &cmdline,
20+
const transition_systemt &transition_system,
21+
ebmc_propertiest &properties,
22+
message_handlert &message_handler)
23+
{
24+
auto solver_factory = ebmc_solver_factory(cmdline);
25+
26+
bool convert_only = cmdline.isset("smt2") || cmdline.isset("outfile") ||
27+
cmdline.isset("show-formula");
28+
29+
int result = 0;
30+
31+
try
32+
{
33+
if(cmdline.isset("max-bound"))
34+
{
35+
if(convert_only)
36+
throw ebmc_errort() << "please set a specific bound";
37+
38+
const std::size_t max_bound =
39+
unsafe_string2size_t(cmdline.get_value("max-bound"));
40+
41+
for(std::size_t bound = 1; bound <= max_bound; bound++)
42+
{
43+
messaget message{message_handler};
44+
message.status() << "Doing BMC with bound " << bound << messaget::eom;
45+
46+
#if 0
47+
const namespacet ns(transition_system.symbol_table);
48+
CHECK_RETURN(trans_expr.has_value());
49+
::unwind(*trans_expr, *message_handler, solver, bound+1, ns, true);
50+
result=finish_word_level_bmc(solver);
51+
#endif
52+
}
53+
54+
const namespacet ns(transition_system.symbol_table);
55+
report_results(cmdline, properties, ns, message_handler);
56+
}
57+
else
58+
{
59+
std::size_t bound;
60+
61+
if(cmdline.isset("bound"))
62+
{
63+
bound = unsafe_string2unsigned(cmdline.get_value("bound"));
64+
}
65+
else
66+
{
67+
messaget message{message_handler};
68+
message.warning() << "using default bound 1" << messaget::eom;
69+
bound = 1;
70+
}
71+
72+
if(!convert_only)
73+
if(properties.properties.empty())
74+
throw "no properties";
75+
76+
bmc(
77+
bound,
78+
convert_only,
79+
transition_system,
80+
properties,
81+
solver_factory,
82+
message_handler);
83+
84+
if(!convert_only)
85+
{
86+
const namespacet ns(transition_system.symbol_table);
87+
report_results(cmdline, properties, ns, message_handler);
88+
result = properties.exit_code();
89+
}
90+
}
91+
}
92+
93+
catch(const char *e)
94+
{
95+
messaget message{message_handler};
96+
message.error() << e << messaget::eom;
97+
return 10;
98+
}
99+
100+
catch(const std::string &e)
101+
{
102+
messaget message{message_handler};
103+
message.error() << e << messaget::eom;
104+
return 10;
105+
}
106+
107+
catch(int)
108+
{
109+
return 10;
110+
}
111+
112+
return result;
113+
}
114+
115+
int property_checker(
116+
const cmdlinet &cmdline,
117+
const transition_systemt &transition_system,
118+
ebmc_propertiest &properties,
119+
message_handlert &message_handler)
120+
{
121+
// default engine is word-level BMC
122+
return word_level_bmc(
123+
cmdline, transition_system, properties, message_handler);
124+
}

src/ebmc/property_checker.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*******************************************************************\
2+
3+
Module: EBMC Property Checker
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_EBMC_PROPERTY_CHECKER_H
10+
#define CPROVER_EBMC_PROPERTY_CHECKER_H
11+
12+
#include "ebmc_properties.h"
13+
#include "transition_system.h"
14+
15+
int property_checker(
16+
const cmdlinet &,
17+
const transition_systemt &,
18+
ebmc_propertiest &,
19+
message_handlert &);
20+
21+
#endif

0 commit comments

Comments
 (0)