12
12
13
13
#include " temporal_logic.h"
14
14
15
- static std::optional<exprt> is_state_formula (const exprt &expr)
15
+ static std::optional<exprt> is_state_predicate (const exprt &expr)
16
16
{
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 ();
21
19
else
22
20
return {};
23
21
}
@@ -30,8 +28,8 @@ exprt trivial_sva(exprt expr)
30
28
// Same as regular implication if lhs and rhs are not sequences.
31
29
auto &sva_implication = to_sva_overlapped_implication_expr (expr);
32
30
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 ());
35
33
36
34
if (lhs.has_value () && rhs.has_value ())
37
35
expr = implies_exprt{*lhs, *rhs};
@@ -50,23 +48,39 @@ exprt trivial_sva(exprt expr)
50
48
{
51
49
auto &sva_and = to_sva_and_expr (expr);
52
50
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
+ }
59
65
}
60
66
else if (expr.id () == ID_sva_or)
61
67
{
62
68
auto &sva_or = to_sva_or_expr (expr);
63
69
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
+ }
70
84
}
71
85
else if (expr.id () == ID_sva_not)
72
86
{
@@ -113,9 +127,10 @@ exprt trivial_sva(exprt expr)
113
127
{
114
128
// We simplify sequences to boolean expressions, and hence can drop
115
129
// 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;
119
134
}
120
135
121
136
return expr;
0 commit comments