Commit 5f0ccee0 by Zachary Snow

conversion for unsized integer arrays

parent 20dc92f6
......@@ -271,6 +271,19 @@ convertAsgn structs types (lhs, expr) =
convertExpr (IntegerVector t sg (r:rs)) (Pattern [(":default", e)]) =
Repeat (rangeSize r) [e']
where e' = convertExpr (IntegerVector t sg rs) e
-- TODO: This is a conversion for concat array literals with elements
-- that are unsized numbers. This probably belongs somewhere else.
convertExpr (t @ IntegerVector{}) (Concat exprs) =
if all isUnsizedNumber exprs
then Concat exprs'
else Concat exprs
where
size = DimsFn FnBits (Left $ dropInnerTypeRange t)
caster = Cast (Right size)
exprs' = map caster exprs
isUnsizedNumber :: Expr -> Bool
isUnsizedNumber (Number n) = not $ elem '\'' n
isUnsizedNumber _ = False
convertExpr (Struct packing fields (_:rs)) (Concat exprs) =
Concat $ map (convertExpr (Struct packing fields rs)) exprs
convertExpr (Struct packing fields (_:rs)) (Bit e _) =
......
module top;
localparam integer B [4] = { 1, 2, 3, 4 };
localparam byte C [4] = { 1, 2, 3, 4 };
localparam bit D [4] = { 1, 2, 3, 4 };
initial begin
`define PRINT(X) \
$display("%b %2d %2d", {X[0], X[1], X[2], X[3]}, $bits(X), $bits(X[0]));
`PRINT(B);
`PRINT(C);
`PRINT(D);
end
endmodule
module top;
localparam [0:127] B = { 32'h1, 32'h2, 32'h3, 32'h4 };
localparam [0:31] C = { 8'h1, 8'h2, 8'h3, 8'h4 };
localparam [0:3] D = { 1'h1, 1'h0, 1'h1, 1'h0 };
initial begin
$display("%b %2d %2d", B, $bits(B), 32);
$display("%b %2d %2d", C, $bits(C), 8);
$display("%b %2d %2d", D, $bits(D), 1);
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