Skip to content

SVA-to-Buechi: sequence repetition operators #1130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions regression/ebmc-spot/sva-buechi/sequence_repetition4.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
../../verilog/SVA/sequence_repetition4.sv
--buechi --bound 10
^\[main\.p0\] \(main\.x == 0 ##1 main\.x == 1\) \[\*2\]: PROVED up to bound \d+$
^\[main\.p1\] \(main\.x == 0 ##1 main\.x == 1 ##1 main\.x == 0\) \[\*2\]: REFUTED$
^EXIT=10$
^SIGNAL=0$
--
^warning: ignoring
--
10 changes: 10 additions & 0 deletions regression/ebmc-spot/sva-buechi/sequence_repetition5.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
../../verilog/SVA/sequence_repetition5.sv
--buechi --bound 20
^\[.*\] main\.pulse ##1 \!main\.pulse \[\*1:9\] ##1 main.pulse: PROVED up to bound 20$
^\[.*\] main\.pulse ##1 \!main\.pulse \[\*1:8\] ##1 main.pulse: REFUTED$
^EXIT=10$
^SIGNAL=0$
--
^warning: ignoring
--
8 changes: 0 additions & 8 deletions regression/ebmc-spot/sva-buechi/sequence_repetition6.desc

This file was deleted.

10 changes: 10 additions & 0 deletions regression/ebmc-spot/sva-buechi/sequence_repetition7.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
../../verilog/SVA/sequence_repetition7.sv
--buechi --bound 20
^\[.*\] \(main\.a ##1 main\.b\) \[\*5\]: PROVED up to bound 20$
^\[.*\] \(\!main\.b ##1 \!main\.a\) \[\*5\]: PROVED up to bound 20$
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
--
99 changes: 99 additions & 0 deletions src/temporal-logic/ltl_sva_to_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,105 @@ ltl_sva_to_stringt::rec(const exprt &expr, modet mode)
auto a2 = and_exprt{not_exprt{if_expr.cond()}, if_expr.false_case()};
return rec(or_exprt{a1, a2}, mode);
}
else if(
expr.id() ==
ID_sva_sequence_repetition_star) // [*] or [*n] or [*x:y] or [*x:$]
{
PRECONDITION(mode == SVA_SEQUENCE);
auto &repetition = to_sva_sequence_repetition_star_expr(expr);
unary_exprt new_expr{ID_sva_sequence_repetition_star, repetition.op()};
if(!repetition.repetitions_given())
{
return suffix("[*]", new_expr, mode);
}
else if(repetition.is_empty_match())
{
throw ebmc_errort{} << "cannot convert [*0] to Buechi";
}
else if(repetition.is_singleton())
{
auto n = numeric_cast_v<mp_integer>(repetition.repetitions());
return suffix("[*" + integer2string(n) + "]", new_expr, mode);
}
else if(repetition.is_bounded_range())
{
auto from = numeric_cast_v<mp_integer>(repetition.from());
auto to = numeric_cast_v<mp_integer>(repetition.to());
return suffix(
"[*" + integer2string(from) + ".." + integer2string(to) + "]",
new_expr,
mode);
}
else if(repetition.is_unbounded())
{
auto from = numeric_cast_v<mp_integer>(repetition.from());
return suffix("[*" + integer2string(from) + "..]", new_expr, mode);
}
else
DATA_INVARIANT(false, "unexpected sva_sequence_repetition_star");
}
else if(expr.id() == ID_sva_sequence_repetition_plus) // something[+]
{
PRECONDITION(mode == SVA_SEQUENCE);
return suffix("[+]", expr, mode);
}
else if(expr.id() == ID_sva_sequence_goto_repetition) // something[->n]
{
PRECONDITION(mode == SVA_SEQUENCE);
auto &repetition = to_sva_sequence_goto_repetition_expr(expr);
unary_exprt new_expr{ID_sva_sequence_goto_repetition, repetition.op()};
if(repetition.is_singleton())
{
auto n = numeric_cast_v<mp_integer>(repetition.repetitions());
return suffix("[->" + integer2string(n) + "]", new_expr, mode);
}
else if(repetition.is_bounded_range())
{
auto from = numeric_cast_v<mp_integer>(repetition.from());
auto to = numeric_cast_v<mp_integer>(repetition.to());
return suffix(
"[->" + integer2string(from) + ".." + integer2string(to) + "]",
new_expr,
mode);
}
else if(repetition.is_unbounded())
{
auto from = numeric_cast_v<mp_integer>(repetition.from());
return suffix("[->" + integer2string(from) + "..]", new_expr, mode);
}
else
DATA_INVARIANT(false, "unexpected sva_sequence_goto_repetition");
}
else if(
expr.id() == ID_sva_sequence_non_consecutive_repetition) // something[=n]
{
PRECONDITION(mode == SVA_SEQUENCE);
auto &repetition = to_sva_sequence_non_consecutive_repetition_expr(expr);
unary_exprt new_expr{
ID_sva_sequence_non_consecutive_repetition, repetition.op()};
if(repetition.is_singleton())
{
auto n = numeric_cast_v<mp_integer>(repetition.repetitions());
return suffix("[=" + integer2string(n) + "]", new_expr, mode);
}
else if(repetition.is_bounded_range())
{
auto from = numeric_cast_v<mp_integer>(repetition.from());
auto to = numeric_cast_v<mp_integer>(repetition.to());
return suffix(
"[=" + integer2string(from) + ".." + integer2string(to) + "]",
new_expr,
mode);
}
else if(repetition.is_unbounded())
{
auto from = numeric_cast_v<mp_integer>(repetition.from());
return suffix("[=" + integer2string(from) + "..]", new_expr, mode);
}
else
DATA_INVARIANT(
false, "unexpected sva_sequence_non_consecutive_repetition");
}
else if(!is_temporal_operator(expr))
{
auto number = atoms.number(expr);
Expand Down
20 changes: 15 additions & 5 deletions src/verilog/sva_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1456,19 +1456,19 @@ class sva_sequence_repetition_exprt : public ternary_exprt
/// op[*0] is a special case, denoting the empty match
bool is_empty_match() const
{
return !is_range() && repetitions_given() && op1().is_zero();
return is_singleton() && op1().is_zero();
}

// The number of repetitions must be a constant after elaboration.
const constant_exprt &repetitions() const
{
PRECONDITION(repetitions_given() && !is_range());
PRECONDITION(is_singleton());
return static_cast<const constant_exprt &>(op1());
}

constant_exprt &repetitions()
{
PRECONDITION(repetitions_given() && !is_range());
PRECONDITION(is_singleton());
return static_cast<constant_exprt &>(op1());
}

Expand All @@ -1477,6 +1477,16 @@ class sva_sequence_repetition_exprt : public ternary_exprt
return op2().is_not_nil();
}

bool is_bounded_range() const
{
return op2().is_not_nil() && op2().id() != ID_infinity;
}

bool is_singleton() const
{
return op1().is_not_nil() && op2().is_nil();
}

bool is_unbounded() const
{
return op2().id() == ID_infinity;
Expand All @@ -1496,13 +1506,13 @@ class sva_sequence_repetition_exprt : public ternary_exprt

const constant_exprt &to() const
{
PRECONDITION(is_range() && !is_unbounded());
PRECONDITION(is_bounded_range());
return static_cast<const constant_exprt &>(op2());
}

constant_exprt &to()
{
PRECONDITION(is_range() && !is_unbounded());
PRECONDITION(is_bounded_range());
return static_cast<constant_exprt &>(op2());
}

Expand Down
Loading