Skip to content

Commit

Permalink
[ADDITIVE] Add access column to address block and register table edit…
Browse files Browse the repository at this point in the history
…ors.
  • Loading branch information
hagantsa committed Nov 17, 2023
1 parent e3ea5d6 commit 8aeb84e
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 84 deletions.
24 changes: 12 additions & 12 deletions KactusAPI/include/AddressBlockInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,34 +166,34 @@ class KACTUS2_API AddressBlockInterface : public MemoryBlockInterface
* accessPolicyIndex parameter. The default value of -1 returns the address block's access value. 0 and above
* returns an indexed access policy's access value.
*
* @param [in] blockName Name of the selected address block.
* @param [in] accessPolicyIndex The access policy to get the access value of.
* @param [in] blockName Name of the selected address block.
* @param [in] getAccessPolicyAccess Flag indicating if access is fetched from access policy or directly
* from address block.
*
* @return Access string of the selected address block or its access policy.
*/
std::string getAccessString(std::string const& blockName, int accessPolicyIndex = -1) const;
std::string getAccessString(std::string const& blockName, bool getAccessPolicyAccess = false) const;

/*!
* Get the access of the selected address block or one of its access policies specified by the
* accessPolicyIndex parameter. The default value of -1 returns the address block's access value. 0 and above
* returns an indexed access policy's access value.
* Get the access of the selected address block. Used in std14 access editor.
*
* @param [in] blockName Name of the selected address block.
* @param [in] accessPolicyIndex The access policy to get the access value of.
*
* @return Access of the selected address block or its access policy.
* @return Access of the selected address block.
*/
AccessTypes::Access getAccess(std::string const& blockName, int accessPolicyIndex = -1) const;
AccessTypes::Access getAccess(std::string const& blockName) const;

/*!
* Set a new access for the selected address block.
*
* @param [in] blockName Name of the selected address block.
* @param [in] newAccess New access value.
* @param [in] blockName Name of the selected address block.
* @param [in] newAccess New access value.
* @param [in] getAccessPolicyAccess Flag indicating if access is set to access policy or directly to
* address block.
*
* @return True, if successful, false otherwise.
*/
bool setAccess(std::string const& blockName, std::string const& newAccess, int accessPolicyIndex = -1) const;
bool setAccess(std::string const& blockName, std::string const& newAccess, bool setAccessPolicyAccess = false) const;

/*!
* Get the volatile value of the selected address block.
Expand Down
37 changes: 28 additions & 9 deletions KactusAPI/include/RegisterInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ class KACTUS2_API RegisterInterface : public ParameterizableInterface, public Na
bool setVolatile(std::string const& registerName, std::string const& newVolatile);

/*!
* Get the access string of the selected register or access policy given by the access policy index.
* Use the default access policy index of -1 to fetch the access value stored directly in the register.
* Get the access string of the selected register or first access policy.
*
* @param [in] registerName Name of the selected register.
* @param [in] accessPolicyIndex The index of the selected access policy.
* @param [in] registerName Name of the selected register.
* @param [in] getAccessPolicyAccess Flag indicating if access is fetched from access policy or directly
* from register. Access is fetched from first access policy, if true.
*
* @return The access string of the selected register.
*/
std::string getAccessString(std::string const& registerName) const;
std::string getAccessString(std::string const& registerName, bool getAccessPolicyAccess = false) const;

/*!
* Get the access of the selected register or access policy given by the access policy index.
Expand All @@ -315,13 +315,32 @@ class KACTUS2_API RegisterInterface : public ParameterizableInterface, public Na
/*!
* Set the access value for the selected register or its access policy given by the access policy index.
*
* @param [in] registerName Name of the selected register.
* @param [in] newAccess The new access value.
* @param [in] accessPolicyIndex The index of the selected access policy.
* @param [in] registerName Name of the selected register.
* @param [in] newAccess The new access value.
* @param [in] getAccessPolicyAccess Flag indicating if access is set to access policy or directly
* to register. Access is set to first access policy, if true.
*
* @return True, if successful, false otherwise.
*/
bool setAccess(std::string const& registerName, std::string const& newAccess);
bool setAccess(std::string const& registerName, std::string const& newAccess, bool setAccessPolicyAccess = false);

/*!
* Get the number of access policies for a given register.
*
* @param [in] registerName The name of the register to get the number off access policies of.
*
* @return The number of access policies for the given register.
*/
int getAccessPolicyCount(std::string const& registerName) const;

/*!
* Adds a new access policy to the selected register.
*
* @param [in] registerName The selected register.
*
* @return True, if operation was successful, otherwise false.
*/
bool addAccessPolicy(std::string const& registerName);

/*!
* Calculate all the references to the selected ID in the selected item.
Expand Down
58 changes: 22 additions & 36 deletions KactusAPI/interfaces/component/AddressBlockInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,21 @@ bool AddressBlockInterface::setUsage(std::string const& blockName, std::string c
//-----------------------------------------------------------------------------
// Function: AddressBlockInterface::getAccessString()
//-----------------------------------------------------------------------------
std::string AddressBlockInterface::getAccessString(std::string const& blockName, int accessPolicyIndex /*= -1*/) const
std::string AddressBlockInterface::getAccessString(std::string const& blockName, bool getAccessPolicyAccess /*= false*/) const
{
if (auto selectedBlock = getAddressBlock(blockName))
{
if (accessPolicyIndex == -1)
if (!getAccessPolicyAccess)
{
return AccessTypes::access2Str(selectedBlock->getAccess()).toStdString();
}
else if (accessPolicyIndex >= 0)
else
{
if (auto accessPolicies = selectedBlock->getAccessPolicies();
accessPolicyIndex <= accessPolicies->size() - 1)
auto accessPolicies = selectedBlock->getAccessPolicies();

if (!accessPolicies->isEmpty())
{
return AccessTypes::access2Str(accessPolicies->at(accessPolicyIndex)->getAccess()).toStdString();
return AccessTypes::access2Str(accessPolicies->first()->getAccess()).toStdString();
}
}
}
Expand All @@ -238,22 +239,11 @@ std::string AddressBlockInterface::getAccessString(std::string const& blockName,
//-----------------------------------------------------------------------------
// Function: AddressBlockInterface::getAccess()
//-----------------------------------------------------------------------------
AccessTypes::Access AddressBlockInterface::getAccess(std::string const& blockName, int accessPolicyIndex /*= -1*/) const
AccessTypes::Access AddressBlockInterface::getAccess(std::string const& blockName) const
{
if (auto selectedBlock = getAddressBlock(blockName))
{
if (accessPolicyIndex == -1)
{
return selectedBlock->getAccess();
}
else if (accessPolicyIndex >= 0)
{
if (auto accessPolicies = selectedBlock->getAccessPolicies();
accessPolicyIndex <= accessPolicies->size() - 1)
{
return accessPolicies->at(accessPolicyIndex)->getAccess();
}
}
return selectedBlock->getAccess();
}

return AccessTypes::ACCESS_COUNT;
Expand All @@ -262,38 +252,34 @@ AccessTypes::Access AddressBlockInterface::getAccess(std::string const& blockNam
//-----------------------------------------------------------------------------
// Function: AddressBlockInterface::setAccess()
//-----------------------------------------------------------------------------
bool AddressBlockInterface::setAccess(std::string const& blockName, std::string const& newAccess, int accessPolicyIndex /*= -1*/) const
bool AddressBlockInterface::setAccess(std::string const& blockName, std::string const& newAccess, bool setAccessPolicyAccess /*= false*/) const
{
auto selectedBlock = getAddressBlock(blockName);
if (!selectedBlock)
{
return false;
}

if (accessPolicyIndex == -1)
if (!setAccessPolicyAccess)
{
selectedBlock->setAccess(AccessTypes::str2Access(QString::fromStdString(newAccess), AccessTypes::ACCESS_COUNT));
return true;
}
else if (accessPolicyIndex >= 0)
else
{
if (auto accessPolicies = selectedBlock->getAccessPolicies();
accessPolicyIndex <= accessPolicies->size() - 1)
{
auto accessPolicy = accessPolicies->at(accessPolicyIndex);

// Remove if empty.
if (newAccess.empty() && accessPolicy->getModeReferences()->isEmpty() &&
accessPolicy->getVendorExtensions()->isEmpty())
{
selectedBlock->getAccessPolicies()->removeAt(accessPolicyIndex);
return true;
}
auto accessPolicy = selectedBlock->getAccessPolicies()->first();

accessPolicy->setAccess(AccessTypes::str2Access(QString::fromStdString(newAccess),
AccessTypes::ACCESS_COUNT));
// Remove access policy, if new access is empty.
if (newAccess.empty() && accessPolicy->getModeReferences()->isEmpty() &&
accessPolicy->getVendorExtensions()->isEmpty())
{
selectedBlock->getAccessPolicies()->clear();
return true;
}

accessPolicy->setAccess(AccessTypes::str2Access(QString::fromStdString(newAccess),
AccessTypes::ACCESS_COUNT));
return true;
}

return false;
Expand Down
69 changes: 64 additions & 5 deletions KactusAPI/interfaces/component/RegisterInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,21 @@ bool RegisterInterface::setVolatile(std::string const& registerName, std::string
//-----------------------------------------------------------------------------
// Function: RegisterInterface::getAccessString()
//-----------------------------------------------------------------------------
std::string RegisterInterface::getAccessString(std::string const& registerName) const
std::string RegisterInterface::getAccessString(std::string const& registerName, bool getAccessPolicyAccess /*= false*/) const
{
if (auto selectedRegister = getRegister(registerName))
{
return AccessTypes::access2Str(selectedRegister->getAccess()).toStdString();
if (!getAccessPolicyAccess)
{
return AccessTypes::access2Str(selectedRegister->getAccess()).toStdString();
}
else
{
if (auto accessPolicies = selectedRegister->getAccessPolicies(); !accessPolicies->isEmpty())
{
return AccessTypes::access2Str(accessPolicies->first()->getAccess()).toStdString();
}
}
}

return string("");
Expand All @@ -460,15 +470,64 @@ AccessTypes::Access RegisterInterface::getAccess(std::string const& registerName
//-----------------------------------------------------------------------------
// Function: RegisterInterface::setAccess()
//-----------------------------------------------------------------------------
bool RegisterInterface::setAccess(std::string const& registerName, std::string const& newAccess)
bool RegisterInterface::setAccess(std::string const& registerName, std::string const& newAccess, bool setAccessPolicyAccess /*= false*/)
{
if (auto selectedRegister = getRegister(registerName))
auto selectedRegister = getRegister(registerName);
if (!selectedRegister)
{
auto newAccessType = AccessTypes::str2Access(QString::fromStdString(newAccess), AccessTypes::ACCESS_COUNT);
return false;
}

if (!setAccessPolicyAccess)
{
auto newAccessType = AccessTypes::str2Access(QString::fromStdString(newAccess), AccessTypes::ACCESS_COUNT);
selectedRegister->setAccess(newAccessType);
return true;
}
else
{
auto accessPolicy = selectedRegister->getAccessPolicies()->first();

// Remove access policy, if new access is empty.
if (newAccess.empty() && accessPolicy->getModeReferences()->isEmpty() &&
accessPolicy->getVendorExtensions()->isEmpty())
{
selectedRegister->getAccessPolicies()->removeFirst();
return true;
}

accessPolicy->setAccess(AccessTypes::str2Access(QString::fromStdString(newAccess),
AccessTypes::ACCESS_COUNT));
return true;
}

return false;
}

//-----------------------------------------------------------------------------
// Function: RegisterInterface::getAccessPolicyCount()
//-----------------------------------------------------------------------------
int RegisterInterface::getAccessPolicyCount(std::string const& registerName) const
{
if (auto selectedRegister = getRegister(registerName))
{
return selectedRegister->getAccessPolicies()->size();
}

return 0;
}

//-----------------------------------------------------------------------------
// Function: RegisterInterface::addAccessPolicy()
//-----------------------------------------------------------------------------
bool RegisterInterface::addAccessPolicy(std::string const& registerName)
{
if (auto selectedRegister = getRegister(registerName))
{
QSharedPointer<AccessPolicy> newAccessPolicy(new AccessPolicy());
selectedRegister->getAccessPolicies()->append(newAccessPolicy);
return true;
}

return false;
}
Expand Down
12 changes: 7 additions & 5 deletions editors/ComponentEditor/memoryMaps/AccessPoliciesEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ AccessPoliciesEditor::AccessPoliciesEditor(QSharedPointer<QList<QSharedPointer<A

auto model = new AccessPoliciesModel(accessPolicyInterface, this);
auto delegate = new AccessPoliciesDelegate(accessPolicyInterface->getModeReferenceInterface(), this);
auto proxy = new QSortFilterProxyModel(this);
proxy_ = new QSortFilterProxyModel(this);

proxy->setSourceModel(model);
view_->setModel(proxy);
proxy_->setSourceModel(model);
view_->setModel(proxy_);
view_->setItemDelegate(delegate);
view_->setSortingEnabled(true);
view_->setItemsDraggable(false);

connect(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
this, SIGNAL(contentChanged()), Qt::UniqueConnection);
connect(model, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()), Qt::UniqueConnection);
connect(model, SIGNAL(invalidateFilter()), proxy, SLOT(invalidate()), Qt::UniqueConnection);
connect(model, SIGNAL(invalidateFilter()), proxy_, SLOT(invalidate()), Qt::UniqueConnection);

connect(view_, SIGNAL(addItem(QModelIndex const&)),
model, SLOT(onAddRow(QModelIndex const&)), Qt::UniqueConnection);
Expand All @@ -64,6 +64,8 @@ AccessPoliciesEditor::AccessPoliciesEditor(QSharedPointer<QList<QSharedPointer<A
void AccessPoliciesEditor::refresh()
{
view_->update();

interface_->setAccessPolicies(accessPolicies_);

// Invalidate filter to force table refresh (access values can be changed in upper level editor).
proxy_->invalidate();
}
4 changes: 4 additions & 0 deletions editors/ComponentEditor/memoryMaps/AccessPoliciesEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class AccessPolicyInterface;
class AccessPolicy;
class EditableTableView;
class QSortFilterProxyModel;

//-----------------------------------------------------------------------------
//! Editor for access policies found in address blocks, registers, register files etc.
Expand Down Expand Up @@ -55,6 +56,9 @@ class AccessPoliciesEditor : public QGroupBox
//! The access policy table view.
EditableTableView* view_;

//! The sort filter proxy.
QSortFilterProxyModel* proxy_;

//! Interface for accessing access policies.
AccessPolicyInterface* interface_;
};
Expand Down
3 changes: 1 addition & 2 deletions editors/ComponentEditor/memoryMaps/addressblockeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ registers_(registers)

QSharedPointer<IPXactSystemVerilogParser> expressionParser(new IPXactSystemVerilogParser(parameterFinder));

model_ = new AddressBlockModel(registerInterface, expressionParser, parameterFinder, this);
model_ = new AddressBlockModel(registerInterface, expressionParser, parameterFinder, component->getRevision(), this);

ComponentParameterModel* componentParametersModel = new ComponentParameterModel(parameterFinder, this);
componentParametersModel->setExpressionParser(expressionParser);
Expand Down Expand Up @@ -80,7 +80,6 @@ registers_(registers)
{
view_->hideColumn(AddressBlockColumns::REGISTER_DIMENSION);
view_->hideColumn(AddressBlockColumns::VOLATILE);
view_->hideColumn(AddressBlockColumns::REGISTER_ACCESS);
view_->hideColumn(AddressBlockColumns::IS_PRESENT);
}

Expand Down
Loading

0 comments on commit 8aeb84e

Please sign in to comment.