Make accessing current processor ptr through ProcessorHandler const-only
MODIFY
external/VSRTL
external/VSRTL
-Subproject commit f16a64733ccc823688b154507df1d85d88f2ed26
+Subproject commit bdf1fa68836222e5b660d2fb963f2a5c3a5e7286

MODIFY
src/memorymodel.cpp
src/memorymodel.cpp
@@ -97,7 +97,7 @@ QVariant MemoryModel::addrData(long long address) const {
}
QVariant MemoryModel::fgColorData(long long address, unsigned byteOffset) const {
- if (address < 0 || !m_handler.getProcessor()->getMemory().contains(address + byteOffset)) {
+ if (address < 0 || !m_handler.getMemory().contains(address + byteOffset)) {
return QBrush(Qt::lightGray);
} else {
return QVariant(); // default
@@ -107,12 +107,12 @@ QVariant MemoryModel::fgColorData(long long address, unsigned byteOffset) const
QVariant MemoryModel::byteData(long long address, unsigned byteOffset) const {
if (address < 0) {
return "-";
- } else if (!m_handler.getProcessor()->getMemory().contains(address + byteOffset)) {
+ } else if (!m_handler.getMemory().contains(address + byteOffset)) {
// Dont read the memory (this will create an entry in the memory if done so). Instead, create a "fake" entry in
// the memory model, containing X's.
return "X";
} else {
- uint32_t value = m_handler.getProcessor()->getMemory().readMem(address);
+ uint32_t value = m_handler.getMemory().readMemConst(address);
value = value >> (byteOffset * 8);
return encodeRadixValue(value & 0xFF, m_radix, 8);
}

MODIFY
src/processorhandler.cpp
src/processorhandler.cpp
@@ -39,6 +39,14 @@ void ProcessorHandler::loadProgram(const Program& p) {
emit reqProcessorReset();
}
+const vsrtl::SparseArray& ProcessorHandler::getMemory() const {
+ return m_currentProcessor->getMemory();
+}
+
+const vsrtl::SparseArray& ProcessorHandler::getRegisters() const {
+ return m_currentProcessor->getRegisters();
+}
+
void ProcessorHandler::setBreakpoint(const uint32_t address, bool enabled) {
if (enabled) {
m_breakpoints.insert(address);
@@ -47,6 +55,10 @@ void ProcessorHandler::setBreakpoint(const uint32_t address, bool enabled) {
}
}
+void ProcessorHandler::loadProcessorToWidget(vsrtl::VSRTLWidget* widget) {
+ widget->setDesign(m_currentProcessor.get());
+}
+
bool ProcessorHandler::hasBreakpoint(const uint32_t address) const {
return m_breakpoints.count(address);
}

MODIFY
src/processorhandler.h
src/processorhandler.h
#include "processorregistry.h"
#include "program.h"
+#include "vsrtl_widget.h"
+
/**
* @brief The ProcessorHandler class
* Manages construction and destruction of a VSRTL processor design, when selecting between processors.
*/
class ProcessorHandler : public QObject {
Q_OBJECT
+ friend class VSRTLWidget;
+
public:
ProcessorHandler();
- /// @todo: this should return a const ptr - ONLY the processorhandler is allowed to modify the state of the
- /// processor
- Ripes::RipesProcessor* getProcessor() { return m_currentProcessor.get(); }
+ const Ripes::RipesProcessor* getProcessor() { return m_currentProcessor.get(); }
const ProcessorSetup& getSetup() const { return m_currentSetup; }
+ /**
+ * @brief loadProcessorToWidget
+ * Loads the current processor to the @param VSRTLWidget. Required given that ProcessorHandler::getProcessor returns
+ * a const ptr.
+ */
+ void loadProcessorToWidget(vsrtl::VSRTLWidget* widget);
+
/**
* @brief selectProcessor
* Constructs the processor identified by @param id, and performs all necessary initialization through the
@@ -47,6 +56,13 @@ public:
*/
QString parseInstrAt(const uint32_t address) const;
+ /**
+ * @brief getMemory & getRegisters
+ * returns const-wrapped references to the current process memory elements
+ */
+ const vsrtl::SparseArray& getMemory() const;
+ const vsrtl::SparseArray& getRegisters() const;
+
/**
* @brief setRegisterValue
* Set the value of register @param idx to @param value.

MODIFY
src/processors/ripesprocessor.h
src/processors/ripesprocessor.h
@@ -72,7 +72,7 @@ public:
* @brief getRegister
* @return value currently present in register @p i
*/
- virtual unsigned int getRegister(unsigned i) = 0;
+ virtual unsigned int getRegister(unsigned i) const = 0;
/**
* @brief getRegisters

MODIFY
src/processors/ss/riscv_ss.h
src/processors/ss/riscv_ss.h
@@ -156,7 +156,7 @@ public:
propagateDesign();
}
SparseArray& getMemory() override { return *m_memory; }
- unsigned int getRegister(unsigned i) override { return registerFile->getRegister(i); }
+ unsigned int getRegister(unsigned i) const override { return registerFile->getRegister(i); }
SparseArray& getRegisters() override { return *m_regMem; }
void finalize() override {
// Allow one additional clock cycle to clear the current instruction

MODIFY
src/processortab.cpp
src/processortab.cpp
@@ -23,7 +23,7 @@ ProcessorTab::ProcessorTab(ProcessorHandler& handler, QToolBar* toolbar, QWidget
m_vsrtlWidget = m_ui->vsrtlWidget;
// Load the default processor
- m_vsrtlWidget->setDesign(m_handler.getProcessor());
+ m_handler.loadProcessorToWidget(m_vsrtlWidget);
updateInstructionModel();
m_ui->registerWidget->setHandler(&m_handler);
@@ -156,7 +156,7 @@ void ProcessorTab::processorSelection() {
// New processor model was selected
m_vsrtlWidget->clearDesign();
m_handler.selectProcessor(diag.selectedSetup);
- m_vsrtlWidget->setDesign(m_handler.getProcessor());
+ m_handler.loadProcessorToWidget(m_vsrtlWidget);
updateInstructionModel();
m_ui->registerWidget->updateModel();
update();

MODIFY
src/registermodel.cpp
src/registermodel.cpp
@@ -107,7 +107,7 @@ QVariant RegisterModel::data(const QModelIndex& index, int role) const {
return QVariant();
}
-void RegisterModel::setRadix(Radix r) {
+void RegisterModel::setRadix(::Radix r) {
m_radix = r;
processorWasClocked();
}

Make accessing current processor ptr through ProcessorHandler const-only