@@ -18,6 +18,19 @@ Module: State Encoding
18
18
19
19
#include < solvers/smt2/smt2_conv.h>
20
20
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
+
21
34
class state_typet : public typet
22
35
{
23
36
public:
@@ -34,7 +47,7 @@ mathematical_function_typet state_predicate_type()
34
47
class state_encodingt
35
48
{
36
49
public:
37
- void operator ()(const goto_functiont &, decision_proceduret &);
50
+ void operator ()(const goto_functiont &, encoding_targett &);
38
51
39
52
protected:
40
53
using loct = goto_programt::const_targett;
@@ -229,7 +242,7 @@ void state_encodingt::setup_incoming(const goto_functiont &goto_function)
229
242
230
243
void state_encodingt::operator ()(
231
244
const goto_functiont &goto_function,
232
- decision_proceduret &dest)
245
+ encoding_targett &dest)
233
246
{
234
247
if (goto_function.body .instructions .empty ())
235
248
return ;
@@ -399,79 +412,90 @@ void state_encodingt::operator()(
399
412
}
400
413
}
401
414
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)
403
419
{
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)
407
421
{
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);
408
427
}
409
428
else
410
429
{
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
+ }
412
441
}
413
442
}
414
443
415
- class smt2_encodert : public smt2_convt
444
+ class smt2_encoding_targett : public encoding_targett
416
445
{
417
446
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)
420
450
{
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 ;
423
453
}
424
- };
425
454
426
- class ascii_decision_proceduret : public decision_proceduret
427
- {
428
- public:
429
- ascii_decision_proceduret (std::ostream &__out) : out(__out)
455
+ ~smt2_encoding_targett ()
430
456
{
457
+ // finish the conversion to SMT-LIB2
458
+ smt2_conv ();
431
459
}
432
460
433
- void set_to ( const exprt & expr, bool value)
461
+ void set_to_true ( exprt expr) override
434
462
{
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));
440
464
}
441
465
442
- exprt handle (const exprt &)
466
+ void annotation (const std::string &text) override
443
467
{
444
- UNIMPLEMENTED ;
468
+ out << ' ; ' << ' ' << text << ' \n ' ;
445
469
}
446
470
447
- exprt get ( const exprt &) const
448
- {
449
- UNIMPLEMENTED ;
450
- }
471
+ protected:
472
+ std::ostream &out;
473
+ smt2_convt smt2_conv ;
474
+ };
451
475
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)
453
480
{
454
- UNIMPLEMENTED;
455
481
}
456
482
457
- std::string decision_procedure_text () const
483
+ void set_to_true (exprt expr) override
458
484
{
459
- UNIMPLEMENTED;
485
+ counter++;
486
+ if (counter < 10 )
487
+ out << ' ' ;
488
+ out << ' (' << counter << ' )' << ' ' ;
489
+ out << format (expr) << ' \n ' ;
460
490
}
461
491
462
- std::size_t get_number_of_solver_calls () const
492
+ void annotation ( const std::string &text) override
463
493
{
464
- UNIMPLEMENTED;
465
494
}
466
495
467
496
protected:
468
497
std::ostream &out;
469
498
std::size_t counter = 0 ;
470
-
471
- resultt dec_solve ()
472
- {
473
- UNIMPLEMENTED;
474
- }
475
499
};
476
500
477
501
static void format_hooks ()
@@ -514,6 +538,7 @@ static void format_hooks()
514
538
void state_encoding (
515
539
const goto_modelt &goto_model,
516
540
state_encoding_formatt state_encoding_format,
541
+ bool program_is_inlined,
517
542
std::ostream &out)
518
543
{
519
544
const namespacet ns (goto_model.symbol_table );
@@ -523,16 +548,15 @@ void state_encoding(
523
548
case state_encoding_formatt::ASCII:
524
549
{
525
550
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);
528
553
}
529
554
break ;
530
555
531
556
case state_encoding_formatt::SMT2:
532
557
{
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);
536
560
}
537
561
break ;
538
562
}
0 commit comments