fix typing bit and part selects

This commit is contained in:
Zachary Snow 2020-07-23 18:23:40 -06:00
parent 359a3de91e
commit bbb469463b
3 changed files with 41 additions and 5 deletions

View File

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

View File

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

View File

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