Skip to content

Commit 1194d7a

Browse files
authored
Merge pull request #1062 from diffblue/sva_sequence_property_expr_baset
`sva_sequence_property_expr_baset`
2 parents bb675f6 + 2555bf0 commit 1194d7a

File tree

4 files changed

+58
-32
lines changed

4 files changed

+58
-32
lines changed

Diff for: src/temporal-logic/trivial_sva.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ exprt trivial_sva(exprt expr)
111111
{
112112
// We simplify sequences to boolean expressions, and hence can drop
113113
// the sva_sequence_property converter
114-
auto &op = to_sva_sequence_property_expr(expr).op();
114+
auto &op = to_sva_sequence_property_expr(expr).sequence();
115115
if(op.type().id() == ID_bool)
116116
return op;
117117
}

Diff for: src/trans-word-level/property.cpp

+4-21
Original file line numberDiff line numberDiff line change
@@ -507,25 +507,6 @@ static obligationst property_obligations_rec(
507507
std::max(obligations_true.first, obligations_false.first),
508508
if_exprt{cond, obligations_true.second, obligations_false.second}};
509509
}
510-
else if(property_expr.id() == ID_sva_sequence_property)
511-
{
512-
// Sequences can be used as property, and evaluate to true
513-
// when there is at least one match.
514-
auto &sequence = to_sva_sequence_property_expr(property_expr).op();
515-
auto matches = instantiate_sequence(sequence, current, no_timeframes);
516-
517-
exprt::operandst disjuncts;
518-
disjuncts.reserve(matches.size());
519-
mp_integer max = current;
520-
521-
for(auto &match : matches)
522-
{
523-
disjuncts.push_back(match.condition);
524-
max = std::max(max, match.end_time);
525-
}
526-
527-
return obligationst{max, disjunction(disjuncts)};
528-
}
529510
else if(
530511
property_expr.id() == ID_typecast &&
531512
to_typecast_expr(property_expr).op().type().id() == ID_bool)
@@ -665,9 +646,11 @@ static obligationst property_obligations_rec(
665646
return obligationst{t, disjunction(disjuncts)};
666647
}
667648
else if(
668-
property_expr.id() == ID_sva_strong || property_expr.id() == ID_sva_weak)
649+
property_expr.id() == ID_sva_strong || property_expr.id() == ID_sva_weak ||
650+
property_expr.id() == ID_sva_sequence_property)
669651
{
670-
auto &sequence = to_unary_expr(property_expr).op();
652+
auto &sequence =
653+
to_sva_sequence_property_expr_base(property_expr).sequence();
671654

672655
// sequence expressions -- these may have multiple potential
673656
// match points, and evaluate to true if any of them matches

Diff for: src/verilog/expr2verilog.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ expr2verilogt::resultt expr2verilogt::convert_sva_unary(
537537
if(op.id() == ID_typecast)
538538
op_operands = to_typecast_expr(op).op().operands().size();
539539
else if(src.op().id() == ID_sva_sequence_property)
540-
op_operands = to_sva_sequence_property_expr(op).op().operands().size();
540+
op_operands =
541+
to_sva_sequence_property_expr(op).sequence().operands().size();
541542
else
542543
op_operands = op.operands().size();
543544

@@ -1816,7 +1817,7 @@ expr2verilogt::resultt expr2verilogt::convert_rec(const exprt &src)
18161817
return convert_function("weak", src);
18171818

18181819
else if(src.id() == ID_sva_sequence_property)
1819-
return convert_rec(to_sva_sequence_property_expr(src).op());
1820+
return convert_rec(to_sva_sequence_property_expr(src).sequence());
18201821

18211822
else if(src.id()==ID_sva_sequence_concatenation)
18221823
return convert_sva_sequence_concatenation(

Diff for: src/verilog/sva_expr.h

+50-8
Original file line numberDiff line numberDiff line change
@@ -1111,44 +1111,86 @@ static inline sva_if_exprt &to_sva_if_expr(exprt &expr)
11111111
return static_cast<sva_if_exprt &>(expr);
11121112
}
11131113

1114-
class sva_strong_exprt : public unary_exprt
1114+
/// Base class for sequence property expressions.
1115+
/// 1800-2017 16.12.2 Sequence property
1116+
class sva_sequence_property_expr_baset : public unary_predicate_exprt
1117+
{
1118+
public:
1119+
sva_sequence_property_expr_baset(irep_idt __id, exprt __op)
1120+
: unary_predicate_exprt(__id, std::move(__op))
1121+
{
1122+
}
1123+
1124+
const exprt &sequence() const
1125+
{
1126+
return op();
1127+
}
1128+
1129+
exprt &sequence()
1130+
{
1131+
return op();
1132+
}
1133+
1134+
protected:
1135+
using unary_predicate_exprt::op;
1136+
};
1137+
1138+
inline const sva_sequence_property_expr_baset &
1139+
to_sva_sequence_property_expr_base(const exprt &expr)
1140+
{
1141+
sva_sequence_property_expr_baset::check(expr);
1142+
return static_cast<const sva_sequence_property_expr_baset &>(expr);
1143+
}
1144+
1145+
inline sva_sequence_property_expr_baset &
1146+
to_sva_sequence_property_base_expr(exprt &expr)
1147+
{
1148+
sva_sequence_property_expr_baset::check(expr);
1149+
return static_cast<sva_sequence_property_expr_baset &>(expr);
1150+
}
1151+
1152+
class sva_strong_exprt : public sva_sequence_property_expr_baset
11151153
{
11161154
public:
1117-
sva_strong_exprt(exprt __op, typet __type)
1118-
: unary_exprt(ID_sva_strong, std::move(__op), std::move(__type))
1155+
sva_strong_exprt(exprt __op)
1156+
: sva_sequence_property_expr_baset(ID_sva_strong, std::move(__op))
11191157
{
11201158
}
11211159
};
11221160

11231161
inline const sva_strong_exprt &to_sva_strong_expr(const exprt &expr)
11241162
{
1163+
PRECONDITION(expr.id() == ID_sva_strong);
11251164
sva_strong_exprt::check(expr);
11261165
return static_cast<const sva_strong_exprt &>(expr);
11271166
}
11281167

11291168
inline sva_strong_exprt &to_sva_strong_expr(exprt &expr)
11301169
{
1170+
PRECONDITION(expr.id() == ID_sva_strong);
11311171
sva_strong_exprt::check(expr);
11321172
return static_cast<sva_strong_exprt &>(expr);
11331173
}
11341174

1135-
class sva_weak_exprt : public unary_exprt
1175+
class sva_weak_exprt : public sva_sequence_property_expr_baset
11361176
{
11371177
public:
1138-
sva_weak_exprt(exprt __op, typet __type)
1139-
: unary_exprt(ID_sva_weak, std::move(__op), std::move(__type))
1178+
sva_weak_exprt(exprt __op)
1179+
: sva_sequence_property_expr_baset(ID_sva_weak, std::move(__op))
11401180
{
11411181
}
11421182
};
11431183

11441184
inline const sva_weak_exprt &to_sva_weak_expr(const exprt &expr)
11451185
{
1186+
PRECONDITION(expr.id() == ID_sva_weak);
11461187
sva_weak_exprt::check(expr);
11471188
return static_cast<const sva_weak_exprt &>(expr);
11481189
}
11491190

11501191
inline sva_weak_exprt &to_sva_weak_expr(exprt &expr)
11511192
{
1193+
PRECONDITION(expr.id() == ID_sva_weak);
11521194
sva_weak_exprt::check(expr);
11531195
return static_cast<sva_weak_exprt &>(expr);
11541196
}
@@ -1517,11 +1559,11 @@ to_sva_sequence_first_match_expr(exprt &expr)
15171559

15181560
/// 1800-2017 16.12.2 Sequence property
15191561
/// Equivalent to weak(...) or strong(...) depending on context.
1520-
class sva_sequence_property_exprt : public unary_predicate_exprt
1562+
class sva_sequence_property_exprt : public sva_sequence_property_expr_baset
15211563
{
15221564
public:
15231565
explicit sva_sequence_property_exprt(exprt op)
1524-
: unary_predicate_exprt(ID_sva_sequence_property, std::move(op))
1566+
: sva_sequence_property_expr_baset(ID_sva_sequence_property, std::move(op))
15251567
{
15261568
}
15271569
};

0 commit comments

Comments
 (0)