@@ -12,12 +12,10 @@ Author: Daniel Kroening, dkr@amazon.com
1212
1313#include " temporal_logic.h"
1414
15- static std::optional<exprt> is_state_formula (const exprt &expr)
15+ static std::optional<exprt> is_state_predicate (const exprt &expr)
1616{
17- if (expr.id () == ID_typecast && expr.type ().id () == ID_verilog_sva_sequence)
18- return to_typecast_expr (expr).op ();
19- else if (expr.type ().id () == ID_bool)
20- return expr;
17+ if (expr.id () == ID_sva_boolean)
18+ return to_sva_boolean_expr (expr).op ();
2119 else
2220 return {};
2321}
@@ -30,8 +28,8 @@ exprt trivial_sva(exprt expr)
3028 // Same as regular implication if lhs and rhs are not sequences.
3129 auto &sva_implication = to_sva_overlapped_implication_expr (expr);
3230
33- auto lhs = is_state_formula (sva_implication.lhs ());
34- auto rhs = is_state_formula (sva_implication.rhs ());
31+ auto lhs = is_state_predicate (sva_implication.lhs ());
32+ auto rhs = is_state_predicate (sva_implication.rhs ());
3533
3634 if (lhs.has_value () && rhs.has_value ())
3735 expr = implies_exprt{*lhs, *rhs};
@@ -50,23 +48,39 @@ exprt trivial_sva(exprt expr)
5048 {
5149 auto &sva_and = to_sva_and_expr (expr);
5250
53- // Same as a ∧ b if the expression is not a sequence.
54- auto lhs = is_state_formula (sva_and.lhs ());
55- auto rhs = is_state_formula (sva_and.rhs ());
56-
57- if (lhs.has_value () && rhs.has_value ())
58- expr = and_exprt{*lhs, *rhs};
51+ // can be sequence or property
52+ if (expr.type ().id () == ID_verilog_sva_sequence)
53+ {
54+ // Same as a ∧ b if the expression is not a sequence.
55+ auto lhs = is_state_predicate (sva_and.lhs ());
56+ auto rhs = is_state_predicate (sva_and.rhs ());
57+
58+ if (lhs.has_value () && rhs.has_value ())
59+ expr = sva_boolean_exprt{and_exprt{*lhs, *rhs}, expr.type ()};
60+ }
61+ else
62+ {
63+ expr = and_exprt{sva_and.lhs (), sva_and.rhs ()};
64+ }
5965 }
6066 else if (expr.id () == ID_sva_or)
6167 {
6268 auto &sva_or = to_sva_or_expr (expr);
6369
64- // Same as a ∨ b if the expression is not a sequence.
65- auto lhs = is_state_formula (sva_or.lhs ());
66- auto rhs = is_state_formula (sva_or.rhs ());
67-
68- if (lhs.has_value () && rhs.has_value ())
69- expr = or_exprt{*lhs, *rhs};
70+ // can be sequence or property
71+ if (expr.type ().id () == ID_verilog_sva_sequence)
72+ {
73+ // Same as a ∨ b if the expression is not a sequence.
74+ auto lhs = is_state_predicate (sva_or.lhs ());
75+ auto rhs = is_state_predicate (sva_or.rhs ());
76+
77+ if (lhs.has_value () && rhs.has_value ())
78+ expr = sva_boolean_exprt{or_exprt{*lhs, *rhs}, expr.type ()};
79+ }
80+ else
81+ {
82+ expr = or_exprt{sva_or.lhs (), sva_or.rhs ()};
83+ }
7084 }
7185 else if (expr.id () == ID_sva_not)
7286 {
@@ -113,9 +127,10 @@ exprt trivial_sva(exprt expr)
113127 {
114128 // We simplify sequences to boolean expressions, and hence can drop
115129 // the sva_sequence_property converter
116- auto &op = to_sva_sequence_property_expr_base (expr).sequence ();
117- if (op.type ().id () == ID_bool)
118- return op;
130+ auto &sequence = to_sva_sequence_property_expr_base (expr).sequence ();
131+ auto pred_opt = is_state_predicate (sequence);
132+ if (pred_opt.has_value ())
133+ return *pred_opt;
119134 }
120135
121136 return expr;
0 commit comments