Commit 7eed2fc5 by Zachary Snow

fix handling of multi-dimensional integer array literals (resolves #113)

parent e6e62e88
......@@ -199,20 +199,27 @@ convertExpr (IntegerVector t sg (r:rs)) (Pattern [(":default", e)]) =
-- TODO: This is a conversion for concat array literals with elements
-- that are unsized numbers. This probably belongs somewhere else.
convertExpr (t @ IntegerVector{}) (Pattern items) =
if all (null . fst) items
then convertExpr t $ Concat $ map snd items
if all null names
then convertExpr t $ Concat exprs'
else Pattern items
where
(names, exprs) = unzip items
t' = dropInnerTypeRange t
exprs' = map (convertExpr t') exprs
convertExpr (t @ IntegerVector{}) (Concat exprs) =
if all isUnsizedNumber exprs
then Concat exprs'
else Concat exprs
then Concat $ map (Cast $ Left t') exprs
else Concat $ map (convertExpr t') exprs
where
caster = Cast (Left $ dropInnerTypeRange t)
exprs' = map caster exprs
t' = dropInnerTypeRange t
isUnsizedNumber :: Expr -> Bool
isUnsizedNumber (Number n) = not $ numberIsSized n
isUnsizedNumber (UniOp UniSub e) = isUnsizedNumber e
isUnsizedNumber _ = False
convertExpr (Implicit sg rs) expr =
if null rs
then expr
else convertExpr (IntegerVector TBit sg rs) expr
convertExpr (Struct packing fields (_:rs)) (Concat exprs) =
Concat $ map (convertExpr (Struct packing fields rs)) exprs
convertExpr (Struct packing fields (_:rs)) (Bit e _) =
......
......@@ -21,4 +21,11 @@ module top;
`PRINT(H);
`PRINT(I);
end
localparam [1:0][0:1] P = '{'{default:'d1}, '{default:'d2}};
localparam bit [1:0][0:1] Q = '{'{default:'d2}, '{default:'d1}};
initial begin
$display("%b %b %b", P, P[0], P[1]);
$display("%b %b %b", Q, Q[0], Q[1]);
end
endmodule
......@@ -19,4 +19,11 @@ module top;
$display("%b %2d %2d", H, $bits(H), 8);
$display("%b %2d %2d", I, $bits(I), 1);
end
localparam [3:0] P = 4'b1100;
localparam [3:0] Q = 4'b0011;
initial begin
$display("%b %b %b", P, P[1:0], P[3:2]);
$display("%b %b %b", Q, Q[1:0], Q[3:2]);
end
endmodule
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