diff options
-rw-r--r-- | qtmips_gui/mainwindow.cpp | 24 | ||||
-rw-r--r-- | qtmips_gui/mainwindow.h | 3 | ||||
-rw-r--r-- | qtmips_gui/newdialog.cpp | 13 |
3 files changed, 28 insertions, 12 deletions
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index 65e6469..a476290 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -36,6 +36,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // Connect signals from menu connect(ui->actionExit, SIGNAL(triggered(bool)), this, SLOT(close())); connect(ui->actionNew, SIGNAL(triggered(bool)), this, SLOT(new_machine())); + connect(ui->actionReload, SIGNAL(triggered(bool)), this, SLOT(machine_reload())); connect(ui->actionRegisters, SIGNAL(triggered(bool)), this, SLOT(show_registers())); connect(ui->actionProgram_memory, SIGNAL(triggered(bool)), this, SLOT(show_program())); connect(ui->actionMemory, SIGNAL(triggered(bool)), this, SLOT(show_memory())); @@ -74,12 +75,15 @@ void MainWindow::start() { ndialog->show(); } -void MainWindow::create_core(machine::MachineConfig *config) { +void MainWindow::create_core(const machine::MachineConfig &config) { + // Create machine + machine::QtMipsMachine *new_machine = new machine::QtMipsMachine(&config); + // Remove old machine if (machine != nullptr) delete machine; - // Create machine - machine = new machine::QtMipsMachine(config); + machine = new_machine; + // Create machine view if (corescene != nullptr) delete corescene; @@ -112,6 +116,20 @@ void MainWindow::new_machine() { ndialog->show(); } +void MainWindow::machine_reload() { + machine::MachineConfig cnf(&machine->config()); // We have to make local copy as create_core will delete current machine + try { + create_core(cnf); + } catch (const machine::QtMipsExceptionInput &e) { + QMessageBox msg(this); + msg.setText(e.msg(false)); + msg.setIcon(QMessageBox::Critical); + msg.setDetailedText(e.msg(true)); + msg.setWindowTitle("Error while initializing new machine"); + msg.exec(); + } +} + #define SHOW_HANDLER(NAME) void MainWindow::show_##NAME() { \ show_dockwidget(NAME); \ } \ diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h index 9431515..1389f21 100644 --- a/qtmips_gui/mainwindow.h +++ b/qtmips_gui/mainwindow.h @@ -23,13 +23,14 @@ public: ~MainWindow(); void start(); - void create_core(machine::MachineConfig *config); + void create_core(const machine::MachineConfig &config); bool configured(); public slots: // Actions signals void new_machine(); + void machine_reload(); void show_registers(); void show_program(); void show_memory(); diff --git a/qtmips_gui/newdialog.cpp b/qtmips_gui/newdialog.cpp index 062eb2d..cc23e2f 100644 --- a/qtmips_gui/newdialog.cpp +++ b/qtmips_gui/newdialog.cpp @@ -41,9 +41,9 @@ void NewDialog::cancel() { void NewDialog::create() { MainWindow *prnt = (MainWindow*)parent(); - machine::MachineConfig *mc = new machine::MachineConfig(); - mc->set_elf(ui->elf_file->text()); - mc->set_pipelined(ui->pipelined->isChecked()); + machine::MachineConfig mc; + mc.set_elf(ui->elf_file->text()); + mc.set_pipelined(ui->pipelined->isChecked()); // TODO other settings try { @@ -52,18 +52,15 @@ void NewDialog::create() { QMessageBox msg(this); msg.setText(e.msg(false)); msg.setIcon(QMessageBox::Critical); - msg.setToolTip("Please check that ELF executable realy exists and is in correct format."); + msg.setToolTip("Please check that ELF executable really exists and is in correct format."); msg.setDetailedText(e.msg(true)); msg.setWindowTitle("Error while initializing new machine"); msg.exec(); - goto cleanup; + return; } store_settings(); // Save to settings this->close(); - -cleanup: - delete mc; } void NewDialog::browse_elf() { |