11
11
12
12
#include " symex_target_equation.h"
13
13
14
+ #include < util/format_expr.h>
14
15
#include < util/std_expr.h>
16
+ #include < util/throw_with_nested.h>
17
+ #include < util/unwrap_nested_exception.h>
15
18
19
+ // Can be removed once deprecated SSA_stept::output is removed
16
20
#include < langapi/language_util.h>
17
- # include < solvers/prop/prop_conv.h >
18
- #include < solvers/prop/prop .h>
21
+
22
+ #include < solvers/flattening/bv_conversion_exceptions .h>
19
23
#include < solvers/prop/literal_expr.h>
24
+ #include < solvers/prop/prop.h>
25
+ #include < solvers/prop/prop_conv.h>
20
26
27
+ #include " equation_conversion_exceptions.h"
21
28
#include " goto_symex_state.h"
22
29
23
30
// / read from a shared variable
@@ -368,14 +375,23 @@ void symex_target_equationt::constraint(
368
375
void symex_target_equationt::convert (
369
376
prop_convt &prop_conv)
370
377
{
371
- convert_guards (prop_conv);
372
- convert_assignments (prop_conv);
373
- convert_decls (prop_conv);
374
- convert_assumptions (prop_conv);
375
- convert_assertions (prop_conv);
376
- convert_goto_instructions (prop_conv);
377
- convert_io (prop_conv);
378
- convert_constraints (prop_conv);
378
+ try
379
+ {
380
+ convert_guards (prop_conv);
381
+ convert_assignments (prop_conv);
382
+ convert_decls (prop_conv);
383
+ convert_assumptions (prop_conv);
384
+ convert_assertions (prop_conv);
385
+ convert_goto_instructions (prop_conv);
386
+ convert_io (prop_conv);
387
+ convert_constraints (prop_conv);
388
+ }
389
+ catch (const equation_conversion_exceptiont &conversion_exception)
390
+ {
391
+ // unwrap the except and throw like normal
392
+ const std::string full_error = unwrap_exception (conversion_exception);
393
+ throw full_error;
394
+ }
379
395
}
380
396
381
397
// / converts assignments
@@ -402,7 +418,16 @@ void symex_target_equationt::convert_decls(
402
418
{
403
419
// The result is not used, these have no impact on
404
420
// the satisfiability of the formula.
405
- prop_conv.convert (step.cond_expr );
421
+ try
422
+ {
423
+ prop_conv.convert (step.cond_expr );
424
+ }
425
+ catch (const bitvector_conversion_exceptiont &conversion_exception)
426
+ {
427
+ util_throw_with_nested (
428
+ equation_conversion_exceptiont (
429
+ " Error converting decls for step" , step));
430
+ }
406
431
}
407
432
}
408
433
}
@@ -417,7 +442,18 @@ void symex_target_equationt::convert_guards(
417
442
if (step.ignore )
418
443
step.guard_literal =const_literal (false );
419
444
else
420
- step.guard_literal =prop_conv.convert (step.guard );
445
+ {
446
+ try
447
+ {
448
+ step.guard_literal = prop_conv.convert (step.guard );
449
+ }
450
+ catch (const bitvector_conversion_exceptiont &conversion_exception)
451
+ {
452
+ util_throw_with_nested (
453
+ equation_conversion_exceptiont (
454
+ " Error converting guard for step" , step));
455
+ }
456
+ }
421
457
}
422
458
}
423
459
@@ -433,7 +469,18 @@ void symex_target_equationt::convert_assumptions(
433
469
if (step.ignore )
434
470
step.cond_literal =const_literal (true );
435
471
else
436
- step.cond_literal =prop_conv.convert (step.cond_expr );
472
+ {
473
+ try
474
+ {
475
+ step.cond_literal = prop_conv.convert (step.cond_expr );
476
+ }
477
+ catch (const bitvector_conversion_exceptiont &conversion_exception)
478
+ {
479
+ util_throw_with_nested (
480
+ equation_conversion_exceptiont (
481
+ " Error converting assumptions for step" , step));
482
+ }
483
+ }
437
484
}
438
485
}
439
486
}
@@ -450,7 +497,18 @@ void symex_target_equationt::convert_goto_instructions(
450
497
if (step.ignore )
451
498
step.cond_literal =const_literal (true );
452
499
else
453
- step.cond_literal =prop_conv.convert (step.cond_expr );
500
+ {
501
+ try
502
+ {
503
+ step.cond_literal = prop_conv.convert (step.cond_expr );
504
+ }
505
+ catch (const bitvector_conversion_exceptiont &conversion_exception)
506
+ {
507
+ util_throw_with_nested (
508
+ equation_conversion_exceptiont (
509
+ " Error converting goto instructions for step" , step));
510
+ }
511
+ }
454
512
}
455
513
}
456
514
}
@@ -519,7 +577,16 @@ void symex_target_equationt::convert_assertions(
519
577
step.cond_expr );
520
578
521
579
// do the conversion
522
- step.cond_literal =prop_conv.convert (implication);
580
+ try
581
+ {
582
+ step.cond_literal = prop_conv.convert (implication);
583
+ }
584
+ catch (const bitvector_conversion_exceptiont &conversion_exception)
585
+ {
586
+ util_throw_with_nested (
587
+ equation_conversion_exceptiont (
588
+ " Error converting assertions for step" , step));
589
+ }
523
590
524
591
// store disjunct
525
592
disjuncts.push_back (literal_exprt (!step.cond_literal ));
@@ -703,3 +770,118 @@ void symex_target_equationt::SSA_stept::output(
703
770
704
771
out << " Guard: " << from_expr (ns, source.pc ->function , guard) << ' \n ' ;
705
772
}
773
+
774
+ void symex_target_equationt::SSA_stept::output (std::ostream &out) const
775
+ {
776
+ if (source.is_set )
777
+ {
778
+ out << " Thread " << source.thread_nr ;
779
+
780
+ if (source.pc ->source_location .is_not_nil ())
781
+ out << " " << source.pc ->source_location << ' \n ' ;
782
+ else
783
+ out << ' \n ' ;
784
+ }
785
+
786
+ switch (type)
787
+ {
788
+ case goto_trace_stept::typet::ASSERT:
789
+ out << " ASSERT " << format (cond_expr) << ' \n ' ;
790
+ break ;
791
+ case goto_trace_stept::typet::ASSUME:
792
+ out << " ASSUME " << format (cond_expr) << ' \n ' ;
793
+ break ;
794
+ case goto_trace_stept::typet::LOCATION:
795
+ out << " LOCATION" << ' \n ' ;
796
+ break ;
797
+ case goto_trace_stept::typet::INPUT:
798
+ out << " INPUT" << ' \n ' ;
799
+ break ;
800
+ case goto_trace_stept::typet::OUTPUT:
801
+ out << " OUTPUT" << ' \n ' ;
802
+ break ;
803
+
804
+ case goto_trace_stept::typet::DECL:
805
+ out << " DECL" << ' \n ' ;
806
+ out << format (ssa_lhs) << ' \n ' ;
807
+ break ;
808
+
809
+ case goto_trace_stept::typet::ASSIGNMENT:
810
+ out << " ASSIGNMENT (" ;
811
+ switch (assignment_type)
812
+ {
813
+ case assignment_typet::HIDDEN:
814
+ out << " HIDDEN" ;
815
+ break ;
816
+ case assignment_typet::STATE:
817
+ out << " STATE" ;
818
+ break ;
819
+ case assignment_typet::VISIBLE_ACTUAL_PARAMETER:
820
+ out << " VISIBLE_ACTUAL_PARAMETER" ;
821
+ break ;
822
+ case assignment_typet::HIDDEN_ACTUAL_PARAMETER:
823
+ out << " HIDDEN_ACTUAL_PARAMETER" ;
824
+ break ;
825
+ case assignment_typet::PHI:
826
+ out << " PHI" ;
827
+ break ;
828
+ case assignment_typet::GUARD:
829
+ out << " GUARD" ;
830
+ break ;
831
+ default :
832
+ {
833
+ }
834
+ }
835
+
836
+ out << " )\n " ;
837
+ break ;
838
+
839
+ case goto_trace_stept::typet::DEAD:
840
+ out << " DEAD\n " ;
841
+ break ;
842
+ case goto_trace_stept::typet::FUNCTION_CALL:
843
+ out << " FUNCTION_CALL\n " ;
844
+ break ;
845
+ case goto_trace_stept::typet::FUNCTION_RETURN:
846
+ out << " FUNCTION_RETURN\n " ;
847
+ break ;
848
+ case goto_trace_stept::typet::CONSTRAINT:
849
+ out << " CONSTRAINT\n " ;
850
+ break ;
851
+ case goto_trace_stept::typet::SHARED_READ:
852
+ out << " SHARED READ\n " ;
853
+ break ;
854
+ case goto_trace_stept::typet::SHARED_WRITE:
855
+ out << " SHARED WRITE\n " ;
856
+ break ;
857
+ case goto_trace_stept::typet::ATOMIC_BEGIN:
858
+ out << " ATOMIC_BEGIN\n " ;
859
+ break ;
860
+ case goto_trace_stept::typet::ATOMIC_END:
861
+ out << " AUTOMIC_END\n " ;
862
+ break ;
863
+ case goto_trace_stept::typet::SPAWN:
864
+ out << " SPAWN\n " ;
865
+ break ;
866
+ case goto_trace_stept::typet::MEMORY_BARRIER:
867
+ out << " MEMORY_BARRIER\n " ;
868
+ break ;
869
+ case goto_trace_stept::typet::GOTO:
870
+ out << " IF " << format (cond_expr) << " GOTO\n " ;
871
+ break ;
872
+
873
+ default :
874
+ UNREACHABLE;
875
+ }
876
+
877
+ if (is_assert () || is_assume () || is_assignment () || is_constraint ())
878
+ out << format (cond_expr) << ' \n ' ;
879
+
880
+ if (is_assert () || is_constraint ())
881
+ out << comment << ' \n ' ;
882
+
883
+ if (is_shared_read () || is_shared_write ())
884
+ out << format (ssa_lhs) << ' \n ' ;
885
+
886
+ out << " Guard: " << format (guard) << ' \n ' ;
887
+ }
0 commit comments