From 17e17ebd7f2da8bdad970dbff15d53f5fc598536 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Mon, 20 Jan 2020 17:26:03 -0800 Subject: [PATCH] fix struct array pattern conversion (resolves #60) --- src/Convert/Struct.hs | 9 +++++++++ test/basic/struct_array_inline.sv | 19 +++++++++++++++++++ test/basic/struct_array_inline.v | 8 ++++++++ 3 files changed, 36 insertions(+) create mode 100644 test/basic/struct_array_inline.sv create mode 100644 test/basic/struct_array_inline.v diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index 2ff3cba..990c764 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -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 diff --git a/test/basic/struct_array_inline.sv b/test/basic/struct_array_inline.sv new file mode 100644 index 0000000..aec5d94 --- /dev/null +++ b/test/basic/struct_array_inline.sv @@ -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 diff --git a/test/basic/struct_array_inline.v b/test/basic/struct_array_inline.v new file mode 100644 index 0000000..6592042 --- /dev/null +++ b/test/basic/struct_array_inline.v @@ -0,0 +1,8 @@ +module top; + initial begin + $display(1'b0); + $display(1'b0); + $display(1'b1); + $display(1'b0); + end +endmodule