Skip to content

Commit a5de607

Browse files
committed
allow type declarations in tasks and functions
IEEE Std 1800-2023 has the following structural hierarchy: 1. A.2.6 Function declarations and A.2.7 Task declarations 2. A.2.8 Block item declarations 3. A.2.1.3 Type declarations Therefore, type declarations can be placed inside task and function declarations.
1 parent 80a2f0c commit a5de607

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/Language/SystemVerilog/Parser/Parse.y

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Language.SystemVerilog.Parser.Tokens
3333
%tokentype { Token }
3434
%error { parseErrorTok }
3535

36-
%expect 0
36+
%expect 4
3737

3838
%token
3939

@@ -947,9 +947,17 @@ ImportOrExport :: { [PackageItem] }
947947
: "import" PackageImportItems ";" { map (uncurry Import) $2 }
948948
| "export" PackageImportItems ";" { map (uncurry Export) $2 }
949949
| "export" "*" "::" "*" ";" { [Export "" ""] }
950+
BlockItemDecls :: { [Decl] }
951+
: {- empty -} { [] }
952+
| ";" BlockItemDecls { $2 }
953+
| BlockItemDecl BlockItemDecls { $1 ++ $2 }
954+
BlockItemDecl :: { [Decl] }
955+
: DataDecl { $1 }
956+
DataDecl :: { [Decl] }
957+
: Typedef { [$1] }
950958
TaskOrFunction :: { PackageItem }
951-
: "function" Lifetime FuncRetAndName TFItems DeclsAndStmts endfunction StrTag {% checkTag (snd $3) $7 $ Function $2 (fst $3) (snd $3) (map makeInput $4 ++ fst $5) (snd $5) }
952-
| "task" Lifetime Identifier TFItems DeclsAndStmts endtask StrTag {% checkTag $3 $7 $ Task $2 $3 ($4 ++ fst $5) (snd $5) }
959+
: "function" Lifetime FuncRetAndName TFItems BlockItemDecls DeclsAndStmts endfunction StrTag {% checkTag (snd $3) $8 $ Function $2 (fst $3) (snd $3) (map makeInput $4 ++ $5 ++ fst $6) (snd $6) }
960+
| "task" Lifetime Identifier TFItems BlockItemDecls DeclsAndStmts endtask StrTag {% checkTag $3 $8 $ Task $2 $3 ($4 ++ $5 ++ fst $6) (snd $6) }
953961
Typedef :: { Decl }
954962
: "typedef" Type Identifier ";" { ParamType Localparam $3 $2 }
955963
| "typedef" Type Identifier DimensionsNonEmpty ";" { ParamType Localparam $3 (UnpackedType $2 $4) }

test/core/tf_typedef.sv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module top;
2+
task t;
3+
typedef bit u;
4+
$display("t = %d", u'(0));
5+
endtask
6+
function f;
7+
typedef bit u;
8+
return u'(1);
9+
endfunction
10+
initial t();
11+
initial $display("f = %d", f());
12+
endmodule

test/core/tf_typedef.v

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module top;
2+
task t;
3+
$display("t = %d", 1'd0);
4+
endtask
5+
function f;
6+
input reg _sv2v_unused;
7+
f = 1'd1;
8+
endfunction
9+
initial t;
10+
initial $display("f = %d", f(0));
11+
endmodule

0 commit comments

Comments
 (0)