1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#include "newdialog.h"
#include "mainwindow.h"
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);
}
|