Skip to content

Commit

Permalink
[ADDITIVE] Update register, register file and field validators to use…
Browse files Browse the repository at this point in the history
… hierarchical validation. Fix oversights in address block and memory map base validators.
  • Loading branch information
hagantsa committed Aug 16, 2024
1 parent 06b41e9 commit 671d243
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 241 deletions.
11 changes: 7 additions & 4 deletions IPXACTmodels/Component/validators/AddressBlockValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool AddressBlockValidator::hasValidRegisterData(QSharedPointer<AddressBlock> ad
qint64 aubInt = getExpressionParser()->parseExpression(addressUnitBits).toLongLong(&aubChangeOk);
qint64 addressBlockRange = getExpressionParser()->parseExpression(addressBlock->getRange()).toLongLong();

auto registerData = addressBlock->getRegisterData();
auto registerDataCopy = QSharedPointer<QList<QSharedPointer<RegisterBase> > >(new QList(*addressBlock->getRegisterData()));

bool errorFound = false;

Expand All @@ -171,13 +171,13 @@ bool AddressBlockValidator::hasValidRegisterData(QSharedPointer<AddressBlock> ad
getExpressionParser()->parseExpression(registerBaseB->getAddressOffset()).toLongLong();
};

std::sort(registerData->begin(), registerData->end(), sortByAddressOffset);
std::sort(registerDataCopy->begin(), registerDataCopy->end(), sortByAddressOffset);
qint64 lastEndAddress = -1;

bool lastWasRegister = true;

// Register and register file validity together must be checked before separately
for (auto regIter = registerData->begin(); regIter != registerData->end(); ++regIter)
for (auto regIter = registerDataCopy->begin(); regIter != registerDataCopy->end(); ++regIter)
{
QSharedPointer<Register> targetRegister = (*regIter).dynamicCast<Register>();
if (targetRegister)
Expand Down Expand Up @@ -244,7 +244,7 @@ bool AddressBlockValidator::hasValidRegisterData(QSharedPointer<AddressBlock> ad
}

// Validate registers and register files separately
for (auto const& registerBase : *registerData)
for (auto const& registerBase : *registerDataCopy)
{
if (QSharedPointer<Register> asRegister = registerBase.dynamicCast<Register>();
asRegister && !registerValidator_->validate(asRegister))
Expand Down Expand Up @@ -399,6 +399,9 @@ bool AddressBlockValidator::markRegisterOverlap(QList<QSharedPointer<RegisterBas

if (registerBaseBegin < 0 || registerBaseBegin + registerBaseRangeInt > addressBlockRange)
{
targetIsRegister
? registerValidator_->setChildItemValidity(targetRegisterBase, false)
: registerFileValidator_->setChildItemValidity(targetRegisterBase, false);
errorFound = true;
}

Expand Down
6 changes: 4 additions & 2 deletions IPXACTmodels/Component/validators/FieldValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ FieldValidator::FieldValidator(QSharedPointer<ExpressionParser> expressionParser
QSharedPointer<EnumeratedValueValidator> enumeratedValueValidator,
QSharedPointer<ParameterValidator> parameterValidator,
Document::Revision docRevision):
HierarchicalValidator(),
expressionParser_(expressionParser),
enumeratedValueValidator_(enumeratedValueValidator),
parameterValidator_(parameterValidator),
Expand Down Expand Up @@ -73,7 +74,7 @@ bool FieldValidator::validate(QSharedPointer<Field> field) const
{
if (docRevision_ == Document::Revision::Std14)
{
return hasValidName(field) && hasValidIsPresent(field) &&
return validComparedToSiblings(field) && hasValidName(field) && hasValidIsPresent(field) &&
hasValidBitOffset(field) && hasValidResets(field) &&
hasValidWriteValueConstraint(field) && hasValidReserved(field) && hasValidBitWidth(field) &&
hasValidEnumeratedValues(field) && hasValidParameters(field) && hasValidAccess(field);
Expand All @@ -97,7 +98,8 @@ bool FieldValidator::validate(QSharedPointer<Field> field) const
return false;
}

return hasValidName(field) && hasValidMemoryArray(field) && hasValidBitOffset(field) && hasValidResets(field) &&
return validComparedToSiblings(field) && hasValidName(field) && hasValidMemoryArray(field) &&
hasValidBitOffset(field) && hasValidResets(field) &&
hasValidWriteValueConstraint(field) && hasValidReserved(field) && hasValidBitWidth(field) &&
hasValidEnumeratedValues(field) && hasValidParameters(field) && hasValidAccess(field) &&
hasValidStructure(field);
Expand Down
4 changes: 3 additions & 1 deletion IPXACTmodels/Component/validators/FieldValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <IPXACTmodels/common/Document.h>

#include <IPXACTmodels/common/validators/HierarchicalValidator.h>

#include <QSharedPointer>
#include <QString>

Expand All @@ -33,7 +35,7 @@ class Mode;
//-----------------------------------------------------------------------------
//! Validator for ipxact:Field.
//-----------------------------------------------------------------------------
class IPXACTMODELS_EXPORT FieldValidator
class IPXACTMODELS_EXPORT FieldValidator : public HierarchicalValidator
{
public:

Expand Down
17 changes: 9 additions & 8 deletions IPXACTmodels/Component/validators/MemoryMapBaseValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ bool MemoryMapBaseValidator::hasValidMemoryBlocks(QSharedPointer<MemoryMapBase>
// Address block and subspace map names should be unique, subspace can't have the same name as an address block.
QMultiHash<QString, QSharedPointer<NameGroup> > foundMemoryBlockNames;

auto childBlocks = memoryMapBase->getMemoryBlocks();
auto childBlocksCopy = QSharedPointer<QList<QSharedPointer<MemoryBlockBase> > >(new QList(*memoryMapBase->getMemoryBlocks()));

// Sort blocks by base address to make checking for overlaps easier.
auto sortByBaseAddr = [this](QSharedPointer<MemoryBlockBase> memoryBlockA, QSharedPointer<MemoryBlockBase> memoryBlockB)
Expand All @@ -183,15 +183,15 @@ bool MemoryMapBaseValidator::hasValidMemoryBlocks(QSharedPointer<MemoryMapBase>
expressionParser_->parseExpression(memoryBlockB->getBaseAddress()).toLongLong();
};

std::sort(childBlocks->begin(), childBlocks->end(), sortByBaseAddr);
std::sort(childBlocksCopy->begin(), childBlocksCopy->end(), sortByBaseAddr);

quint64 lastEnd = 0;
bool lastBlockWasAddressBlock = false;

// Validate blocks together
for (int blockIndex = 0; blockIndex < childBlocks->size(); ++blockIndex)
for (int blockIndex = 0; blockIndex < childBlocksCopy->size(); ++blockIndex)
{
auto child = childBlocks->at(blockIndex).staticCast<MemoryBlockBase>();
auto child = childBlocksCopy->at(blockIndex).staticCast<MemoryBlockBase>();
bool currentIsAddressBlock = false;

// First check names, but don't set invalidity yet.
Expand Down Expand Up @@ -234,8 +234,8 @@ bool MemoryMapBaseValidator::hasValidMemoryBlocks(QSharedPointer<MemoryMapBase>
if (blockBegin <= lastEnd)
{
lastBlockWasAddressBlock
? addressBlockValidator_->setChildItemValidity(childBlocks->at(blockIndex - 1), false)
: subspaceValidator_->setChildItemValidity(childBlocks->at(blockIndex - 1), false);
? addressBlockValidator_->setChildItemValidity(childBlocksCopy->at(blockIndex - 1), false)
: subspaceValidator_->setChildItemValidity(childBlocksCopy->at(blockIndex - 1), false);

currentIsAddressBlock
? addressBlockValidator_->setChildItemValidity(child, false)
Expand Down Expand Up @@ -265,10 +265,11 @@ bool MemoryMapBaseValidator::hasValidMemoryBlocks(QSharedPointer<MemoryMapBase>
}

// Validate blocks separately
for (auto const& child : *childBlocks)
for (auto const& child : *childBlocksCopy)
{
if (QSharedPointer<AddressBlock> addressBlock = child.dynamicCast<AddressBlock>();
addressBlock && !addressBlockValidator_->validate(addressBlock, addressUnitBits))
addressBlock && (!addressBlockValidator_->validate(addressBlock, addressUnitBits)
|| !addressBlockWidthIsMultipleOfAUB(addressUnitBits, addressBlock)))
{
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions IPXACTmodels/Component/validators/RegisterBaseValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class IPXACTMODELS_EXPORT RegisterBaseValidator : public HierarchicalValidator
RegisterBaseValidator(RegisterBaseValidator const& rhs) = delete;
RegisterBaseValidator& operator=(RegisterBaseValidator const& rhs) = delete;

QSharedPointer<FieldValidator> getFieldValidator() const;

/*!
* Validates the given register.
*
Expand Down
Loading

0 comments on commit 671d243

Please sign in to comment.