From bbb469463bd40c3a987c04e88f832a2e040b0c92 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Thu, 23 Jul 2020 18:23:40 -0600 Subject: [PATCH] fix typing bit and part selects --- src/Convert/Struct.hs | 21 ++++++++++++++++----- test/basic/integer_array.sv | 12 ++++++++++++ test/basic/integer_array.v | 13 +++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index f2e0bed..1929224 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -163,6 +163,17 @@ dropInnerTypeRange t = (_, []) -> unknownType (tf, rs) -> tf $ tail rs +-- produces the type of the given part select, if possible +replaceInnerTypeRange :: PartSelectMode -> Range -> Type -> Type +replaceInnerTypeRange NonIndexed r t = + case typeRanges t of + (_, []) -> unknownType + (tf, rs) -> tf $ r : tail rs +replaceInnerTypeRange IndexedPlus r t = + replaceInnerTypeRange NonIndexed (snd r, RawNum 1) t +replaceInnerTypeRange IndexedMinus r t = + replaceInnerTypeRange NonIndexed (snd r, RawNum 1) t + unknownType :: Type unknownType = Implicit Unspecified [] @@ -341,9 +352,9 @@ convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) = if isntStruct subExprType then fallbackType scopes orig' else if structIsntReady subExprType then - (dropInnerTypeRange fieldType, orig') + (replaceInnerTypeRange NonIndexed rOuter fieldType, orig') else - (dropInnerTypeRange fieldType, undotted) + (replaceInnerTypeRange NonIndexed rOuter fieldType, undotted) where (subExprType, e') = convertSubExpr scopes e orig' = Range (Dot e' x) NonIndexed rOuter @@ -359,9 +370,9 @@ convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) = if isntStruct subExprType then fallbackType scopes orig' else if structIsntReady subExprType then - (dropInnerTypeRange fieldType, orig') + (replaceInnerTypeRange mode (baseO, lenO) fieldType, orig') else - (dropInnerTypeRange fieldType, undotted) + (replaceInnerTypeRange mode (baseO, lenO) fieldType, undotted) where (subExprType, e') = convertSubExpr scopes e orig' = Range (Dot e' x) mode (baseO, lenO) @@ -378,7 +389,7 @@ convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) = undotted = Range e' mode (base, lenO) one = RawNum 1 convertSubExpr scopes (Range e mode r) = - (dropInnerTypeRange t, Range e' mode r) + (replaceInnerTypeRange mode r t, Range e' mode r) where (t, e') = convertSubExpr scopes e convertSubExpr scopes (Bit (Dot e x) i) = if isntStruct subExprType then diff --git a/test/basic/integer_array.sv b/test/basic/integer_array.sv index 39c12f7..5962c64 100644 --- a/test/basic/integer_array.sv +++ b/test/basic/integer_array.sv @@ -28,4 +28,16 @@ module top; $display("%b %b %b", P, P[0], P[1]); $display("%b %b %b", Q, Q[0], Q[1]); end + + initial begin + logic [1:0][0:1][7:0] a; + a[0][0:1] = '{default: 1}; + $display("a: %b", a); + a[1][0+:1] = '{default: 2}; + $display("a: %b", a); + a[1][1-:1] = '{default: 3}; + $display("a: %b", a); + a[1][1][3+:4] = '{default: '1}; + $display("a: %b", a); + end endmodule diff --git a/test/basic/integer_array.v b/test/basic/integer_array.v index 01008f9..119d9f3 100644 --- a/test/basic/integer_array.v +++ b/test/basic/integer_array.v @@ -26,4 +26,17 @@ module top; $display("%b %b %b", P, P[1:0], P[3:2]); $display("%b %b %b", Q, Q[1:0], Q[3:2]); end + + initial begin : block + reg [31:0] a; + a[7:0] = 1; + a[15:8] = 1; + $display("a: %b", a); + a[31:24] = 2; + $display("a: %b", a); + a[23:16] = 3; + $display("a: %b", a); + a[23:19] = 4'b1111; + $display("a: %b", a); + end endmodule