Skip to content

Commit c5ef5a1

Browse files
committed
SVA: sequence and property instance expressions
IEEE 1800-2017 refers to sequence and property instances, and rewriting algorithms for them (F.4.1). This introduces an expression class each for sequence and property instance expressions.
1 parent 70adb86 commit c5ef5a1

File tree

6 files changed

+118
-0
lines changed

6 files changed

+118
-0
lines changed

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ IREP_ID_ONE(sva_sequence_goto_repetition)
8080
IREP_ID_ONE(sva_sequence_intersect)
8181
IREP_ID_ONE(sva_sequence_non_consecutive_repetition)
8282
IREP_ID_ONE(sva_sequence_property)
83+
IREP_ID_ONE(sva_sequence_property_instance)
8384
IREP_ID_ONE(sva_sequence_repetition_star)
8485
IREP_ID_ONE(sva_sequence_repetition_plus)
8586
IREP_ID_ONE(sva_sequence_throughout)

src/verilog/expr2verilog.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,45 @@ expr2verilogt::convert_inside(const verilog_inside_exprt &src)
14831483

14841484
/*******************************************************************\
14851485
1486+
Function: expr2verilogt::convert_sequence_property_instance
1487+
1488+
Inputs:
1489+
1490+
Outputs:
1491+
1492+
Purpose:
1493+
1494+
\*******************************************************************/
1495+
1496+
expr2verilogt::resultt expr2verilogt::convert_sequence_property_instance(
1497+
const sva_sequence_property_instance_exprt &src)
1498+
{
1499+
if(src.arguments().empty())
1500+
return convert_rec(src.symbol());
1501+
1502+
auto fkt = convert_rec(src.symbol());
1503+
1504+
std::string dest = fkt.s;
1505+
bool first = true;
1506+
dest += "(";
1507+
1508+
for(const auto &op : src.arguments())
1509+
{
1510+
if(first)
1511+
first = false;
1512+
else
1513+
dest += ", ";
1514+
1515+
dest += convert_rec(op).s;
1516+
}
1517+
1518+
dest += ")";
1519+
1520+
return {verilog_precedencet::MEMBER, dest};
1521+
}
1522+
1523+
/*******************************************************************\
1524+
14861525
Function: expr2verilogt::convert_value_range
14871526
14881527
Inputs:
@@ -2015,6 +2054,12 @@ expr2verilogt::resultt expr2verilogt::convert_rec(const exprt &src)
20152054
else if(src.id() == ID_zero_extend)
20162055
return convert_rec(to_zero_extend_expr(src).op());
20172056

2057+
else if(src.id() == ID_sva_sequence_property_instance)
2058+
{
2059+
return convert_sequence_property_instance(
2060+
to_sva_sequence_property_instance_expr(src));
2061+
}
2062+
20182063
// no VERILOG language expression for internal representation
20192064
return convert_norep(src);
20202065
}

src/verilog/expr2verilog_class.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class sva_if_exprt;
1717
class sva_ranged_predicate_exprt;
1818
class sva_cycle_delay_exprt;
1919
class sva_sequence_first_match_exprt;
20+
class sva_sequence_property_instance_exprt;
2021
class sva_sequence_repetition_exprt;
2122

2223
// Precedences (higher means binds more strongly).
@@ -180,6 +181,9 @@ class expr2verilogt
180181

181182
resultt convert_value_range(const class verilog_value_range_exprt &);
182183

184+
resultt convert_sequence_property_instance(
185+
const class sva_sequence_property_instance_exprt &);
186+
183187
protected:
184188
const namespacet &ns;
185189
};

src/verilog/sva_expr.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,4 +2047,56 @@ enum class sva_sequence_semanticst
20472047
STRONG
20482048
};
20492049

2050+
/// a base class for both sequence and property instance expressions
2051+
class sva_sequence_property_instance_exprt : public binary_exprt
2052+
{
2053+
public:
2054+
sva_sequence_property_instance_exprt(
2055+
symbol_exprt _symbol,
2056+
exprt::operandst _arguments)
2057+
: binary_exprt{
2058+
_symbol,
2059+
ID_sva_sequence_property_instance,
2060+
multi_ary_exprt{ID_arguments, std::move(_arguments), typet{}},
2061+
_symbol.type()}
2062+
{
2063+
}
2064+
2065+
const symbol_exprt &symbol() const
2066+
{
2067+
return static_cast<const symbol_exprt &>(op0());
2068+
}
2069+
2070+
symbol_exprt &symbol()
2071+
{
2072+
return static_cast<symbol_exprt &>(op0());
2073+
}
2074+
2075+
exprt::operandst &arguments()
2076+
{
2077+
return op1().operands();
2078+
}
2079+
2080+
const exprt::operandst &arguments() const
2081+
{
2082+
return op1().operands();
2083+
}
2084+
};
2085+
2086+
inline const sva_sequence_property_instance_exprt &
2087+
to_sva_sequence_property_instance_expr(const exprt &expr)
2088+
{
2089+
PRECONDITION(expr.id() == ID_sva_sequence_property_instance);
2090+
sva_sequence_property_instance_exprt::check(expr);
2091+
return static_cast<const sva_sequence_property_instance_exprt &>(expr);
2092+
}
2093+
2094+
inline sva_sequence_property_instance_exprt &
2095+
to_sva_sequence_property_instance_expr(exprt &expr)
2096+
{
2097+
PRECONDITION(expr.id() == ID_sva_sequence_property_instance);
2098+
sva_sequence_property_instance_exprt::check(expr);
2099+
return static_cast<sva_sequence_property_instance_exprt &>(expr);
2100+
}
2101+
20502102
#endif

src/verilog/verilog_synthesis.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ exprt verilog_synthesist::synth_expr_rec(exprt expr, symbol_statet symbol_state)
7171
{
7272
return expand_function_call(to_function_call_expr(expr), symbol_state);
7373
}
74+
else if(expr.id() == ID_sva_sequence_property_instance)
75+
{
76+
auto &instance = to_sva_sequence_property_instance_expr(expr);
77+
const symbolt &symbol = ns.lookup(instance.symbol());
78+
return synth_expr(symbol.value, symbol_state);
79+
}
7480
else if(expr.id() == ID_hierarchical_identifier)
7581
{
7682
expand_hierarchical_identifier(

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,16 @@ exprt verilog_typecheck_exprt::convert_symbol(
13601360
result.add_source_location()=source_location;
13611361
return result;
13621362
}
1363+
else if(
1364+
symbol->type.id() == ID_verilog_sva_sequence ||
1365+
symbol->type.id() == ID_verilog_sva_property)
1366+
{
1367+
// A named sequence or property. Use an instance expression.
1368+
expr.type() = symbol->type;
1369+
expr.set_identifier(symbol->name);
1370+
return sva_sequence_property_instance_exprt{expr, {}}
1371+
.with_source_location(expr);
1372+
}
13631373
else
13641374
{
13651375
expr.type()=symbol->type;

0 commit comments

Comments
 (0)