Skip to content

Commit 753e9c4

Browse files
authored
Merge pull request #1445 from diffblue/tc-sequence-property-instances
SystemVerilog: checking sequence and property declarations
2 parents f494926 + 939438f commit 753e9c4

File tree

8 files changed

+78
-26
lines changed

8 files changed

+78
-26
lines changed

regression/verilog/SVA/named_property1.sv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ module main(input clk);
1212
x_is_ten
1313
endsequence
1414

15+
initial assert(some_sequence);
16+
1517
endmodule

src/trans-netlist/trans_to_netlist.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ void convert_trans_to_netlistt::map_vars(
212212
if (symbol.is_property)
213213
return; // ignore properties
214214
else if(
215-
symbol.type.id() == ID_verilog_sva_sequence ||
216-
symbol.type.id() == ID_verilog_sva_property)
215+
symbol.type.id() == ID_verilog_sva_named_sequence ||
216+
symbol.type.id() == ID_verilog_sva_named_property)
217217
{
218-
return; // ignore properties
218+
return; // ignore sequence/property declarations
219219
}
220220
else if(
221221
symbol.type.id() == ID_natural || symbol.type.id() == ID_integer ||

src/verilog/sva_expr.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, kroening@kroening.com
1111

1212
#include <util/std_expr.h>
1313

14+
#include "verilog_expr.h"
1415
#include "verilog_types.h"
1516

1617
/// 1800-2017 16.6 Boolean expressions
@@ -2048,17 +2049,19 @@ enum class sva_sequence_semanticst
20482049
};
20492050

20502051
/// a base class for both sequence and property instance expressions
2051-
class sva_sequence_property_instance_exprt : public binary_exprt
2052+
class sva_sequence_property_instance_exprt : public ternary_exprt
20522053
{
20532054
public:
20542055
sva_sequence_property_instance_exprt(
20552056
symbol_exprt _symbol,
2056-
exprt::operandst _arguments)
2057-
: binary_exprt{
2058-
_symbol,
2057+
exprt::operandst _arguments,
2058+
verilog_sequence_property_declaration_baset _declaration)
2059+
: ternary_exprt{
20592060
ID_sva_sequence_property_instance,
2061+
std::move(_symbol),
20602062
multi_ary_exprt{ID_arguments, std::move(_arguments), typet{}},
2061-
_symbol.type()}
2063+
std::move(_declaration),
2064+
typet{}}
20622065
{
20632066
}
20642067

@@ -2081,6 +2084,26 @@ class sva_sequence_property_instance_exprt : public binary_exprt
20812084
{
20822085
return op1().operands();
20832086
}
2087+
2088+
verilog_sequence_property_declaration_baset &declaration()
2089+
{
2090+
return static_cast<verilog_sequence_property_declaration_baset &>(op2());
2091+
}
2092+
2093+
const verilog_sequence_property_declaration_baset &declaration() const
2094+
{
2095+
return static_cast<const verilog_sequence_property_declaration_baset &>(
2096+
op2());
2097+
}
2098+
2099+
/// Add the source location from \p other, if it has any.
2100+
sva_sequence_property_instance_exprt &&
2101+
with_source_location(const exprt &other) &&
2102+
{
2103+
if(other.source_location().is_not_nil())
2104+
add_source_location() = other.source_location();
2105+
return std::move(*this);
2106+
}
20842107
};
20852108

20862109
inline const sva_sequence_property_instance_exprt &

src/verilog/verilog_synthesis.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ exprt verilog_synthesist::synth_expr_rec(exprt expr, symbol_statet symbol_state)
7474
else if(expr.id() == ID_sva_sequence_property_instance)
7575
{
7676
auto &instance = to_sva_sequence_property_instance_expr(expr);
77-
const symbolt &symbol = ns.lookup(instance.symbol());
78-
auto &declaration =
79-
to_verilog_sequence_property_declaration_base(symbol.value);
80-
return synth_expr(declaration.cond(), symbol_state);
77+
return synth_expr(instance.declaration().cond(), symbol_state);
8178
}
8279
else if(expr.id() == ID_hierarchical_identifier)
8380
{

src/verilog/verilog_typecheck.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,13 +1802,13 @@ void verilog_typecheckt::convert_property_declaration(
18021802
auto base_name = declaration.base_name();
18031803
auto full_identifier = hierarchical_identifier(base_name);
18041804

1805-
convert_sva(declaration.property());
1806-
require_sva_property(declaration.property());
1807-
1805+
// 1800-2017 F.4.1
1806+
// Typechecking of the property expression has to be delayed
1807+
// until the instance is known, owing to untyped ports.
18081808
declaration.type() = verilog_sva_named_property_typet{};
18091809

18101810
// The symbol uses the full declaration as value
1811-
auto type = verilog_sva_property_typet{};
1811+
auto type = verilog_sva_named_property_typet{};
18121812
symbolt symbol{full_identifier, type, mode};
18131813

18141814
symbol.module = module_identifier;
@@ -1838,14 +1838,14 @@ void verilog_typecheckt::convert_sequence_declaration(
18381838
auto base_name = declaration.base_name();
18391839
auto full_identifier = hierarchical_identifier(base_name);
18401840

1841-
auto &sequence = declaration.sequence();
1842-
convert_sva(sequence);
1843-
require_sva_sequence(sequence);
1844-
1841+
// 1800-2017 F.4.1
1842+
// Typechecking of the sequence expression has to be delayed
1843+
// until the instance is known, owing to untyped ports.
18451844
declaration.type() = verilog_sva_named_sequence_typet{};
18461845

18471846
// The symbol uses the full declaration as value
1848-
symbolt symbol{full_identifier, sequence.type(), mode};
1847+
auto type = verilog_sva_named_sequence_typet{};
1848+
symbolt symbol{full_identifier, type, mode};
18491849

18501850
symbol.module = module_identifier;
18511851
symbol.base_name = base_name;

src/verilog/verilog_typecheck_expr.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,14 +1361,19 @@ exprt verilog_typecheck_exprt::convert_symbol(
13611361
return result;
13621362
}
13631363
else if(
1364-
symbol->type.id() == ID_verilog_sva_sequence ||
1365-
symbol->type.id() == ID_verilog_sva_property)
1364+
symbol->type.id() == ID_verilog_sva_named_sequence ||
1365+
symbol->type.id() == ID_verilog_sva_named_property)
13661366
{
1367-
// A named sequence or property. Use an instance expression.
1367+
// A named sequence or property. Create an instance expression,
1368+
// and then flatten it.
13681369
expr.type() = symbol->type;
13691370
expr.set_identifier(symbol->name);
1370-
return sva_sequence_property_instance_exprt{expr, {}}
1371-
.with_source_location(expr);
1371+
auto &declaration =
1372+
to_verilog_sequence_property_declaration_base(symbol->value);
1373+
auto instance =
1374+
sva_sequence_property_instance_exprt{expr, {}, declaration}
1375+
.with_source_location(expr);
1376+
return flatten_named_sequence_property(instance);
13721377
}
13731378
else
13741379
{

src/verilog/verilog_typecheck_expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ class verilog_typecheck_exprt:public verilog_typecheck_baset
212212
[[nodiscard]] exprt convert_binary_sva(binary_exprt);
213213
[[nodiscard]] exprt convert_ternary_sva(ternary_exprt);
214214
[[nodiscard]] exprt convert_other_sva(exprt);
215+
[[nodiscard]] exprt
216+
flatten_named_sequence_property(sva_sequence_property_instance_exprt);
215217

216218
// system functions
217219
exprt bits(const exprt &);

src/verilog/verilog_typecheck_sva.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,26 @@ exprt verilog_typecheck_exprt::convert_sva_rec(exprt expr)
493493
return convert_other_sva(expr);
494494
}
495495
}
496+
497+
/// 1800-2017 F.4.1
498+
exprt verilog_typecheck_exprt::flatten_named_sequence_property(
499+
sva_sequence_property_instance_exprt instance)
500+
{
501+
auto &cond = instance.declaration().cond();
502+
convert_sva(cond);
503+
504+
if(instance.symbol().type().id() == ID_verilog_sva_named_sequence)
505+
{
506+
require_sva_sequence(cond);
507+
instance.type() = verilog_sva_sequence_typet{};
508+
}
509+
else if(instance.symbol().type().id() == ID_verilog_sva_named_property)
510+
{
511+
require_sva_property(cond);
512+
instance.type() = verilog_sva_property_typet{};
513+
}
514+
else
515+
PRECONDITION(false);
516+
517+
return instance;
518+
}

0 commit comments

Comments
 (0)