From a6ebc0e3ff6987b4224bb9d831eed6ca8c61024b Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sun, 9 May 2021 19:23:00 -0400 Subject: [PATCH] fix elaboration of struct array fields referenced hierarchically - `expr.name[idx]` considers `expr.name` could be a struct array - remove fallback struct type lookups which were guaranteed to fail --- src/Convert/Struct.hs | 9 +++++---- test/basic/struct_hier_bit.sv | 12 ++++++++++++ test/basic/struct_hier_bit.v | 7 +++++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 test/basic/struct_hier_bit.sv create mode 100644 test/basic/struct_hier_bit.v diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index 12d02dd..806fd76 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -349,7 +349,7 @@ convertSubExpr scopes (Dot e x) = else Range e' IndexedMinus (base, len) convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) = if isntStruct subExprType then - fallbackType scopes orig' + (UnknownType, orig') else if structIsntReady subExprType then (replaceInnerTypeRange NonIndexed rOuter' fieldType, orig') else @@ -371,7 +371,7 @@ convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) = endianCondRange dim rangeLeft rangeRight convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) = if isntStruct subExprType then - fallbackType scopes orig' + (UnknownType, orig') else if structIsntReady subExprType then (replaceInnerTypeRange mode (baseO', lenO') fieldType, orig') else @@ -401,7 +401,7 @@ convertSubExpr scopes (Range e mode (left, right)) = r' = (left', right') convertSubExpr scopes (Bit (Dot e x) i) = if isntStruct subExprType then - fallbackType scopes orig' + (dropInnerTypeRange backupType, orig') else if structIsntReady subExprType then (dropInnerTypeRange fieldType, orig') else @@ -409,6 +409,7 @@ convertSubExpr scopes (Bit (Dot e x) i) = where (subExprType, e') = convertSubExpr scopes e (_, i') = convertSubExpr scopes i + (backupType, _) = fallbackType scopes $ Dot e' x orig' = Bit (Dot e' x) i' (fieldType, bounds, dims) = lookupFieldInfo subExprType x [dim] = dims @@ -417,7 +418,7 @@ convertSubExpr scopes (Bit (Dot e x) i) = iFlat = endianCondExpr dim left right convertSubExpr scopes (Bit e i) = if t == UnknownType - then fallbackType scopes $ Bit e' i' + then (UnknownType, Bit e' i') else (dropInnerTypeRange t, Bit e' i') where (t, e') = convertSubExpr scopes e diff --git a/test/basic/struct_hier_bit.sv b/test/basic/struct_hier_bit.sv new file mode 100644 index 0000000..8672689 --- /dev/null +++ b/test/basic/struct_hier_bit.sv @@ -0,0 +1,12 @@ +module top; + if (1) begin : blk + struct packed { + logic x, y; + } [1:0] s; + end + assign blk.s[0].x = 0; + assign top.blk.s[0].y = 1; + assign top.blk.s[1].x = 1; + assign blk.s[1].y = 0; + initial #1 $display("%b", blk.s); +endmodule diff --git a/test/basic/struct_hier_bit.v b/test/basic/struct_hier_bit.v new file mode 100644 index 0000000..257b876 --- /dev/null +++ b/test/basic/struct_hier_bit.v @@ -0,0 +1,7 @@ +module top; + if (1) begin : blk + wire [3:0] s; + end + assign blk.s = 4'b1001; + initial #1 $display("%b", blk.s); +endmodule