Support repeated forward typedefs.

This commit is contained in:
Wilson Snyder 2020-10-10 11:29:10 -04:00
parent 070bead9f9
commit e25a6334cf
3 changed files with 39 additions and 18 deletions

View File

@ -2165,15 +2165,39 @@ implicit_typeE<dtypep>: // IEEE: part of *data_type_or_implicit
//UNSUP ;
type_declaration<nodep>: // ==IEEE: type_declaration
// // Use idAny, as we can redeclare a typedef on an existing typedef
yTYPEDEF data_type idAny variable_dimensionListE dtypeAttrListE ';'
{ $$ = GRAMMARP->createTypedef($<fl>3, *$3, $5, $2, $4); }
// Data_type expanded
yTYPEDEF data_typeNoRef
/*cont*/ idAny variable_dimensionListE dtypeAttrListE ';'
{ AstNodeDType* dtp = $2;
$$ = GRAMMARP->createTypedef($<fl>3, *$3, $5, dtp, $4); }
| yTYPEDEF packageClassScope idType packed_dimensionListE
/*cont*/ idAny variable_dimensionListE dtypeAttrListE ';'
{ AstRefDType* refp = new AstRefDType($<fl>3, *$3, $2, nullptr);
AstNodeDType* dtp = GRAMMARP->createArray(refp, $4, true);
$$ = GRAMMARP->createTypedef($<fl>5, *$5, $7, dtp, $6); }
| yTYPEDEF packageClassScope idType parameter_value_assignmentClass packed_dimensionListE
/*cont*/ idAny variable_dimensionListE dtypeAttrListE ';'
{ AstRefDType* refp = new AstRefDType($<fl>3, *$3, $2, $4);
AstNodeDType* dtp = GRAMMARP->createArray(refp, $5, true);
$$ = GRAMMARP->createTypedef($<fl>6, *$6, $8, dtp, $7); }
| yTYPEDEF idType packed_dimensionListE
/*cont*/ idAny variable_dimensionListE dtypeAttrListE ';'
{ AstRefDType* refp = new AstRefDType($<fl>2, *$2, nullptr, nullptr);
AstNodeDType* dtp = GRAMMARP->createArray(refp, $3, true);
$$ = GRAMMARP->createTypedef($<fl>4, *$4, $6, dtp, $5); }
| yTYPEDEF idType parameter_value_assignmentClass packed_dimensionListE
/*cont*/ idAny variable_dimensionListE dtypeAttrListE ';'
{ AstRefDType* refp = new AstRefDType($<fl>2, *$2, nullptr, $3);
AstNodeDType* dtp = GRAMMARP->createArray(refp, $4, true);
$$ = GRAMMARP->createTypedef($<fl>5, *$5, $7, dtp, $6); }
// //
| yTYPEDEF id/*interface*/ '.' idAny/*type*/ idAny/*type*/ ';'
{ $$ = nullptr; BBUNSUP($1, "Unsupported: SystemVerilog 2005 typedef in this context"); }
// // Allow redeclaring same typedef again
// // Alternative is use of idAny below, but this will cause conflicts with ablve
| yTYPEDEF idType ';' { $$ = GRAMMARP->createTypedefFwd($<fl>2, *$2); }
// // Combines into above "data_type id" rule
// // Verilator: Not important what it is in the AST, just need to make sure the yaID__aTYPE gets returned
//UNSUP // Below should be idAny to allow duplicate forward defs; need to expand
// // data_type to exclude IDs, or add id__SEMI rule
| yTYPEDEF id ';' { $$ = GRAMMARP->createTypedefFwd($<fl>2, *$2); }
| yTYPEDEF yENUM idAny ';' { $$ = GRAMMARP->createTypedefFwd($<fl>3, *$3); }
| yTYPEDEF ySTRUCT idAny ';' { $$ = GRAMMARP->createTypedefFwd($<fl>3, *$3); }
@ -6192,9 +6216,9 @@ dist_list<nodep>: // ==IEEE: dist_list
;
dist_item<nodep>: // ==IEEE: dist_item + dist_weight
value_range { $$ = $1; }
| value_range yP_COLONEQ expr { $$ = $1; BBUNSUP($1, "Unsupported: dist :="); }
| value_range yP_COLONDIV expr { $$ = $1; BBUNSUP($1, "Unsupported: dist :/"); }
value_range { $$ = $1; /* Same as := 1 */ }
| value_range yP_COLONEQ expr { $$ = $1; nullptr; /*UNSUP-no-UVM*/ }
| value_range yP_COLONDIV expr { $$ = $1; nullptr; /*UNSUP-no-UVM*/ }
;
//UNSUPextern_constraint_declaration: // ==IEEE: extern_constraint_declaration

View File

@ -4,15 +4,6 @@
%Error-UNSUPPORTED: t/t_randomize.v:29:29: Unsupported: solve before
29 | constraint order { solve length before header; }
| ^~~~~~
%Error-UNSUPPORTED: t/t_randomize.v:32:16: Unsupported: dist :/
32 | x dist { [100:102] :/ 1, 200 := 2, 300 := 5, 400};
| ^
%Error-UNSUPPORTED: t/t_randomize.v:32:32: Unsupported: dist :=
32 | x dist { [100:102] :/ 1, 200 := 2, 300 := 5, 400};
| ^~~
%Error-UNSUPPORTED: t/t_randomize.v:32:42: Unsupported: dist :=
32 | x dist { [100:102] :/ 1, 200 := 2, 300 := 5, 400};
| ^~~
%Error-UNSUPPORTED: t/t_randomize.v:32:9: Unsupported: dist
32 | x dist { [100:102] :/ 1, 200 := 2, 300 := 5, 400};
| ^~~~

View File

@ -4,11 +4,15 @@
// any use, without warranty, 2009 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
package pkg;
typedef bit pkg_bit_t;
endpackage
program t;
parameter SIZE = 5;
typedef vec_t; // Forward
//UNSUP typedef vec_t; // Multi-forward is ok
typedef vec_t; // Multi-forward is ok
typedef reg [SIZE-1:0] vec_t;
vec_t a; initial a =0;
@ -20,6 +24,8 @@ program t;
typedef array_t array2_t [2];
array2_t ar [1];
typedef pkg::pkg_bit_t lcl_pkg_bit_t;
// Define before use
// Not sure how well supported this is elsewhere
//UNSUP typedef preuse;