Internals: Add isNonPackedArray(). No functional change. (#7334 prep)

This commit is contained in:
Yilou Wang 2026-04-04 14:31:09 -04:00 committed by Wilson Snyder
parent adb48046c2
commit 3b454a6f60
5 changed files with 16 additions and 23 deletions

View File

@ -125,6 +125,8 @@ public:
virtual AstNodeDType* subDTypep() const VL_MT_STABLE { return nullptr; } virtual AstNodeDType* subDTypep() const VL_MT_STABLE { return nullptr; }
virtual AstNodeDType* subDType2p() const VL_MT_STABLE { return nullptr; } virtual AstNodeDType* subDType2p() const VL_MT_STABLE { return nullptr; }
virtual bool isAggregateType() const { return false; } virtual bool isAggregateType() const { return false; }
// True for unpacked, dynamic, queue, and associative arrays (not packed arrays)
bool isNonPackedArray() const;
virtual bool isFourstate() const; virtual bool isFourstate() const;
// Ideally an IEEE $typename // Ideally an IEEE $typename
virtual string prettyDTypeName(bool) const { return prettyTypeName(); } virtual string prettyDTypeName(bool) const { return prettyTypeName(); }

View File

@ -1013,6 +1013,11 @@ bool AstNodeDType::similarDType(const AstNodeDType* samep) const {
bool AstNodeDType::isFourstate() const { return basicp() && basicp()->isFourstate(); } bool AstNodeDType::isFourstate() const { return basicp() && basicp()->isFourstate(); }
bool AstNodeDType::isNonPackedArray() const {
return VN_IS(this, UnpackArrayDType) || VN_IS(this, DynArrayDType)
|| VN_IS(this, QueueDType) || VN_IS(this, AssocArrayDType);
}
class AstNodeDType::CTypeRecursed final { class AstNodeDType::CTypeRecursed final {
public: public:
string m_type; // The base type, e.g.: "Foo_t"s string m_type; // The base type, e.g.: "Foo_t"s

View File

@ -280,9 +280,7 @@ class EmitCHeader final : public EmitCConstInit {
enum class AttributeType { Width, Dimension }; enum class AttributeType { Width, Dimension };
// Get member attribute based on type // Get member attribute based on type
int getNodeAttribute(const AstMemberDType* itemp, AttributeType type) { int getNodeAttribute(const AstMemberDType* itemp, AttributeType type) {
const bool isArrayType const bool isArrayType = itemp->dtypep()->isNonPackedArray();
= VN_IS(itemp->dtypep(), UnpackArrayDType) || VN_IS(itemp->dtypep(), DynArrayDType)
|| VN_IS(itemp->dtypep(), QueueDType) || VN_IS(itemp->dtypep(), AssocArrayDType);
switch (type) { switch (type) {
case AttributeType::Width: { case AttributeType::Width: {
if (isArrayType) { if (isArrayType) {

View File

@ -1136,8 +1136,7 @@ class ConstraintExprVisitor final : public VNVisitor {
AstClassRefDType* elemClassRefDtp = nullptr; AstClassRefDType* elemClassRefDtp = nullptr;
{ {
AstNodeDType* varDtp = varp->dtypep()->skipRefp(); AstNodeDType* varDtp = varp->dtypep()->skipRefp();
if (VN_IS(varDtp, DynArrayDType) || VN_IS(varDtp, QueueDType) if (varDtp->isNonPackedArray()) {
|| VN_IS(varDtp, UnpackArrayDType) || VN_IS(varDtp, AssocArrayDType)) {
AstNodeDType* const elemDtp = varDtp->subDTypep()->skipRefp(); AstNodeDType* const elemDtp = varDtp->subDTypep()->skipRefp();
elemClassRefDtp = VN_CAST(elemDtp, ClassRefDType); elemClassRefDtp = VN_CAST(elemDtp, ClassRefDType);
if (elemClassRefDtp) { if (elemClassRefDtp) {
@ -1209,9 +1208,7 @@ class ConstraintExprVisitor final : public VNVisitor {
AstVar* const memberVarp = VN_CAST(mnodep, Var); AstVar* const memberVarp = VN_CAST(mnodep, Var);
if (!memberVarp || !memberVarp->rand().isRandomizable()) continue; if (!memberVarp || !memberVarp->rand().isRandomizable()) continue;
AstNodeDType* const memberDtp = memberVarp->dtypep()->skipRefp(); AstNodeDType* const memberDtp = memberVarp->dtypep()->skipRefp();
if (VN_IS(memberDtp, ClassRefDType) || VN_IS(memberDtp, DynArrayDType) if (VN_IS(memberDtp, ClassRefDType) || memberDtp->isNonPackedArray())
|| VN_IS(memberDtp, QueueDType) || VN_IS(memberDtp, UnpackArrayDType)
|| VN_IS(memberDtp, AssocArrayDType))
continue; continue;
const int memberWidth = memberDtp->width(); const int memberWidth = memberDtp->width();
@ -1281,9 +1278,7 @@ class ConstraintExprVisitor final : public VNVisitor {
VAccess::READWRITE}, VAccess::READWRITE},
VCMethod::RANDOMIZER_WRITE_VAR}; VCMethod::RANDOMIZER_WRITE_VAR};
uint32_t dimension = 0; uint32_t dimension = 0;
if (VN_IS(varp->dtypep(), UnpackArrayDType) || VN_IS(varp->dtypep(), DynArrayDType) if (varp->dtypep()->isNonPackedArray()) {
|| VN_IS(varp->dtypep(), QueueDType)
|| VN_IS(varp->dtypep(), AssocArrayDType)) {
const std::pair<uint32_t, uint32_t> dims const std::pair<uint32_t, uint32_t> dims
= varp->dtypep()->dimensions(/*includeBasic=*/true); = varp->dtypep()->dimensions(/*includeBasic=*/true);
const uint32_t unpackedDimensions = dims.second; const uint32_t unpackedDimensions = dims.second;
@ -1316,8 +1311,7 @@ class ConstraintExprVisitor final : public VNVisitor {
methodp->addPinsp(varRefp); methodp->addPinsp(varRefp);
} }
AstNodeDType* tmpDtypep = varp->dtypep(); AstNodeDType* tmpDtypep = varp->dtypep();
while (VN_IS(tmpDtypep, UnpackArrayDType) || VN_IS(tmpDtypep, DynArrayDType) while (tmpDtypep->isNonPackedArray())
|| VN_IS(tmpDtypep, QueueDType) || VN_IS(tmpDtypep, AssocArrayDType))
tmpDtypep = tmpDtypep->subDTypep(); tmpDtypep = tmpDtypep->subDTypep();
const size_t width = tmpDtypep->width(); const size_t width = tmpDtypep->width();
methodp->addPinsp( methodp->addPinsp(
@ -3370,8 +3364,7 @@ class RandomizeVisitor final : public VNVisitor {
dtypep->findBasicDType(VBasicDTypeKwd::UINT32)}; dtypep->findBasicDType(VBasicDTypeKwd::UINT32)};
}; };
AstNodeExpr* tempElementp = nullptr; AstNodeExpr* tempElementp = nullptr;
while (VN_IS(tempDTypep, DynArrayDType) || VN_IS(tempDTypep, UnpackArrayDType) while (tempDTypep->isNonPackedArray()) {
|| VN_IS(tempDTypep, AssocArrayDType) || VN_IS(tempDTypep, QueueDType)) {
AstVar* const newRandLoopIndxp = createLoopIndex(tempDTypep); AstVar* const newRandLoopIndxp = createLoopIndex(tempDTypep);
randLoopIndxp = AstNode::addNext(randLoopIndxp, newRandLoopIndxp); randLoopIndxp = AstNode::addNext(randLoopIndxp, newRandLoopIndxp);
AstNodeExpr* const tempExprp = tempElementp ? tempElementp : exprp; AstNodeExpr* const tempExprp = tempElementp ? tempElementp : exprp;
@ -4397,8 +4390,7 @@ class RandomizeVisitor final : public VNVisitor {
} }
AstNodeDType* tmpDtypep = arrVarp->dtypep(); AstNodeDType* tmpDtypep = arrVarp->dtypep();
while (VN_IS(tmpDtypep, UnpackArrayDType) || VN_IS(tmpDtypep, DynArrayDType) while (tmpDtypep->isNonPackedArray())
|| VN_IS(tmpDtypep, QueueDType) || VN_IS(tmpDtypep, AssocArrayDType))
tmpDtypep = tmpDtypep->subDTypep(); tmpDtypep = tmpDtypep->subDTypep();
const size_t width = tmpDtypep->width(); const size_t width = tmpDtypep->width();

View File

@ -6043,12 +6043,8 @@ class WidthVisitor final : public VNVisitor {
const AstNodeDType* const rhsDtp = nodep->rhsp()->dtypep()->skipRefp(); const AstNodeDType* const rhsDtp = nodep->rhsp()->dtypep()->skipRefp();
// Only check if number of states match for unpacked array to unpacked array // Only check if number of states match for unpacked array to unpacked array
// assignments // assignments
const bool lhsIsUnpackArray const bool lhsIsUnpackArray = lhsDtp->isNonPackedArray();
= VN_IS(lhsDtp, UnpackArrayDType) || VN_IS(lhsDtp, DynArrayDType) const bool rhsIsUnpackArray = rhsDtp->isNonPackedArray();
|| VN_IS(lhsDtp, QueueDType) || VN_IS(lhsDtp, AssocArrayDType);
const bool rhsIsUnpackArray
= VN_IS(rhsDtp, UnpackArrayDType) || VN_IS(rhsDtp, DynArrayDType)
|| VN_IS(rhsDtp, QueueDType) || VN_IS(rhsDtp, AssocArrayDType);
if (lhsIsUnpackArray && rhsIsUnpackArray) { if (lhsIsUnpackArray && rhsIsUnpackArray) {
if (lhsDtp->isFourstate() != rhsDtp->isFourstate()) { if (lhsDtp->isFourstate() != rhsDtp->isFourstate()) {
nodep->v3error("Assignment between 2-state and 4-state types requires " nodep->v3error("Assignment between 2-state and 4-state types requires "