From 13b62fd81e49b9619d230ec3b893880c1efdfeb3 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Tue, 11 Aug 2020 18:37:21 -0400 Subject: [PATCH] support structs of integers --- src/Convert/IntTypes.hs | 14 ++++++++++++++ test/basic/struct_integer.sv | 7 +++++++ test/basic/struct_integer.v | 4 ++++ 3 files changed, 25 insertions(+) create mode 100644 test/basic/struct_integer.sv create mode 100644 test/basic/struct_integer.v diff --git a/src/Convert/IntTypes.hs b/src/Convert/IntTypes.hs index 47cb05b..60d2cb8 100644 --- a/src/Convert/IntTypes.hs +++ b/src/Convert/IntTypes.hs @@ -17,6 +17,20 @@ convert = traverseTypes $ traverseNestedTypes convertType convertType :: Type -> Type +convertType (Struct pk fields rs) = + Struct pk fields' rs + where fields' = convertStructFields fields +convertType (Union pk fields rs) = + Union pk fields' rs + where fields' = convertStructFields fields convertType (IntegerAtom kw sg) = elaborateIntegerAtom $ IntegerAtom kw sg convertType (IntegerVector TBit sg rs) = IntegerVector TLogic sg rs convertType other = other + +convertStructFields :: [(Type, Identifier)] -> [(Type, Identifier)] +convertStructFields fields = + zip (map (convertStructFieldType . fst) fields) (map snd fields) + +convertStructFieldType :: Type -> Type +convertStructFieldType (IntegerAtom TInteger sg) = IntegerAtom TInt sg +convertStructFieldType t = t diff --git a/test/basic/struct_integer.sv b/test/basic/struct_integer.sv new file mode 100644 index 0000000..6315cab --- /dev/null +++ b/test/basic/struct_integer.sv @@ -0,0 +1,7 @@ +module top; + typedef struct packed { + integer a, b, c; + } S; + S s = '{a: 1, b: 2, c: 3}; + initial #1 $display("%b %b %b %b", s, s.a, s.b, s.c); +endmodule diff --git a/test/basic/struct_integer.v b/test/basic/struct_integer.v new file mode 100644 index 0000000..31cf607 --- /dev/null +++ b/test/basic/struct_integer.v @@ -0,0 +1,4 @@ +module top; + wire [32*3-1:0] s = {32'd1, 32'd2, 32'd3}; + initial #1 $display("%b %b %b %b", s, s[64+:32], s[32+:32], s[0+:32]); +endmodule