Skip to content

Commit 8642dd3

Browse files
authored
Merge pull request #831 from diffblue/checker1
SystemVerilog: grammar for checkers
2 parents f7c3108 + fae82ea commit 8642dd3

File tree

7 files changed

+106
-1
lines changed

7 files changed

+106
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
checker1.sv
3+
--show-parse
4+
^Checker: myChecker$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
checker myChecker;
2+
endchecker
3+
4+
module main;
5+
endmodule

src/hw_cbmc_irep_ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ IREP_ID_ONE(negedge)
119119
IREP_ID_ONE(posedge)
120120
IREP_ID_ONE(event_guard)
121121
IREP_ID_ONE(verilog_star_event)
122+
IREP_ID_ONE(verilog_checker)
122123
IREP_ID_ONE(verilog_cycle_delay)
123124
IREP_ID_ONE(delay)
124125
IREP_ID_ONE(verilog_non_blocking_assign)

src/verilog/parser.y

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,20 @@ program_declaration:
746746
TOK_PROGRAM TOK_ENDPROGRAM
747747
;
748748

749+
checker_declaration:
750+
TOK_CHECKER checker_identifier
751+
{
752+
init($$, ID_verilog_checker);
753+
stack_expr($$).set(ID_base_name, stack_expr($2).id());
754+
}
755+
';'
756+
checker_or_generate_item_brace
757+
TOK_ENDCHECKER
758+
{
759+
$$ = $3;
760+
}
761+
;
762+
749763
class_declaration:
750764
TOK_CLASS class_identifier
751765
';'
@@ -1007,6 +1021,42 @@ non_port_interface_item:
10071021
| interface_declaration
10081022
/* | timeunits_declaration */
10091023
;
1024+
1025+
// System Verilog standard 1800-2017
1026+
// A.1.9 Checker items
1027+
1028+
checker_or_generate_item_brace:
1029+
/* Optional */
1030+
| checker_or_generate_item_brace attribute_instance_brace checker_or_generate_item
1031+
;
1032+
1033+
checker_or_generate_item:
1034+
checker_or_generate_item_declaration
1035+
| initial_construct
1036+
| always_construct
1037+
| final_construct
1038+
| assertion_item
1039+
| continuous_assign
1040+
| checker_generate_item
1041+
;
1042+
1043+
checker_or_generate_item_declaration:
1044+
data_declaration
1045+
| function_declaration
1046+
| checker_declaration
1047+
| assertion_item_declaration
1048+
| covergroup_declaration
1049+
| genvar_declaration
1050+
| TOK_DEFAULT TOK_CLOCKING clocking_identifier ';'
1051+
| TOK_DEFAULT TOK_DISABLE TOK_IFF expression_or_dist ';'
1052+
| ';'
1053+
;
1054+
1055+
checker_generate_item:
1056+
loop_generate_construct
1057+
| conditional_generate_construct
1058+
| generate_region
1059+
;
10101060

10111061
// System Verilog standard 1800-2017
10121062
// A.1.9 Class items
@@ -1170,6 +1220,7 @@ package_or_generate_item_declaration:
11701220
| data_declaration
11711221
| task_declaration
11721222
| function_declaration
1223+
| checker_declaration
11731224
| class_declaration
11741225
| local_parameter_declaration ';'
11751226
| parameter_declaration ';'
@@ -4076,6 +4127,10 @@ endmodule_identifier_opt:
40764127
| TOK_COLON module_identifier
40774128
;
40784129

4130+
clocking_identifier: TOK_NON_TYPE_IDENTIFIER;
4131+
4132+
checker_identifier: TOK_NON_TYPE_IDENTIFIER;
4133+
40794134
net_identifier: identifier;
40804135

40814136
package_identifier: TOK_NON_TYPE_IDENTIFIER;

src/verilog/verilog_expr.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ std::vector<irep_idt> verilog_item_containert::dependencies() const
112112
return result;
113113
}
114114

115+
void verilog_checkert::show(std::ostream &out) const
116+
{
117+
out << "Checker: " << base_name() << '\n';
118+
119+
out << " Items:\n";
120+
121+
for(auto &item : items())
122+
out << " " << item.pretty() << '\n';
123+
124+
out << '\n';
125+
}
126+
115127
void verilog_packaget::show(std::ostream &out) const
116128
{
117129
out << "Pacakge: " << base_name() << '\n';

src/verilog/verilog_expr.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,29 @@ inline verilog_module_sourcet &to_verilog_module_source(irept &irep)
21432143
return static_cast<verilog_module_sourcet &>(irep);
21442144
}
21452145

2146+
class verilog_checkert : public verilog_item_containert
2147+
{
2148+
public:
2149+
explicit verilog_checkert(irep_idt _base_name)
2150+
: verilog_item_containert(ID_verilog_module, _base_name)
2151+
{
2152+
}
2153+
2154+
void show(std::ostream &) const;
2155+
};
2156+
2157+
inline const verilog_checkert &to_verilog_checker(const irept &irep)
2158+
{
2159+
PRECONDITION(irep.id() == ID_verilog_checker);
2160+
return static_cast<const verilog_checkert &>(irep);
2161+
}
2162+
2163+
inline verilog_checkert &to_verilog_checker(irept &irep)
2164+
{
2165+
PRECONDITION(irep.id() == ID_verilog_checker);
2166+
return static_cast<verilog_checkert &>(irep);
2167+
}
2168+
21462169
class verilog_packaget : public verilog_item_containert
21472170
{
21482171
public:

src/verilog/verilog_parse_tree.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ Function: verilog_parse_treet::show
131131

132132
void verilog_parse_treet::show(const itemt &item, std::ostream &out) const
133133
{
134-
if(item.id() == ID_verilog_class)
134+
if(item.id() == ID_verilog_checker)
135+
to_verilog_checker(item).show(out);
136+
else if(item.id() == ID_verilog_class)
135137
to_verilog_class(item).show(out);
136138
else if(item.id() == ID_verilog_interface)
137139
to_verilog_interface(item).show(out);

0 commit comments

Comments
 (0)