Skip to content

Commit 2399b56

Browse files
authored
Merge pull request #684 from diffblue/dist-weight
SystemVerilog: grammar for distribution weights
2 parents 81b3d8e + d97bf18 commit 2399b56

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
constraint1.sv
3+
4+
^no module found$
5+
^EXIT=1$
6+
^SIGNAL=0$
7+
--
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class data;
2+
// rand bit [15:0] field1;
3+
constraint c_f1 {
4+
field1 dist {[0:31] :/ 1, [32:65535] :/ 1};
5+
}
6+
endclass

src/verilog/parser.y

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ int yyverilogerror(const char *error)
394394
%token TOK_HASHMINUSHASH "#-#"
395395
%token TOK_HASHEQUALHASH "#=#"
396396
%token TOK_COLONCOLON "::"
397+
%token TOK_COLONEQUAL ":="
398+
%token TOK_COLONSLASH ":/"
397399
%token TOK_EQUALEQUALQUESTION "==?"
398400
%token TOK_EXCLAMEQUALQUESTION "!=?"
399401
%token TOK_LSQASTERIC "[*"
@@ -941,9 +943,9 @@ class_item:
941943
// { add_attributes($2, $1); $$=$2; }
942944
// | attribute_instance_brace class_method
943945
// { add_attributes($2, $1); $$=$2; }
944-
// | attribute_instance_brace class_constraint
945-
// { add_attributes($2, $1); $$=$2; }
946-
attribute_instance_brace class_declaration
946+
attribute_instance_brace class_constraint
947+
{ add_attributes($2, $1); $$=$2; }
948+
| attribute_instance_brace class_declaration
947949
{ add_attributes($2, $1); $$=$2; }
948950
| attribute_instance_brace covergroup_declaration
949951
{ add_attributes($2, $1); $$=$2; }
@@ -1046,7 +1048,22 @@ constraint_block_item:
10461048
;
10471049

10481050
constraint_expression:
1049-
expression
1051+
expression_or_dist ';'
1052+
;
1053+
1054+
dist_list:
1055+
dist_item
1056+
| dist_list ',' dist_item
1057+
;
1058+
1059+
dist_item:
1060+
value_range
1061+
| value_range dist_weight
1062+
;
1063+
1064+
dist_weight:
1065+
":=" expression
1066+
| ":/" expression
10501067
;
10511068

10521069
constraint_prototype: TOK_CONSTRAINT constraint_identifier ';'
@@ -2314,6 +2331,7 @@ cycle_delay_const_range_expression:
23142331

23152332
expression_or_dist:
23162333
expression
2334+
| expression TOK_DIST '{' dist_list '}'
23172335
;
23182336

23192337
// System Verilog standard 1800-2017
@@ -3600,6 +3618,11 @@ expression:
36003618
{ init($$, ID_constant); stack_expr($$).type()=typet(ID_string); addswap($$, ID_value, $1); }
36013619
;
36023620

3621+
value_range:
3622+
expression
3623+
| '[' expression TOK_COLON expression ']'
3624+
;
3625+
36033626
indexed_range:
36043627
expression TOK_PLUSCOLON constant_expression
36053628
{ init($$, ID_verilog_indexed_part_select_plus); mto($$, $1); mto($$, $3); }

src/verilog/scanner.l

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ void verilog_scanner_init()
264264
"->" { SYSTEM_VERILOG_OPERATOR(TOK_MINUSGREATER, "->"); }
265265
"'" { SYSTEM_VERILOG_OPERATOR('\'', "'"); }
266266
"::" { SYSTEM_VERILOG_OPERATOR(TOK_COLONCOLON, "::"); }
267+
":=" { SYSTEM_VERILOG_OPERATOR(TOK_COLONEQUAL, ":="); }
268+
":/" { SYSTEM_VERILOG_OPERATOR(TOK_COLONSLASH, ":/"); }
267269
"==?" { SYSTEM_VERILOG_OPERATOR(TOK_EQUALEQUALQUESTION, "==?"); }
268270
"!=?" { SYSTEM_VERILOG_OPERATOR(TOK_EXCLAMEQUALQUESTION, "!=?"); }
269271
/* Table 16-1 in 1800-2017 suggests the following tokens for sequence operators */

0 commit comments

Comments
 (0)