From 20dc92f6d8a821b49e03cf84ef02369965b4d609 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sun, 16 Feb 2020 23:39:48 -0500 Subject: [PATCH] fix typeof integer slices --- src/Convert/TypeOf.hs | 12 ++++++---- test/basic/dimensions.sv | 6 +++++ test/basic/dimensions.v | 50 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/Convert/TypeOf.hs b/src/Convert/TypeOf.hs index 8f1dee3..15eeca1 100644 --- a/src/Convert/TypeOf.hs +++ b/src/Convert/TypeOf.hs @@ -104,14 +104,18 @@ injectRanges t unpacked = UnpackedType t unpacked -- removes the most significant range of the given type popRange :: Type -> Type popRange (UnpackedType t [_]) = t +popRange (IntegerAtom TInteger sg) = + IntegerVector TLogic sg [] popRange t = - tf $ tail rs - where (tf, rs) = typeRanges t + tf rs + where (tf, _ : rs) = typeRanges t -- replaces the most significant range of the given type replaceRange :: Range -> Type -> Type replaceRange r (UnpackedType t (_ : rs)) = UnpackedType t (r : rs) +replaceRange r (IntegerAtom TInteger sg) = + IntegerVector TLogic sg [r] replaceRange r t = - tf $ r : tail rs - where (tf, rs) = typeRanges t + tf (r : rs) + where (tf, _ : rs) = typeRanges t diff --git a/test/basic/dimensions.sv b/test/basic/dimensions.sv index 5c32d61..ef9af85 100644 --- a/test/basic/dimensions.sv +++ b/test/basic/dimensions.sv @@ -14,6 +14,7 @@ module top; Word Ram[0:9]; type(Ram) RamPair [2]; integer ints [3:0]; + integer ints_rev [0:3]; typedef struct packed { logic x, y, z; } T; logic [$size(T)-1:0] foo; typedef byte unpacked_t [3]; @@ -35,7 +36,12 @@ module top; `EXHAUST(bit); `EXHAUST(byte); `EXHAUST(ints); + `EXHAUST(ints_rev); `EXHAUST(unpacked_t); `EXHAUST(unpacked); + `EXHAUST(type(foo[3:0])); + `EXHAUST(type(ints[2][3:0])); + `EXHAUST(type(ints[1:0])); + `EXHAUST(type(ints_rev[0:1])); end endmodule diff --git a/test/basic/dimensions.v b/test/basic/dimensions.v index aa741de..d77c1cd 100644 --- a/test/basic/dimensions.v +++ b/test/basic/dimensions.v @@ -115,6 +115,16 @@ module top; $display(1); $display(128); + $display(4, 4, 32); + $display(0, 0, 31); + $display(3, 3, 0); + $display(3, 3, 31); + $display(0, 0, 0); + $display(-1, -1, 1); + $display(2); + $display(1); + $display(128); + $display(3, 3, 8); $display(0, 0, 7); $display(2, 2, 0); @@ -135,5 +145,45 @@ module top; $display(1); $display(24); + $display(4, 4, 1'bx); + $display(3, 3, 1'bx); + $display(0, 0, 1'bx); + $display(3, 3, 1'bx); + $display(0, 0, 1'bx); + $display(1, 1, 1'bx); + $display(1); + $display(0); + $display(4); + + $display(4, 4, 1'bx); + $display(3, 3, 1'bx); + $display(0, 0, 1'bx); + $display(3, 3, 1'bx); + $display(0, 0, 1'bx); + $display(1, 1, 1'bx); + $display(1); + $display(0); + $display(4); + + $display(2, 2, 32); + $display(1, 1, 31); + $display(0, 0, 0); + $display(1, 1, 31); + $display(0, 0, 0); + $display(1, 1, 1); + $display(2); + $display(1); + $display(64); + + $display(2, 2, 32); + $display(0, 0, 31); + $display(1, 1, 0); + $display(1, 1, 31); + $display(0, 0, 0); + $display(-1, -1, 1); + $display(2); + $display(1); + $display(64); + end endmodule