From f0ad502e4651243d6a96194b3393bd460c0f7fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 19 Nov 2017 21:23:04 +0100 Subject: Another huge pile of work for about two months Well I should commit every change instead of this madness. I am not documenting changes as all this is just improvements and implementation progression. --- qtmips_gui/newdialog.cpp | 153 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 2 deletions(-) (limited to 'qtmips_gui/newdialog.cpp') diff --git a/qtmips_gui/newdialog.cpp b/qtmips_gui/newdialog.cpp index b2d24a8..31f4bb8 100644 --- a/qtmips_gui/newdialog.cpp +++ b/qtmips_gui/newdialog.cpp @@ -1,6 +1,155 @@ #include "newdialog.h" +#include "mainwindow.h" -newdialog::newdialog() -{ +NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) { + ui = new Ui::NewDialog(); + ui->setupUi(this); + setWindowTitle("New machine"); + this->settings = settings; + + QObject::connect(ui->pushButton_load, SIGNAL(clicked(bool)), this, SLOT(create())); + QObject::connect(ui->pushButton_cancel, SIGNAL(clicked(bool)), this, SLOT(cancel())); + // Signals on Base tab + QObject::connect(ui->preset_no_pipeline, SIGNAL(toggled(bool)), this, SLOT(preset(bool))); + QObject::connect(ui->preset_pipelined, SIGNAL(toggled(bool)), this, SLOT(preset(bool))); + QObject::connect(ui->pushButton_browse, SIGNAL(clicked(bool)), this, SLOT(browse_elf())); +#define CUSTOM_PRESET(UI) QObject::connect(UI, SIGNAL(clicked(bool)), this, SLOT(set_custom_preset())) + // Signals on Core tab + CUSTOM_PRESET(ui->pipelined); + CUSTOM_PRESET(ui->hazard); + CUSTOM_PRESET(ui->flush_jump); + CUSTOM_PRESET(ui->prediction); + CUSTOM_PRESET(ui->prediction_static); + CUSTOM_PRESET(ui->prediction_one_dynamic); + // Signals on Memory tab + CUSTOM_PRESET(ui->mem_protec_write); + CUSTOM_PRESET(ui->mem_protec_exec); + CUSTOM_PRESET(ui->cache); + CUSTOM_PRESET(ui->cache_associative); +#undef CUSTOM_PRESET + + // Load setting after signals are configured so that we can have correct settings + load_settings(); +} + +NewDialog::~NewDialog() { + delete ui; + // Settings is freed by parent + delete elf_dialog; +} + +void NewDialog::cancel() { + this->close(); +} + +void NewDialog::create() { + MainWindow *prnt = (MainWindow*)parent(); + + MachineConfig *mc = new MachineConfig(); + mc->set_elf(ui->elf_file->text()); + mc->set_pipelined(ui->pipelined->isChecked()); + // TODO other settings + + try { + prnt->create_core(mc); + } catch (const QtMipsExceptionInput &e) { + 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.setDetailedText(e.msg(true)); + msg.setWindowTitle("Error while initializing new machine"); + msg.exec(); + goto cleanup; + } + + store_settings(); // Save to settings + this->close(); + +cleanup: + delete mc; +} + +void NewDialog::browse_elf() { + QFileDialog elf_dialog(this); + elf_dialog.setFileMode(QFileDialog::ExistingFile); + if (elf_dialog.exec()) + ui->elf_file->setText(elf_dialog.selectedFiles()[0]); +} + +void NewDialog::preset(bool value) { + if (value) { + bool pip = ui->preset_pipelined->isChecked(); + // Core settings + ui->pipelined->setChecked(pip); + ui->hazard->setChecked(pip); + ui->flush_jump->setChecked(pip); + ui->prediction->setChecked(pip); + ui->prediction_one_dynamic->setChecked(pip); + // Memory settings + ui->mem_protec_write->setChecked(true); + ui->mem_protec_exec->setChecked(true); + ui->cache->setChecked(pip); + ui->cache_associative->setChecked(true); + } // Else custom so do no changes +} + +void NewDialog::set_custom_preset() { + ui->preset_custom->setChecked(true); +} + +void NewDialog::closeEvent(QCloseEvent *) { + load_settings(); // Reset from settings + // Close main window if not already configured + MainWindow *prnt = (MainWindow*)parent(); + if (!prnt->configured()) + prnt->close(); +} + +#define LOAD_BUTTON(NAME, DEF) ui->NAME->setChecked(settings->value(#NAME, DEF).toBool()) +#define LOAD_LINE(NAME, DEF) ui->NAME->setText(settings->value(#NAME, DEF).toString()) + +#define STORE_BUTTON(NAME) settings->setValue(#NAME, ui->NAME->isChecked()) +#define STORE_LINE(NAME) settings->setValue(#NAME, ui->NAME->text()) + +void NewDialog::load_settings() { + // Core tab + LOAD_BUTTON(pipelined, false); + LOAD_BUTTON(hazard, false); + LOAD_BUTTON(flush_jump, false); + LOAD_BUTTON(prediction, false); + LOAD_BUTTON(prediction_static, true); + LOAD_BUTTON(prediction_one_dynamic, false); + // Memory tab + LOAD_BUTTON(mem_protec_write, true); + LOAD_BUTTON(mem_protec_exec, true); + LOAD_BUTTON(cache, false); + LOAD_BUTTON(cache_associative, true); + // Base tab + // We are doing this last so presets can reset previous configuration to somethin valid + LOAD_BUTTON(preset_no_pipeline, true); + LOAD_BUTTON(preset_pipelined, false); + LOAD_BUTTON(preset_custom, false); + LOAD_LINE(elf_file, ""); +} + +void NewDialog::store_settings() { + // Core tab + STORE_BUTTON(pipelined); + STORE_BUTTON(hazard); + STORE_BUTTON(flush_jump); + STORE_BUTTON(prediction); + STORE_BUTTON(prediction_static); + STORE_BUTTON(prediction_one_dynamic); + // Memory tab + STORE_BUTTON(mem_protec_write); + STORE_BUTTON(mem_protec_exec); + STORE_BUTTON(cache); + STORE_BUTTON(cache_associative); + // Base tab + STORE_BUTTON(preset_no_pipeline); + STORE_BUTTON(preset_pipelined); + STORE_BUTTON(preset_custom); + STORE_LINE(elf_file); } -- cgit v1.2.3