Fix multi-range indices assignment (#5534) (#5547)

Co-authored-by: Udaya Raj Subedi <075bei047.udaya@pcampus.edu.np>
This commit is contained in:
Yilou Wang 2024-10-21 15:56:50 +02:00 committed by GitHub
parent 8c3cc3af8f
commit 2409f32d87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View File

@ -1404,9 +1404,19 @@ class RandomizeVisitor final : public VNVisitor {
AstVarRef* tempRefp = new AstVarRef{fl, newRandLoopIndxp, VAccess::READ};
if (VN_IS(tempDTypep, DynArrayDType))
tempElementp = new AstCMethodHard{fl, tempExprp, "atWrite", tempRefp};
else if (VN_IS(tempDTypep, UnpackArrayDType))
tempElementp = new AstArraySel{fl, tempExprp, tempRefp};
else if (VN_IS(tempDTypep, AssocArrayDType))
else if (VN_IS(tempDTypep, UnpackArrayDType)) {
AstNodeArrayDType* const aryDTypep = VN_CAST(tempDTypep, NodeArrayDType);
// Adjust the bitp to ensure it covers all possible indices
tempElementp = new AstArraySel{
fl, tempExprp,
new AstSel{
fl,
new AstSub{fl, tempRefp,
new AstConst{fl, static_cast<uint32_t>(aryDTypep->lo())}},
new AstConst{fl, 0},
new AstConst{
fl, static_cast<uint32_t>(V3Number::log2b(aryDTypep->hi()) + 1)}}};
} else if (VN_IS(tempDTypep, AssocArrayDType))
tempElementp = new AstAssocSel{fl, tempExprp, tempRefp};
else if (VN_IS(tempDTypep, QueueDType))
tempElementp = new AstCMethodHard{fl, tempExprp, "atWriteAppend", tempRefp};

View File

@ -34,10 +34,14 @@ endclass
class unconstrained_unpacked_array_test;
rand bit [2:0] [15:0] unpacked_array [3][5];
rand int unpacked_array1 [9:3][4:8];
rand int unpacked_array2 [3:9][8:4];
function new();
unpacked_array = '{ '{default: '{default: 'h0}},
'{default: '{default: 'h1}},
'{default: '{default: 'h2}}};
unpacked_array1 = '{default: '{default: 0}};
unpacked_array2 = '{default: '{default: 0}};
endfunction
function void check_randomization();
@ -47,6 +51,12 @@ class unconstrained_unpacked_array_test;
`check_rand(this, this.unpacked_array[i][j])
end
end
foreach (unpacked_array1[i, j]) begin
`check_rand(this, this.unpacked_array1[i][j])
end
foreach (unpacked_array2[i, j]) begin
`check_rand(this, this.unpacked_array2[i][j])
end
endfunction
endclass