From 4ded2a598d8827bea0fcd9264e5af3c7846654dc Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sun, 15 Aug 2021 12:25:32 -0700 Subject: [PATCH] apply implicit port directions to tasks and functions --- .../SystemVerilog/Parser/ParseDecl.hs | 37 ++++++++++--------- test/core/task_implicit_dir.sv | 19 ++++++++++ test/core/task_implicit_dir.v | 21 +++++++++++ 3 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 test/core/task_implicit_dir.sv create mode 100644 test/core/task_implicit_dir.v diff --git a/src/Language/SystemVerilog/Parser/ParseDecl.hs b/src/Language/SystemVerilog/Parser/ParseDecl.hs index 6767280..5012e0a 100644 --- a/src/Language/SystemVerilog/Parser/ParseDecl.hs +++ b/src/Language/SystemVerilog/Parser/ParseDecl.hs @@ -101,23 +101,6 @@ parseDTsAsPortDecls' pieces = pieces' = filter (not . isAttr) pieces - propagateDirections :: Direction -> [Decl] -> [Decl] - propagateDirections dir (decl@(Variable _ InterfaceT{} _ _ _) : decls) = - decl : propagateDirections dir decls - propagateDirections lastDir (Variable currDir t x a e : decls) = - decl : propagateDirections dir decls - where - decl = Variable dir t x a e - dir = if currDir == Local then lastDir else currDir - propagateDirections lastDir (Net currDir n s t x a e : decls) = - decl : propagateDirections dir decls - where - decl = Net dir n s t x a e - dir = if currDir == Local then lastDir else currDir - propagateDirections dir (decl : decls) = - decl : propagateDirections dir decls - propagateDirections _ [] = [] - portNames :: [Decl] -> [Identifier] portNames = filter (not . null) . map portName portName :: Decl -> Identifier @@ -141,6 +124,24 @@ parseDTsAsPortDecls' pieces = wrapDecl :: [Attr] -> Decl -> ModuleItem wrapDecl attrs decl = foldr MIAttr (MIPackageItem $ Decl decl) attrs +-- internal utility for carying forward port directions in a port list +propagateDirections :: Direction -> [Decl] -> [Decl] +propagateDirections dir (decl@(Variable _ InterfaceT{} _ _ _) : decls) = + decl : propagateDirections dir decls +propagateDirections lastDir (Variable currDir t x a e : decls) = + decl : propagateDirections dir decls + where + decl = Variable dir t x a e + dir = if currDir == Local then lastDir else currDir +propagateDirections lastDir (Net currDir n s t x a e : decls) = + decl : propagateDirections dir decls + where + decl = Net dir n s t x a e + dir = if currDir == Local then lastDir else currDir +propagateDirections dir (decl : decls) = + decl : propagateDirections dir decls +propagateDirections _ [] = [] + -- internal utility for a simple list of port identifiers parseDTsAsIdents :: [DeclToken] -> Maybe [Identifier] parseDTsAsIdents [DTIdent _ x, DTEnd _ _] = Just [x] @@ -235,7 +236,7 @@ parseDTsAsIntantiation l0 delimTok = -- [PUBLIC]: parser for comma-separated task/function port declarations parseDTsAsTFDecls :: [DeclToken] -> [Decl] -parseDTsAsTFDecls = parseDTsAsDecls ModeDefault +parseDTsAsTFDecls = propagateDirections Input . parseDTsAsDecls ModeDefault -- [PUBLIC]; used for "single" declarations, i.e., declarations appearing diff --git a/test/core/task_implicit_dir.sv b/test/core/task_implicit_dir.sv new file mode 100644 index 0000000..610b3ff --- /dev/null +++ b/test/core/task_implicit_dir.sv @@ -0,0 +1,19 @@ +module top; + task t( + integer inp, + output byte out1, + shortint out2 + ); + $display("t(inp = %0d)", inp); + out1 = inp; + out2 = inp; + endtask + initial begin + integer a; + byte b; + shortint c; + a = 5; + t(a, b, c); + $display("a = %0d, b = %0d, c = %0d", a, b, c); + end +endmodule diff --git a/test/core/task_implicit_dir.v b/test/core/task_implicit_dir.v new file mode 100644 index 0000000..ed7be1e --- /dev/null +++ b/test/core/task_implicit_dir.v @@ -0,0 +1,21 @@ +module top; + task t( + input reg [31:0] inp, + output reg [7:0] out1, + output reg [15:0] out2 + ); + begin + $display("t(inp = %0d)", inp); + out1 = inp; + out2 = inp; + end + endtask + initial begin : blk + reg [31:0] a; + reg [7:0] b; + reg [15:0] c; + a = 5; + t(a, b, c); + $display("a = %0d, b = %0d, c = %0d", a, b, c); + end +endmodule