Skip to content

Commit 4cf3a13

Browse files
committed
SystemVerilog checkers
This adds 1800-2017 Sec. 17 checkers.
1 parent cbad677 commit 4cf3a13

File tree

8 files changed

+104
-10
lines changed

8 files changed

+104
-10
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* SystemVerilog: $itor, $rtoi
1111
* SystemVerilog: chandle, event, string
1212
* SystemVerilog: package scope operator
13+
* SystemVerilog: checkers
1314

1415
# EBMC 5.4
1516

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
KNOWNBUG
2+
checker2.sv
3+
--bound 20
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
checker myChecker(input logic [31:0] data);
2+
assert property (data != 10);
3+
endchecker
4+
5+
module main(input clk);
6+
reg [31:0] counter = 0;
7+
always_ff @(posedge clk) counter++;
8+
myChecker c(counter);
9+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ IREP_ID_ONE(verilog_indexed_part_select_minus)
100100
IREP_ID_ONE(verilog_past)
101101
IREP_ID_ONE(verilog_property_declaration)
102102
IREP_ID_ONE(verilog_sequence_declaration)
103+
IREP_ID_ONE(verilog_sequence)
103104
IREP_ID_ONE(verilog_value_range)
104105
IREP_ID_ONE(verilog_void)
105106
IREP_ID_ONE(verilog_streaming_concatenation_left_to_right)

src/verilog/parser.y

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -750,19 +750,66 @@ program_declaration:
750750
;
751751

752752
checker_declaration:
753-
TOK_CHECKER checker_identifier
754-
{
755-
init($$, ID_verilog_checker);
756-
stack_expr($$).set(ID_base_name, stack_expr($2).id());
757-
}
758-
';'
753+
TOK_CHECKER { init($$); } checker_identifier
754+
checker_port_list_paren_opt ';'
759755
checker_or_generate_item_brace
760756
TOK_ENDCHECKER
761757
{
762-
$$ = $3;
758+
init($$);
759+
irept attributes;
760+
exprt parameter_port_list;
761+
stack_expr($$) = verilog_parse_treet::create_module(
762+
attributes, // attributes,
763+
stack_expr($2), // module_keyword
764+
stack_expr($3), // name
765+
parameter_port_list, // parameter_port_list
766+
stack_expr($4), // ports
767+
stack_expr($6) // module_items
768+
);
769+
stack_expr($$).id(ID_verilog_checker);
763770
}
764771
;
765772

773+
checker_port_list_paren_opt:
774+
/* Optional */
775+
{ init($$); }
776+
| '(' checker_port_list_opt ')'
777+
{ $$ = $2; }
778+
;
779+
780+
checker_port_list_opt:
781+
/* Optional */
782+
{ init($$); }
783+
| checker_port_list
784+
;
785+
786+
checker_port_list:
787+
checker_port_item
788+
{ init($$); mts($$, $1); }
789+
| checker_port_list checker_port_item
790+
{ $$ = $1; mts($$, $2); }
791+
;
792+
793+
checker_port_item:
794+
attribute_instance_brace
795+
checker_port_direction_opt
796+
property_formal_type
797+
formal_port_identifier
798+
variable_dimension_brace
799+
{ init($$, ID_decl);
800+
mto($$, $4);
801+
}
802+
;
803+
804+
checker_port_direction_opt:
805+
/* Optional */
806+
{ init($$); }
807+
| TOK_INPUT
808+
{ init($$, ID_input); }
809+
| TOK_OUTPUT
810+
{ init($$, ID_output); }
811+
;
812+
766813
class_declaration:
767814
TOK_CLASS class_identifier
768815
';'
@@ -1030,7 +1077,9 @@ non_port_interface_item:
10301077

10311078
checker_or_generate_item_brace:
10321079
/* Optional */
1080+
{ init($$); }
10331081
| checker_or_generate_item_brace attribute_instance_brace checker_or_generate_item
1082+
{ $$ = $1; mts($$, $3); }
10341083
;
10351084

10361085
checker_or_generate_item:
@@ -2323,7 +2372,8 @@ property_port_item:
23232372
;
23242373

23252374
property_formal_type:
2326-
TOK_PROPERTY
2375+
sequence_formal_type
2376+
| TOK_PROPERTY
23272377
;
23282378

23292379
property_spec:
@@ -2334,6 +2384,14 @@ property_spec:
23342384
| property_expr
23352385
;
23362386

2387+
sequence_formal_type:
2388+
data_type
2389+
| TOK_SEQUENCE
2390+
{ init($$, ID_verilog_sequence); }
2391+
| TOK_UNTYPED
2392+
{ init($$, ID_verilog_untyped); }
2393+
;
2394+
23372395
// The 1800-2017 grammar has an ambiguity where
23382396
// '(' expression ')' can either be an expression or a property_expr,
23392397
// which yields a reduce/reduce conflict. Hence, we split the rules

src/verilog/verilog_expr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ void verilog_checkert::show(std::ostream &out) const
124124
{
125125
out << "Checker: " << base_name() << '\n';
126126

127+
out << " Ports:\n";
128+
129+
for(auto &port : ports())
130+
out << " " << port.pretty() << '\n';
131+
132+
out << '\n';
133+
127134
out << " Items:\n";
128135

129136
for(auto &item : items())

src/verilog/verilog_expr.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,18 @@ class verilog_checkert : public verilog_item_containert
23542354
{
23552355
}
23562356

2357+
using portst = std::vector<verilog_declt>;
2358+
2359+
portst &ports()
2360+
{
2361+
return (portst &)(add(ID_ports).get_sub());
2362+
}
2363+
2364+
const portst &ports() const
2365+
{
2366+
return (const portst &)(find(ID_ports).get_sub());
2367+
}
2368+
23572369
void show(std::ostream &) const;
23582370
};
23592371

src/verilog/verilog_parse_tree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void verilog_parse_treet::modules_provided(
6161
{
6262
for(auto &item : items)
6363
{
64-
if(item.id() == ID_verilog_module)
64+
if(item.id() == ID_verilog_module || item.id() == ID_verilog_checker)
6565
{
6666
module_set.insert(id2string(
6767
verilog_module_symbol(to_verilog_module_source(item).base_name())));
@@ -92,7 +92,7 @@ void verilog_parse_treet::build_item_map()
9292

9393
for(const auto &item : items)
9494
{
95-
if(item.id() == ID_verilog_module)
95+
if(item.id() == ID_verilog_module || item.id() == ID_verilog_checker)
9696
{
9797
auto &verilog_module = to_verilog_module_source(item);
9898
item_map[verilog_module.base_name()] = &verilog_module;

0 commit comments

Comments
 (0)