Use copy instead of reference for CacheSim to CacheGraphic transactions
MODIFY
src/cachesim/cachegraphic.cpp
src/cachesim/cachegraphic.cpp
@@ -447,11 +447,11 @@ void CacheGraphic::cacheInvalidated() {
}
}
-void CacheGraphic::updateAddressing(bool valid, const CacheSim::CacheTransaction* transaction) {
+void CacheGraphic::updateAddressing(bool valid, const CacheSim::CacheTransaction& transaction) {
if (m_indexingVisible) {
if (valid) {
- const CacheWay& way = m_cacheTextItems.at(transaction->index.line).at(transaction->index.way);
- m_addressTextItem->setText(QString::number(transaction->address, 2).rightJustified(32, '0'));
+ const CacheWay& way = m_cacheTextItems.at(transaction.index.line).at(transaction.index.way);
+ m_addressTextItem->setText(QString::number(transaction.address, 2).rightJustified(32, '0'));
if (way.tag) {
QPolygonF lineIndexingPoly;
@@ -459,8 +459,7 @@ void CacheGraphic::updateAddressing(bool valid, const CacheSim::CacheTransaction
lineIndexingPoly << m_lineIndexStartPoint;
lineIndexingPoly << m_lineIndexStartPoint + QPointF(0, (m_setHeight / 2));
lineIndexingPoly << QPointF(-m_tagWidth * 0.75, lineIndexingPoly.last().y());
- lineIndexingPoly << QPointF{lineIndexingPoly.last().x(),
- (transaction->index.line + 0.5) * m_lineHeight};
+ lineIndexingPoly << QPointF{lineIndexingPoly.last().x(), (transaction.index.line + 0.5) * m_lineHeight};
lineIndexingPoly << QPointF{-m_fm.width(QString::number(m_cache.getLines())) * 1.25,
lineIndexingPoly.last().y()};
m_lineIndexingLine->setPolygon(lineIndexingPoly);
@@ -468,7 +467,7 @@ void CacheGraphic::updateAddressing(bool valid, const CacheSim::CacheTransaction
QPolygonF blockIndexingPoly;
blockIndexingPoly << m_blockIndexStartPoint;
blockIndexingPoly << m_blockIndexStartPoint + QPointF(0, (m_setHeight / 2) * 1.5);
- blockIndexingPoly << QPointF(m_widthBeforeBlocks + m_blockWidth * (transaction->index.block + 0.5),
+ blockIndexingPoly << QPointF(m_widthBeforeBlocks + m_blockWidth * (transaction.index.block + 0.5),
blockIndexingPoly.last().y());
blockIndexingPoly << QPointF(blockIndexingPoly.last().x(),
-m_addressTextItem->boundingRect().size().height());
@@ -489,14 +488,14 @@ void CacheGraphic::wayInvalidated(unsigned lineIdx, unsigned wayIdx) {
updateLineReplFields(lineIdx);
}
-void CacheGraphic::dataChanged(const CacheSim::CacheTransaction* transaction) {
- if (transaction != nullptr) {
- wayInvalidated(transaction->index.line, transaction->index.way);
+void CacheGraphic::dataChanged(CacheSim::CacheTransaction transaction) {
+ if (transaction.type != MemoryAccess::None) {
+ wayInvalidated(transaction.index.line, transaction.index.way);
updateAddressing(true, transaction);
updateHighlighting(true, transaction);
} else {
- updateHighlighting(false, nullptr);
- updateAddressing(false);
+ updateHighlighting(false, transaction);
+ updateAddressing(false, transaction);
}
}
@@ -515,15 +514,15 @@ QGraphicsSimpleTextItem* CacheGraphic::drawText(const QString& text, qreal x, qr
return textItem;
}
-void CacheGraphic::updateHighlighting(bool active, const CacheSim::CacheTransaction* transaction) {
+void CacheGraphic::updateHighlighting(bool active, const CacheSim::CacheTransaction& transaction) {
m_highlightingItems.clear();
if (active) {
// Redraw highlighting rectangles indicating the current indexing
// Draw cache line highlighting rectangle
- QPointF topLeft = QPointF(0, transaction->index.line * m_lineHeight);
- QPointF bottomRight = QPointF(m_cacheWidth, (transaction->index.line + 1) * m_lineHeight);
+ QPointF topLeft = QPointF(0, transaction.index.line * m_lineHeight);
+ QPointF bottomRight = QPointF(m_cacheWidth, (transaction.index.line + 1) * m_lineHeight);
m_highlightingItems.emplace_back(std::make_unique<QGraphicsRectItem>(QRectF(topLeft, bottomRight), this));
auto* lineRectItem = m_highlightingItems.rbegin()->get();
lineRectItem->setZValue(-2);
@@ -531,8 +530,8 @@ void CacheGraphic::updateHighlighting(bool active, const CacheSim::CacheTransact
lineRectItem->setBrush(Qt::yellow);
// Draw cache block highlighting rectangle
- topLeft = QPointF(transaction->index.block * m_blockWidth + m_widthBeforeBlocks, 0);
- bottomRight = QPointF((transaction->index.block + 1) * m_blockWidth + m_widthBeforeBlocks, m_cacheHeight);
+ topLeft = QPointF(transaction.index.block * m_blockWidth + m_widthBeforeBlocks, 0);
+ bottomRight = QPointF((transaction.index.block + 1) * m_blockWidth + m_widthBeforeBlocks, m_cacheHeight);
m_highlightingItems.emplace_back(std::make_unique<QGraphicsRectItem>(QRectF(topLeft, bottomRight), this));
auto* blockRectItem = m_highlightingItems.rbegin()->get();
blockRectItem->setZValue(-2);
@@ -540,14 +539,14 @@ void CacheGraphic::updateHighlighting(bool active, const CacheSim::CacheTransact
blockRectItem->setBrush(Qt::yellow);
// Draw highlighting on the currently accessed block
- topLeft = QPointF(transaction->index.block * m_blockWidth + m_widthBeforeBlocks,
- transaction->index.line * m_lineHeight + transaction->index.way * m_setHeight);
- bottomRight = QPointF((transaction->index.block + 1) * m_blockWidth + m_widthBeforeBlocks,
- transaction->index.line * m_lineHeight + (transaction->index.way + 1) * m_setHeight);
+ topLeft = QPointF(transaction.index.block * m_blockWidth + m_widthBeforeBlocks,
+ transaction.index.line * m_lineHeight + transaction.index.way * m_setHeight);
+ bottomRight = QPointF((transaction.index.block + 1) * m_blockWidth + m_widthBeforeBlocks,
+ transaction.index.line * m_lineHeight + (transaction.index.way + 1) * m_setHeight);
m_highlightingItems.emplace_back(std::make_unique<QGraphicsRectItem>(QRectF(topLeft, bottomRight), this));
auto* hitRectItem = m_highlightingItems.rbegin()->get();
hitRectItem->setZValue(-1);
- if (transaction->isHit) {
+ if (transaction.isHit) {
hitRectItem->setOpacity(0.4);
hitRectItem->setBrush(Qt::green);
} else {

MODIFY
src/cachesim/cachegraphic.h
src/cachesim/cachegraphic.h
@@ -25,7 +25,7 @@ public slots:
* The cache simulator indicates that some entries in the cache has changed. CacheGraphic will, using @p
* transaction, lazily initialize and update all required values to reflect the new state of the cache.
*/
- void dataChanged(const CacheSim::CacheTransaction* transaction);
+ void dataChanged(CacheSim::CacheTransaction transaction);
/**
* @brief wayInvalidated
@@ -71,7 +71,7 @@ private:
* Constructs all of the "Valid" and "LRU" text items within the cache
*/
void initializeControlBits();
- void updateHighlighting(bool active, const CacheSim::CacheTransaction* transaction);
+ void updateHighlighting(bool active, const CacheSim::CacheTransaction& transaction);
QGraphicsSimpleTextItem* drawText(const QString& text, const QPointF& pos, const QFont* otherFont = nullptr);
QGraphicsSimpleTextItem* drawText(const QString& text, qreal x, qreal y, const QFont* otherFont = nullptr);
QGraphicsSimpleTextItem* tryCreateGraphicsTextItem(QGraphicsSimpleTextItem** item, qreal x, qreal y);
@@ -80,7 +80,7 @@ private:
// Graphical update functions
void updateLineReplFields(unsigned lineIdx);
void updateWay(unsigned lineIdx, unsigned wayIdx);
- void updateAddressing(bool valid, const CacheSim::CacheTransaction* transaction = nullptr);
+ void updateAddressing(bool valid, const CacheSim::CacheTransaction& transaction);
void drawIndexingItems();
QString addressString() const;

MODIFY
src/cachesim/cachesim.cpp
src/cachesim/cachesim.cpp
@@ -328,7 +328,7 @@ void CacheSim::access(AInt address, MemoryAccess::Type type) {
}
if (!ProcessorHandler::isRunning()) {
- emit dataChanged(&transaction);
+ emit dataChanged(transaction);
}
}
@@ -366,9 +366,9 @@ void CacheSim::undo() {
// Finally, re-emit the transaction which occurred in the previous cache access to update the cache
// highlighting state
if (m_traceStack.size() > 0) {
- emit dataChanged(&m_traceStack.begin()->transaction);
+ emit dataChanged(m_traceStack.begin()->transaction);
} else {
- emit dataChanged(nullptr);
+ emit dataChanged(CacheTransaction());
}
}

MODIFY
src/cachesim/cachesim.h
src/cachesim/cachesim.h
@@ -122,7 +122,7 @@ public:
bool isHit = false;
bool isWriteback = false; // True if the transaction resulted in an eviction of a dirty cacheline
- MemoryAccess::Type type;
+ MemoryAccess::Type type = MemoryAccess::None;
bool transToValid = false; // True if the cacheline just transitioned from invalid to valid
bool tagChanged = false; // True if transToValid or the previous entry was evicted
};
@@ -201,7 +201,7 @@ public slots:
signals:
void configurationChanged();
- void dataChanged(const CacheSim::CacheTransaction* transaction);
+ void dataChanged(CacheSim::CacheTransaction transaction);
void hitrateChanged();
// Signals that the entire cache line @p

Use copy instead of reference for CacheSim to CacheGraphic transactions