fix struct array pattern conversion (resolves #60)

This commit is contained in:
Zachary Snow 2020-01-20 17:26:03 -08:00
parent cf4c2a5491
commit 17e17ebd7f
3 changed files with 36 additions and 0 deletions

View File

@ -341,6 +341,15 @@ convertAsgn structs types (lhs, expr) =
isStruct (Struct{}) = True
isStruct _ = False
convertExpr (Struct packing fields (r : rs)) (Pattern items) =
if all null keys
then convertExpr (structTf (r : rs)) (Concat vals)
else Repeat (rangeSize r) [subExpr']
where
(keys, vals) = unzip items
subExpr = Pattern items
structTf = Struct packing fields
subExpr' = convertExpr (structTf rs) subExpr
convertExpr (Struct packing fields (r : rs)) subExpr =
Repeat (rangeSize r) [subExpr']
where

View File

@ -0,0 +1,19 @@
module top;
typedef struct packed {
bit a, b;
} T;
localparam T FOO [4] = '{
'{ 0, 0 },
'{ 0, 1 },
'{ 1, 0 },
'{ 1, 1 }
};
initial begin
$display(FOO[0].a);
$display(FOO[0].b);
$display(FOO[2].a);
$display(FOO[2].b);
end
endmodule

View File

@ -0,0 +1,8 @@
module top;
initial begin
$display(1'b0);
$display(1'b0);
$display(1'b1);
$display(1'b0);
end
endmodule