Skip to content

Commit 33f42fc

Browse files
committed
introduce verilog_sva_property_typet
This introduces a type for Verilog SVA properties to distinguish properties from state predicates and sequences.
1 parent 0d4c976 commit 33f42fc

File tree

7 files changed

+161
-80
lines changed

7 files changed

+161
-80
lines changed

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ IREP_ID_ONE(verilog_null)
147147
IREP_ID_ONE(verilog_event)
148148
IREP_ID_ONE(verilog_event_trigger)
149149
IREP_ID_ONE(verilog_string)
150+
IREP_ID_ONE(verilog_sva_property)
150151
IREP_ID_ONE(verilog_sva_sequence)
151152
IREP_ID_ONE(reg)
152153
IREP_ID_ONE(macromodule)

src/temporal-logic/normalize_property.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ exprt normalize_property(exprt expr)
105105
{
106106
// top-level only
107107
if(expr.id() == ID_sva_cover)
108-
expr = sva_always_exprt{not_exprt{to_sva_cover_expr(expr).op()}};
108+
expr = sva_always_exprt{sva_not_exprt{to_sva_cover_expr(expr).op()}};
109109

110110
expr = trivial_sva(expr);
111111

src/temporal-logic/trivial_sva.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,32 @@ exprt trivial_sva(exprt expr)
3232
auto rhs = is_state_predicate(sva_implication.rhs());
3333

3434
if(lhs.has_value() && rhs.has_value())
35-
expr = implies_exprt{*lhs, *rhs};
35+
expr = sva_boolean_exprt{
36+
implies_exprt{*lhs, *rhs}, verilog_sva_property_typet{}};
3637
}
3738
else if(expr.id() == ID_sva_iff)
3839
{
40+
// same as boolean iff when both lhs/rhs are state predicates
3941
auto &sva_iff = to_sva_iff_expr(expr);
40-
expr = equal_exprt{sva_iff.lhs(), sva_iff.rhs()};
42+
43+
auto lhs = is_state_predicate(sva_iff.lhs());
44+
auto rhs = is_state_predicate(sva_iff.rhs());
45+
46+
if(lhs.has_value() && rhs.has_value())
47+
expr = sva_boolean_exprt{
48+
equal_exprt{*lhs, *rhs}, verilog_sva_property_typet{}};
4149
}
4250
else if(expr.id() == ID_sva_implies)
4351
{
52+
// same as boolean implication when both lhs/rhs are state predicates
4453
auto &sva_implies = to_sva_implies_expr(expr);
45-
expr = implies_exprt{sva_implies.lhs(), sva_implies.rhs()};
54+
55+
auto lhs = is_state_predicate(sva_implies.lhs());
56+
auto rhs = is_state_predicate(sva_implies.rhs());
57+
58+
if(lhs.has_value() && rhs.has_value())
59+
expr = sva_boolean_exprt{
60+
implies_exprt{*lhs, *rhs}, verilog_sva_property_typet{}};
4661
}
4762
else if(expr.id() == ID_sva_and)
4863
{
@@ -84,11 +99,16 @@ exprt trivial_sva(exprt expr)
8499
}
85100
else if(expr.id() == ID_sva_not)
86101
{
87-
// Same as regular 'not'. These do not apply to sequences.
88-
expr = not_exprt{to_sva_not_expr(expr).op()};
102+
// Same as boolean 'not' when applied to a state predicate.
103+
auto &op = to_sva_not_expr(expr).op();
104+
auto predicate = is_state_predicate(op);
105+
if(predicate.has_value())
106+
expr =
107+
sva_boolean_exprt{not_exprt{*predicate}, verilog_sva_property_typet{}};
89108
}
90109
else if(expr.id() == ID_sva_if)
91110
{
111+
// same as boolean 'if' when both cases are state predicates.
92112
auto &sva_if_expr = to_sva_if_expr(expr);
93113
auto false_case = sva_if_expr.false_case().is_nil()
94114
? true_exprt{}

src/trans-word-level/property.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,10 @@ static obligationst property_obligations_rec(
530530
return property_obligations_rec(
531531
to_typecast_expr(property_expr).op(), current, no_timeframes);
532532
}
533-
else if(property_expr.id() == ID_not)
533+
else if(property_expr.id() == ID_sva_not)
534534
{
535535
// We need NNF, try to eliminate the negation.
536-
auto &op = to_not_expr(property_expr).op();
536+
auto &op = to_sva_not_expr(property_expr).op();
537537

538538
auto op_negated_opt = negate_property_node(op);
539539

@@ -570,8 +570,9 @@ static obligationst property_obligations_rec(
570570
else
571571
{
572572
// state formula
573-
return obligationst{
574-
current, instantiate_property(property_expr, current, no_timeframes)};
573+
auto sampled =
574+
instantiate_property(not_exprt{op}, current, no_timeframes);
575+
return obligationst{current, sampled};
575576
}
576577
}
577578
else if(property_expr.id() == ID_sva_implies)

0 commit comments

Comments
 (0)