Recognize some basic specify blocks and ignore them (#309)

* Add parser support for specify blocks and specparam
Treated like regular parameters, and so ignored

* Add regression test

* Apply PR feedback

* missed the verilog_lang
This commit is contained in:
ambd161 2025-10-12 14:11:00 -07:00 committed by GitHub
parent c11bb38f58
commit 36e516924f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 50 additions and 1 deletions

View File

@ -152,12 +152,13 @@ record_sta_tests {
package_require package_require
path_group_names path_group_names
prima3 prima3
report_checks_sorted
report_checks_src_attr report_checks_src_attr
report_json1 report_json1
report_json2 report_json2
suppress_msg suppress_msg
verilog_attribute verilog_attribute
report_checks_sorted verilog_specify
} }
define_test_group fast [group_tests all] define_test_group fast [group_tests all]

0
test/verilog_specify.ok Normal file
View File

2
test/verilog_specify.tcl Normal file
View File

@ -0,0 +1,2 @@
# try to load verilog language file
read_verilog verilog_specify.v

20
test/verilog_specify.v Normal file
View File

@ -0,0 +1,20 @@
module counter(clk, reset, in, out);
input clk;
output out;
input reset;
input in;
wire mid;
parameter PARAM1=1;
parameter PARAM2="test";
specify
specparam SPARAM1=2;
specparam SPARAM2="test2";
endspecify
defparam _1415_.PARAM2 = 1;
endmodule

View File

@ -132,6 +132,9 @@ output { return token::OUTPUT; }
parameter { return token::PARAMETER; } parameter { return token::PARAMETER; }
defparam { return token::DEFPARAM; } defparam { return token::DEFPARAM; }
reg { return token::REG; } reg { return token::REG; }
specify { return token::SPECIFY; }
endspecify { return token::ENDSPECIFY; }
specparam { return token::SPECPARAM; }
supply0 { return token::SUPPLY0; } supply0 { return token::SUPPLY0; }
supply1 { return token::SUPPLY1; } supply1 { return token::SUPPLY1; }
tri { return token::TRI; } tri { return token::TRI; }

View File

@ -83,6 +83,7 @@ sta::VerilogParse::error(const location_type &loc,
} }
%token INT CONSTANT ID STRING MODULE ENDMODULE ASSIGN PARAMETER DEFPARAM %token INT CONSTANT ID STRING MODULE ENDMODULE ASSIGN PARAMETER DEFPARAM
%token SPECIFY ENDSPECIFY SPECPARAM
%token WIRE WAND WOR TRI INPUT OUTPUT INOUT SUPPLY1 SUPPLY0 REG %token WIRE WAND WOR TRI INPUT OUTPUT INOUT SUPPLY1 SUPPLY0 REG
%token ATTR_OPEN ATTR_CLOSED %token ATTR_OPEN ATTR_CLOSED
@ -99,6 +100,8 @@ sta::VerilogParse::error(const location_type &loc,
%type <stmt> stmt declaration instance parameter parameter_dcls parameter_dcl %type <stmt> stmt declaration instance parameter parameter_dcls parameter_dcl
%type <stmt> defparam param_values param_value port_dcl %type <stmt> defparam param_values param_value port_dcl
%type <stmt_seq> stmts stmt_seq net_assignments continuous_assign port_dcls %type <stmt_seq> stmts stmt_seq net_assignments continuous_assign port_dcls
%type <stmt> specify_block
%type <stmt_seq> specify_stmts
%type <assign> net_assignment %type <assign> net_assignment
%type <dcl_arg> dcl_arg %type <dcl_arg> dcl_arg
%type <dcl_arg_seq> dcl_args %type <dcl_arg_seq> dcl_args
@ -232,6 +235,7 @@ stmt:
| defparam | defparam
| declaration | declaration
| instance | instance
| specify_block
| error ';' | error ';'
{ yyerrok; $$ = nullptr; } { yyerrok; $$ = nullptr; }
; ;
@ -240,6 +244,25 @@ stmt_seq:
continuous_assign continuous_assign
; ;
/* specify blocks are used by some comercial tools to convey macro timing
* and other metadata.
* Their presence is not forbidden in structural verilog, this is a placeholder
* that just ignores them and allows verilog processing to proceed
* <<TODO>> if someone in the future wants implement support for timing info
* via specify blocks, implement proper parsing here
*/
specify_block:
SPECIFY specify_stmts ENDSPECIFY
{ $$ = nullptr; }
;
specify_stmts:
SPECPARAM parameter_dcl ';'
{ $$ = nullptr; }
| specify_stmts SPECPARAM parameter_dcl ';'
{ $$ = nullptr; }
;
/* Parameters are parsed and ignored. */ /* Parameters are parsed and ignored. */
parameter: parameter:
PARAMETER parameter_dcls ';' PARAMETER parameter_dcls ';'