Synchronize program loading through ProcessorHandler instead of EditTab
MODIFY
external/VSRTL
external/VSRTL
-Subproject commit 262dfb1146a4c99f4cb40205bd9be93463935022
+Subproject commit d8ae47915a357d4eadcfcaaa758c13d709ae4e33

MODIFY
src/edittab.cpp
src/edittab.cpp
@@ -73,6 +73,7 @@ EditTab::EditTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, parent)
[=] { m_buildAction->setEnabled(m_ui->setCInput->isChecked()); });
connect(ProcessorHandler::get(), &ProcessorHandler::procStateChangedNonRun, this,
&EditTab::updateProgramViewerHighlighting);
+ connect(ProcessorHandler::get(), &ProcessorHandler::programChanged, this, &EditTab::updateProgramViewer);
onProcessorChanged();
sourceTypeChanged();
@@ -154,8 +155,7 @@ void EditTab::loadFile(const LoadFileParams& fileParams) {
if (success) {
// Move the shared pointer to be the current active program
- m_activeProgram = loadedProgram;
- emitProgramChanged();
+ ProcessorHandler::loadProgram(loadedProgram);
} else {
QMessageBox::warning(this, "Error", "Error: Could not load file " + fileParams.filepath);
}
@@ -166,13 +166,6 @@ QString EditTab::getAssemblyText() {
return m_ui->codeEditor->toPlainText();
}
-const QByteArray* EditTab::getBinaryData() {
- if (m_activeProgram && (m_activeProgram.get()->sections.count(".text") != 0)) {
- return &m_activeProgram.get()->sections.at(".text").data;
- }
- return nullptr;
-}
-
void EditTab::clearAssemblyEditor() {
m_ui->codeEditor->clear();
}
@@ -220,11 +213,6 @@ void EditTab::onProcessorChanged() {
m_ui->codeEditor->setSourceType(m_currentSourceType, ProcessorHandler::getAssembler()->getOpcodes());
}
-void EditTab::emitProgramChanged() {
- emit programChanged(m_activeProgram);
- updateProgramViewer();
-}
-
void EditTab::sourceCodeChanged() {
switch (m_currentSourceType) {
case SourceType::Assembly:
@@ -242,8 +230,7 @@ void EditTab::assemble() {
&IOManager::get().assemblerSymbols());
*m_sourceErrors = res.errors;
if (m_sourceErrors->size() == 0) {
- m_activeProgram = std::make_shared<Program>(res.program);
- emitProgramChanged();
+ ProcessorHandler::loadProgram(std::make_shared<Program>(res.program));
} else {
// Errors occured; rehighlight will reflect current m_sourceErrors in the editor
}
@@ -285,8 +272,7 @@ void EditTab::setSourceText(const QString& text) {
void EditTab::enableAssemblyInput() {
// Clear currently loaded binary/ELF program
- m_activeProgram.reset();
- m_ui->programViewer->clear();
+ updateProgramViewer();
enableEditor();
}

MODIFY
src/edittab.h
src/edittab.h
@@ -48,7 +48,6 @@ signals:
public slots:
void onProcessorChanged();
void updateProgramViewerHighlighting();
- void emitProgramChanged();
/**
* @brief sourceTypeChanged
@@ -84,8 +83,6 @@ private:
QAction* m_symbolNavigatorAction = nullptr;
Ui::EditTab* m_ui = nullptr;
-
- std::shared_ptr<Program> m_activeProgram;
std::shared_ptr<Assembler::Errors> m_sourceErrors;
SourceType m_currentSourceType = SourceType::Assembly;

MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -96,7 +96,6 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
setupMenus();
// setup and connect widgets
- connect(editTab, &EditTab::programChanged, ProcessorHandler::get(), &ProcessorHandler::loadProgram);
connect(editTab, &EditTab::editorStateChanged, [=] { RipesSettings::setValue(RIPES_SETTING_HAS_SAVEFILE, false); });
connect(ProcessorHandler::get(), &ProcessorHandler::exit, processorTab, &ProcessorTab::processorFinished);
@@ -347,9 +346,10 @@ void MainWindow::saveFilesTriggered() {
if (!diag.binaryPath().isEmpty()) {
QFile file(diag.binaryPath());
- if (auto* program = static_cast<EditTab*>(m_tabWidgets.at(EditTabID).tab)->getBinaryData()) {
+ auto program = ProcessorHandler::getProgram();
+ if (program && (program.get()->sections.count(".text") != 0)) {
savedFiles << diag.binaryPath();
- writeBinaryFile(file, *program);
+ writeBinaryFile(file, program.get()->sections.at(".text").data);
didSave |= true;
}
}

MODIFY
src/processorhandler.cpp
src/processorhandler.cpp
@@ -56,7 +56,7 @@ ProcessorHandler::ProcessorHandler() {
m_syscallManager = std::make_unique<RISCVSyscallManager>();
}
-void ProcessorHandler::loadProgram(const std::shared_ptr<Program>& p) {
+void ProcessorHandler::_loadProgram(const std::shared_ptr<Program>& p) {
// Stop any currently executing simulation
stopRun();
@@ -90,6 +90,7 @@ void ProcessorHandler::loadProgram(const std::shared_ptr<Program>& p) {
}
RipesSettings::getObserver(RIPES_GLOBALSIGNAL_REQRESET)->trigger();
+ emit programChanged();
}
void ProcessorHandler::_writeMem(uint32_t address, uint32_t value, int size) {
@@ -244,6 +245,7 @@ void ProcessorHandler::_selectProcessor(const ProcessorID& id, const QStringList
loadProgram(m_program);
} else {
m_program = nullptr;
+ emit programChanged();
}
// Reconnect the wrappers for processor signal emission

Synchronize program loading through ProcessorHandler instead of EditTab