Skip to content

Commit 49923bb

Browse files
committed
SVA: strengthen typing of sva_sequence_concatenation_exprt
The RHS of a sva_sequence_concatenation_exprt is always a sva_cycle_delay expression. This strengthens the typing of the rhs() method accordingly.
1 parent ddeb32d commit 49923bb

File tree

2 files changed

+77
-70
lines changed

2 files changed

+77
-70
lines changed

src/temporal-logic/ltl_sva_to_string.cpp

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -337,56 +337,50 @@ ltl_sva_to_stringt::rec(const exprt &expr, modet mode)
337337
// f ##1 g --> f ; g
338338
// f ##n g --> f ; 1[*n-1] ; b
339339
auto &concatenation = to_sva_sequence_concatenation_expr(expr);
340-
if(concatenation.rhs().id() == ID_sva_cycle_delay)
341-
{
342-
auto &delay = to_sva_cycle_delay_expr(concatenation.rhs());
340+
auto &delay = concatenation.rhs();
343341

344-
auto new_expr = concatenation;
345-
new_expr.rhs() = delay.op();
342+
binary_exprt new_expr = concatenation;
343+
new_expr.rhs() = delay.op();
346344

347-
if(delay.is_range())
348-
{
349-
auto from = numeric_cast_v<mp_integer>(delay.from());
345+
if(delay.is_range())
346+
{
347+
auto from = numeric_cast_v<mp_integer>(delay.from());
350348

351-
if(from == 0)
352-
{
353-
// requires treatment of empty sequences on lhs
354-
throw ebmc_errort{}
355-
<< "cannot convert 0.. ranged sequence concatenation to Buechi";
356-
}
357-
else if(delay.is_unbounded())
358-
{
359-
return infix(
360-
" ; 1[*" + integer2string(from - 1) + "..] ; ", new_expr, mode);
361-
}
362-
else
363-
{
364-
auto to = numeric_cast_v<mp_integer>(delay.to());
365-
PRECONDITION(to >= 0);
366-
return infix(
367-
" ; 1[*" + integer2string(from - 1) + ".." +
368-
integer2string(to - 1) + "] ; ",
369-
new_expr,
370-
mode);
371-
}
349+
if(from == 0)
350+
{
351+
// requires treatment of empty sequences on lhs
352+
throw ebmc_errort{}
353+
<< "cannot convert 0.. ranged sequence concatenation to Buechi";
354+
}
355+
else if(delay.is_unbounded())
356+
{
357+
return infix(
358+
" ; 1[*" + integer2string(from - 1) + "..] ; ", new_expr, mode);
372359
}
373360
else
374361
{
375-
auto n = numeric_cast_v<mp_integer>(delay.from());
376-
PRECONDITION(n >= 0);
377-
if(n == 0)
378-
return infix(" : ", new_expr, mode);
379-
else if(n == 1)
380-
return infix(" ; ", new_expr, mode);
381-
else
382-
{
383-
return infix(
384-
" ; 1[*" + integer2string(n - 1) + "] ; ", new_expr, mode);
385-
}
362+
auto to = numeric_cast_v<mp_integer>(delay.to());
363+
PRECONDITION(to >= 0);
364+
return infix(
365+
" ; 1[*" + integer2string(from - 1) + ".." + integer2string(to - 1) +
366+
"] ; ",
367+
new_expr,
368+
mode);
386369
}
387370
}
388371
else
389-
return infix(":", expr, mode);
372+
{
373+
auto n = numeric_cast_v<mp_integer>(delay.from());
374+
PRECONDITION(n >= 0);
375+
if(n == 0)
376+
return infix(" : ", new_expr, mode);
377+
else if(n == 1)
378+
return infix(" ; ", new_expr, mode);
379+
else
380+
{
381+
return infix(" ; 1[*" + integer2string(n - 1) + "] ; ", new_expr, mode);
382+
}
383+
}
390384
}
391385
else if(expr.id() == ID_sva_cycle_delay)
392386
{

src/verilog/sva_expr.h

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -861,35 +861,6 @@ static inline sva_and_exprt &to_sva_and_expr(exprt &expr)
861861
return static_cast<sva_and_exprt &>(expr);
862862
}
863863

864-
class sva_sequence_concatenation_exprt : public binary_exprt
865-
{
866-
public:
867-
explicit sva_sequence_concatenation_exprt(exprt op0, exprt op1)
868-
: binary_exprt(
869-
std::move(op0),
870-
ID_sva_sequence_concatenation,
871-
std::move(op1),
872-
verilog_sva_sequence_typet{})
873-
{
874-
}
875-
};
876-
877-
static inline const sva_sequence_concatenation_exprt &
878-
to_sva_sequence_concatenation_expr(const exprt &expr)
879-
{
880-
PRECONDITION(expr.id() == ID_sva_sequence_concatenation);
881-
sva_sequence_concatenation_exprt::check(expr, validation_modet::INVARIANT);
882-
return static_cast<const sva_sequence_concatenation_exprt &>(expr);
883-
}
884-
885-
static inline sva_sequence_concatenation_exprt &
886-
to_sva_sequence_concatenation_expr(exprt &expr)
887-
{
888-
PRECONDITION(expr.id() == ID_sva_sequence_concatenation);
889-
sva_sequence_concatenation_exprt::check(expr, validation_modet::INVARIANT);
890-
return static_cast<sva_sequence_concatenation_exprt &>(expr);
891-
}
892-
893864
class sva_iff_exprt : public binary_predicate_exprt
894865
{
895866
public:
@@ -1084,6 +1055,48 @@ static inline sva_cycle_delay_exprt &to_sva_cycle_delay_expr(exprt &expr)
10841055
return static_cast<sva_cycle_delay_exprt &>(expr);
10851056
}
10861057

1058+
class sva_sequence_concatenation_exprt : public binary_exprt
1059+
{
1060+
public:
1061+
// The lhs is a sequence, the rhs is a sva_cycle_delay expression
1062+
explicit sva_sequence_concatenation_exprt(
1063+
exprt __lhs,
1064+
sva_cycle_delay_exprt __rhs)
1065+
: binary_exprt(
1066+
std::move(__lhs),
1067+
ID_sva_sequence_concatenation,
1068+
std::move(__rhs),
1069+
verilog_sva_sequence_typet{})
1070+
{
1071+
}
1072+
1073+
const sva_cycle_delay_exprt &rhs() const
1074+
{
1075+
return static_cast<const sva_cycle_delay_exprt &>(binary_exprt::rhs());
1076+
}
1077+
1078+
sva_cycle_delay_exprt &rhs()
1079+
{
1080+
return static_cast<sva_cycle_delay_exprt &>(binary_exprt::rhs());
1081+
}
1082+
};
1083+
1084+
static inline const sva_sequence_concatenation_exprt &
1085+
to_sva_sequence_concatenation_expr(const exprt &expr)
1086+
{
1087+
PRECONDITION(expr.id() == ID_sva_sequence_concatenation);
1088+
sva_sequence_concatenation_exprt::check(expr, validation_modet::INVARIANT);
1089+
return static_cast<const sva_sequence_concatenation_exprt &>(expr);
1090+
}
1091+
1092+
static inline sva_sequence_concatenation_exprt &
1093+
to_sva_sequence_concatenation_expr(exprt &expr)
1094+
{
1095+
PRECONDITION(expr.id() == ID_sva_sequence_concatenation);
1096+
sva_sequence_concatenation_exprt::check(expr, validation_modet::INVARIANT);
1097+
return static_cast<sva_sequence_concatenation_exprt &>(expr);
1098+
}
1099+
10871100
class sva_cycle_delay_plus_exprt : public unary_exprt
10881101
{
10891102
public:

0 commit comments

Comments
 (0)