From d57c9670905bb692424a69562fdd5cc2b8f7fe74 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sat, 28 Sep 2019 16:57:36 -0400 Subject: [PATCH] added partial support for implicitly sized arrays --- src/Language/SystemVerilog/Parser/Parse.y | 1 + src/Language/SystemVerilog/Parser/ParseDecl.hs | 13 +++++++++++++ test/basic/stream.sv | 3 +-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Language/SystemVerilog/Parser/Parse.y b/src/Language/SystemVerilog/Parser/Parse.y index 9bf0117..c577dae 100644 --- a/src/Language/SystemVerilog/Parser/Parse.y +++ b/src/Language/SystemVerilog/Parser/Parse.y @@ -592,6 +592,7 @@ DeclOrStmtTokens(delim) :: { [DeclToken] } | "<=" opt(DelayOrEventControl) Expr delim { [DTAsgnNBlk $2 $3] } DeclOrStmtToken :: { DeclToken } : "," { DTComma } + | "[" "]" { DTAutoDim } | PartSelect { DTRange $1 } | Identifier { DTIdent $1 } | Direction { DTDir $1 } diff --git a/src/Language/SystemVerilog/Parser/ParseDecl.hs b/src/Language/SystemVerilog/Parser/ParseDecl.hs index 6b5bcad..71e255c 100644 --- a/src/Language/SystemVerilog/Parser/ParseDecl.hs +++ b/src/Language/SystemVerilog/Parser/ParseDecl.hs @@ -46,6 +46,7 @@ import Language.SystemVerilog.AST -- [PUBLIC]: combined (irregular) tokens for declarations data DeclToken = DTComma + | DTAutoDim | DTAsgn AsgnOp Expr | DTAsgnNBlk (Maybe Timing) Expr | DTRange (PartSelectMode, Range) @@ -384,10 +385,22 @@ takeRanges (token : tokens) = case token of DTRange (NonIndexed, r) -> (r : rs, rest ) DTBit s -> (asRange s : rs, rest ) + DTAutoDim -> + case rest of + (DTAsgn AsgnOpEq (Pattern l) : _) -> autoDim l + (DTAsgn AsgnOpEq (Concat l) : _) -> autoDim l + _ -> ([] , token : tokens) _ -> ([] , token : tokens) where (rs, rest) = takeRanges tokens asRange s = (Number "0", BinOp Sub s (Number "1")) + autoDim :: [a] -> ([Range], [DeclToken]) + autoDim l = + ((lo, hi) : rs, rest) + where + n = length l + lo = Number "0" + hi = Number $ show (n - 1) -- Matching DTAsgnNBlk here allows tripLookahead to work both for standard -- declarations and in `parseDTsAsDeclOrAsgn`, where we're checking for an diff --git a/test/basic/stream.sv b/test/basic/stream.sv index a856003..c60713d 100644 --- a/test/basic/stream.sv +++ b/test/basic/stream.sv @@ -6,8 +6,7 @@ module top; logic [3:0] data; } packet_t; initial begin - // TODO: Add support for implicitly sized arrays. - logic [1:0] array[4] = '{ 2'b10, 2'b01, 2'b11, 2'b00 }; + logic [1:0] array[] = '{ 2'b10, 2'b01, 2'b11, 2'b00 }; packet_t packet = {<<4{ {<<2{array}} }}; $display("packet addr = %b", packet.addr); $display("packet data = %b", packet.data);