Commit d57c9670 by Zachary Snow

added partial support for implicitly sized arrays

parent 454afa97
...@@ -592,6 +592,7 @@ DeclOrStmtTokens(delim) :: { [DeclToken] } ...@@ -592,6 +592,7 @@ DeclOrStmtTokens(delim) :: { [DeclToken] }
| "<=" opt(DelayOrEventControl) Expr delim { [DTAsgnNBlk $2 $3] } | "<=" opt(DelayOrEventControl) Expr delim { [DTAsgnNBlk $2 $3] }
DeclOrStmtToken :: { DeclToken } DeclOrStmtToken :: { DeclToken }
: "," { DTComma } : "," { DTComma }
| "[" "]" { DTAutoDim }
| PartSelect { DTRange $1 } | PartSelect { DTRange $1 }
| Identifier { DTIdent $1 } | Identifier { DTIdent $1 }
| Direction { DTDir $1 } | Direction { DTDir $1 }
......
...@@ -46,6 +46,7 @@ import Language.SystemVerilog.AST ...@@ -46,6 +46,7 @@ import Language.SystemVerilog.AST
-- [PUBLIC]: combined (irregular) tokens for declarations -- [PUBLIC]: combined (irregular) tokens for declarations
data DeclToken data DeclToken
= DTComma = DTComma
| DTAutoDim
| DTAsgn AsgnOp Expr | DTAsgn AsgnOp Expr
| DTAsgnNBlk (Maybe Timing) Expr | DTAsgnNBlk (Maybe Timing) Expr
| DTRange (PartSelectMode, Range) | DTRange (PartSelectMode, Range)
...@@ -384,10 +385,22 @@ takeRanges (token : tokens) = ...@@ -384,10 +385,22 @@ takeRanges (token : tokens) =
case token of case token of
DTRange (NonIndexed, r) -> (r : rs, rest ) DTRange (NonIndexed, r) -> (r : rs, rest )
DTBit s -> (asRange s : 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) _ -> ([] , token : tokens)
where where
(rs, rest) = takeRanges tokens (rs, rest) = takeRanges tokens
asRange s = (Number "0", BinOp Sub s (Number "1")) 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 -- Matching DTAsgnNBlk here allows tripLookahead to work both for standard
-- declarations and in `parseDTsAsDeclOrAsgn`, where we're checking for an -- declarations and in `parseDTsAsDeclOrAsgn`, where we're checking for an
......
...@@ -6,8 +6,7 @@ module top; ...@@ -6,8 +6,7 @@ module top;
logic [3:0] data; logic [3:0] data;
} packet_t; } packet_t;
initial begin initial begin
// TODO: Add support for implicitly sized arrays. logic [1:0] array[] = '{ 2'b10, 2'b01, 2'b11, 2'b00 };
logic [1:0] array[4] = '{ 2'b10, 2'b01, 2'b11, 2'b00 };
packet_t packet = {<<4{ {<<2{array}} }}; packet_t packet = {<<4{ {<<2{array}} }};
$display("packet addr = %b", packet.addr); $display("packet addr = %b", packet.addr);
$display("packet data = %b", packet.data); $display("packet data = %b", packet.data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment