Skip to content

Commit fc441a4

Browse files
committed
fx cprover
1 parent c81ef31 commit fc441a4

File tree

4 files changed

+85
-49
lines changed

4 files changed

+85
-49
lines changed

src/cprover/cprover_parse_options.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,15 @@ int cprover_parse_optionst::main()
9898
initialize_goto_model(cmdline.args, message_handler, options);
9999

100100
adjust_float_expressions(goto_model);
101-
goto_inline(goto_model, message_handler, true);
101+
102+
bool perform_inlining = true;
103+
104+
if(perform_inlining)
105+
{
106+
std::cout << "Performing inlining\n";
107+
goto_inline(goto_model, message_handler, true);
108+
}
109+
102110
goto_model.goto_functions.compute_location_numbers();
103111

104112
if(cmdline.isset("show-goto-functions"))
@@ -130,11 +138,11 @@ int cprover_parse_optionst::main()
130138
#else
131139
std::ofstream out(file_name);
132140
#endif
133-
state_encoding(goto_model, format, out);
141+
state_encoding(goto_model, format, perform_inlining, out);
134142
std::cout << "formula written to " << file_name << '\n';
135143
}
136144
else
137-
state_encoding(goto_model, format, std::cout);
145+
state_encoding(goto_model, format, perform_inlining, std::cout);
138146

139147
return CPROVER_EXIT_SUCCESS;
140148
}
@@ -165,7 +173,9 @@ void cprover_parse_optionst::help()
165173
" {bcprover} {usource-file.c} \t convert a given C program\n"
166174
"\n"
167175
"Other options:\n"
168-
" {y--smt2} \t output formula in SMT-LIB2 format\n"
176+
" {y--inline} \t perform function call inlining before\n"
177+
" \t generating the formula\n"
169178
" {y--outfile} {ufile-name} \t set output file for formula\n"
179+
" {y--smt2} \t output formula in SMT-LIB2 format\n"
170180
"\n");
171181
}

src/cprover/cprover_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#define CPROVER_OPTIONS \
1818
"(help)?h(version)" \
1919
"(smt2)(outfile):" \
20+
"(inline)" \
2021
"(show-goto-functions)(show-loops)" \
2122
"(validate-goto-model)" \
2223
"(verbose)"

src/cprover/state_encoding.cpp

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ Module: State Encoding
1818

1919
#include <solvers/smt2/smt2_conv.h>
2020

21+
class encoding_targett
22+
{
23+
public:
24+
virtual void annotation(const std::string &) = 0;
25+
virtual void set_to_true(exprt) = 0;
26+
virtual ~encoding_targett() = default;
27+
};
28+
29+
void operator<<(encoding_targett &target, exprt constraint)
30+
{
31+
target.set_to_true(std::move(constraint));
32+
}
33+
2134
class state_typet : public typet
2235
{
2336
public:
@@ -34,7 +47,7 @@ mathematical_function_typet state_predicate_type()
3447
class state_encodingt
3548
{
3649
public:
37-
void operator()(const goto_functiont &, decision_proceduret &);
50+
void operator()(const goto_functiont &, encoding_targett &);
3851

3952
protected:
4053
using loct = goto_programt::const_targett;
@@ -229,7 +242,7 @@ void state_encodingt::setup_incoming(const goto_functiont &goto_function)
229242

230243
void state_encodingt::operator()(
231244
const goto_functiont &goto_function,
232-
decision_proceduret &dest)
245+
encoding_targett &dest)
233246
{
234247
if(goto_function.body.instructions.empty())
235248
return;
@@ -399,79 +412,90 @@ void state_encodingt::operator()(
399412
}
400413
}
401414

402-
void state_encoding(const goto_modelt &goto_model, decision_proceduret &dest)
415+
void state_encoding(
416+
const goto_modelt &goto_model,
417+
bool program_is_inlined,
418+
encoding_targett &dest)
403419
{
404-
auto f_entry =
405-
goto_model.goto_functions.function_map.find(goto_functionst::entry_point());
406-
if(f_entry == goto_model.goto_functions.function_map.end())
420+
if(program_is_inlined)
407421
{
422+
auto f_entry = goto_model.goto_functions.function_map.find(
423+
goto_functionst::entry_point());
424+
PRECONDITION(f_entry != goto_model.goto_functions.function_map.end());
425+
426+
state_encodingt{}(f_entry->second, dest);
408427
}
409428
else
410429
{
411-
state_encodingt{}(f_entry->second, dest);
430+
// output alphabetically
431+
const auto sorted = goto_model.goto_functions.sorted();
432+
433+
for(const auto &f : sorted)
434+
{
435+
if(f->second.body_available())
436+
{
437+
dest.annotation("function " + id2string(f->first));
438+
state_encodingt{}(f->second, dest);
439+
}
440+
}
412441
}
413442
}
414443

415-
class smt2_encodert : public smt2_convt
444+
class smt2_encoding_targett : public encoding_targett
416445
{
417446
public:
418-
smt2_encodert(const namespacet &ns, std::ostream &out)
419-
: smt2_convt(ns, "", "cprover", "", solvert::GENERIC, out)
447+
smt2_encoding_targett(const namespacet &ns, std::ostream &__out)
448+
: out(__out),
449+
smt2_conv(ns, "", "cprover", "", smt2_convt::solvert::GENERIC, out)
420450
{
421-
use_array_of_bool = true;
422-
use_as_const = true;
451+
smt2_conv.use_array_of_bool = true;
452+
smt2_conv.use_as_const = true;
423453
}
424-
};
425454

426-
class ascii_decision_proceduret : public decision_proceduret
427-
{
428-
public:
429-
ascii_decision_proceduret(std::ostream &__out) : out(__out)
455+
~smt2_encoding_targett()
430456
{
457+
// finish the conversion to SMT-LIB2
458+
smt2_conv();
431459
}
432460

433-
void set_to(const exprt &expr, bool value)
461+
void set_to_true(exprt expr) override
434462
{
435-
counter++;
436-
if(counter < 10)
437-
out << ' ';
438-
out << '(' << counter << ')' << ' ';
439-
out << format(expr) << '\n';
463+
smt2_conv.set_to_true(std::move(expr));
440464
}
441465

442-
exprt handle(const exprt &)
466+
void annotation(const std::string &text) override
443467
{
444-
UNIMPLEMENTED;
468+
out << ';' << ' ' << text << '\n';
445469
}
446470

447-
exprt get(const exprt &) const
448-
{
449-
UNIMPLEMENTED;
450-
}
471+
protected:
472+
std::ostream &out;
473+
smt2_convt smt2_conv;
474+
};
451475

452-
void print_assignment(std::ostream &) const
476+
class ascii_encoding_targett : public encoding_targett
477+
{
478+
public:
479+
explicit ascii_encoding_targett(std::ostream &__out) : out(__out)
453480
{
454-
UNIMPLEMENTED;
455481
}
456482

457-
std::string decision_procedure_text() const
483+
void set_to_true(exprt expr) override
458484
{
459-
UNIMPLEMENTED;
485+
counter++;
486+
if(counter < 10)
487+
out << ' ';
488+
out << '(' << counter << ')' << ' ';
489+
out << format(expr) << '\n';
460490
}
461491

462-
std::size_t get_number_of_solver_calls() const
492+
void annotation(const std::string &text) override
463493
{
464-
UNIMPLEMENTED;
465494
}
466495

467496
protected:
468497
std::ostream &out;
469498
std::size_t counter = 0;
470-
471-
resultt dec_solve()
472-
{
473-
UNIMPLEMENTED;
474-
}
475499
};
476500

477501
static void format_hooks()
@@ -514,6 +538,7 @@ static void format_hooks()
514538
void state_encoding(
515539
const goto_modelt &goto_model,
516540
state_encoding_formatt state_encoding_format,
541+
bool program_is_inlined,
517542
std::ostream &out)
518543
{
519544
const namespacet ns(goto_model.symbol_table);
@@ -523,16 +548,15 @@ void state_encoding(
523548
case state_encoding_formatt::ASCII:
524549
{
525550
format_hooks();
526-
ascii_decision_proceduret dest(out);
527-
state_encoding(goto_model, dest);
551+
ascii_encoding_targett dest(out);
552+
state_encoding(goto_model, program_is_inlined, dest);
528553
}
529554
break;
530555

531556
case state_encoding_formatt::SMT2:
532557
{
533-
smt2_encodert dest(ns, out);
534-
state_encoding(goto_model, dest);
535-
dest(); // finish conversion
558+
smt2_encoding_targett dest(ns, out);
559+
state_encoding(goto_model, program_is_inlined, dest);
536560
}
537561
break;
538562
}

src/cprover/state_encoding.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum class state_encoding_formatt
2525
void state_encoding(
2626
const goto_modelt &,
2727
state_encoding_formatt,
28+
bool program_is_inlined,
2829
std::ostream &out);
2930

3031
#endif // CPROVER_GOTO_INSTRUMENT_STATE_ENCODING_H

0 commit comments

Comments
 (0)