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
This commit is contained in:
Zachary Snow 2021-05-09 19:23:00 -04:00
parent f71accb3c8
commit a6ebc0e3ff
3 changed files with 24 additions and 4 deletions

View File

@ -349,7 +349,7 @@ convertSubExpr scopes (Dot e x) =
else Range e' IndexedMinus (base, len) else Range e' IndexedMinus (base, len)
convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) = convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
if isntStruct subExprType then if isntStruct subExprType then
fallbackType scopes orig' (UnknownType, orig')
else if structIsntReady subExprType then else if structIsntReady subExprType then
(replaceInnerTypeRange NonIndexed rOuter' fieldType, orig') (replaceInnerTypeRange NonIndexed rOuter' fieldType, orig')
else else
@ -371,7 +371,7 @@ convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
endianCondRange dim rangeLeft rangeRight endianCondRange dim rangeLeft rangeRight
convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) = convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) =
if isntStruct subExprType then if isntStruct subExprType then
fallbackType scopes orig' (UnknownType, orig')
else if structIsntReady subExprType then else if structIsntReady subExprType then
(replaceInnerTypeRange mode (baseO', lenO') fieldType, orig') (replaceInnerTypeRange mode (baseO', lenO') fieldType, orig')
else else
@ -401,7 +401,7 @@ convertSubExpr scopes (Range e mode (left, right)) =
r' = (left', right') r' = (left', right')
convertSubExpr scopes (Bit (Dot e x) i) = convertSubExpr scopes (Bit (Dot e x) i) =
if isntStruct subExprType then if isntStruct subExprType then
fallbackType scopes orig' (dropInnerTypeRange backupType, orig')
else if structIsntReady subExprType then else if structIsntReady subExprType then
(dropInnerTypeRange fieldType, orig') (dropInnerTypeRange fieldType, orig')
else else
@ -409,6 +409,7 @@ convertSubExpr scopes (Bit (Dot e x) i) =
where where
(subExprType, e') = convertSubExpr scopes e (subExprType, e') = convertSubExpr scopes e
(_, i') = convertSubExpr scopes i (_, i') = convertSubExpr scopes i
(backupType, _) = fallbackType scopes $ Dot e' x
orig' = Bit (Dot e' x) i' orig' = Bit (Dot e' x) i'
(fieldType, bounds, dims) = lookupFieldInfo subExprType x (fieldType, bounds, dims) = lookupFieldInfo subExprType x
[dim] = dims [dim] = dims
@ -417,7 +418,7 @@ convertSubExpr scopes (Bit (Dot e x) i) =
iFlat = endianCondExpr dim left right iFlat = endianCondExpr dim left right
convertSubExpr scopes (Bit e i) = convertSubExpr scopes (Bit e i) =
if t == UnknownType if t == UnknownType
then fallbackType scopes $ Bit e' i' then (UnknownType, Bit e' i')
else (dropInnerTypeRange t, Bit e' i') else (dropInnerTypeRange t, Bit e' i')
where where
(t, e') = convertSubExpr scopes e (t, e') = convertSubExpr scopes e

View File

@ -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

View File

@ -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