diff options
Diffstat (limited to 'qtmips_gui')
-rw-r--r-- | qtmips_gui/MainWindow.ui | 15 | ||||
-rw-r--r-- | qtmips_gui/mainwindow.cpp | 57 | ||||
-rw-r--r-- | qtmips_gui/mainwindow.h | 2 | ||||
-rw-r--r-- | qtmips_gui/programmodel.cpp | 3 |
4 files changed, 76 insertions, 1 deletions
diff --git a/qtmips_gui/MainWindow.ui b/qtmips_gui/MainWindow.ui index 3202726..92fa695 100644 --- a/qtmips_gui/MainWindow.ui +++ b/qtmips_gui/MainWindow.ui @@ -101,6 +101,7 @@ <addaction name="separator"/> <addaction name="actionRestart"/> <addaction name="actionShow_Symbol"/> + <addaction name="actionCompileSource"/> </widget> <widget class="QMenu" name="menuHelp"> <property name="title"> @@ -239,6 +240,20 @@ <string>Ctrl+C</string> </property> </action> + <action name="actionCompileSource"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Compile Source</string> + </property> + <property name="toolTip"> + <string>Compile source and update memory</string> + </property> + <property name="shortcut"> + <string>Ctrl+C</string> + </property> + </action> <action name="actionExit"> <property name="icon"> <iconset resource="icons.qrc"> diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index 241a623..8a7956f 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -41,6 +41,8 @@ #include <QFile> #include <QFileInfo> #include <QMessageBox> +#include <QTextDocument> +#include <iostream> #include "mainwindow.h" #include "aboutdialog.h" @@ -107,6 +109,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { connect(ui->actionSave, SIGNAL(triggered(bool)), this, SLOT(save_source())); connect(ui->actionSaveAs, SIGNAL(triggered(bool)), this, SLOT(save_source_as())); connect(ui->actionClose, SIGNAL(triggered(bool)), this, SLOT(close_source())); + connect(ui->actionCompileSource, SIGNAL(triggered(bool)), this, SLOT(compile_source())); connect(ui->actionShow_Symbol, SIGNAL(triggered(bool)), this, SLOT(show_symbol_dialog())); connect(ui->actionRegisters, SIGNAL(triggered(bool)), this, SLOT(show_registers())); connect(ui->actionProgram_memory, SIGNAL(triggered(bool)), this, SLOT(show_program())); @@ -458,10 +461,12 @@ void MainWindow::setCurrentSrcEditor(SrcEditor *srceditor) { ui->actionSave->setEnabled(false); ui->actionSaveAs->setEnabled(false); ui->actionClose->setEnabled(false); + ui->actionCompileSource->setEnabled(false); } else { ui->actionSave->setEnabled(true); ui->actionSaveAs->setEnabled(true); ui->actionClose->setEnabled(true); + ui->actionCompileSource->setEnabled(true); } } @@ -540,3 +545,55 @@ void MainWindow::close_source() { central_window->removeTab(idx); delete editor; } + +void MainWindow::compile_source() { + if (current_srceditor == nullptr) + return; + if (machine == nullptr) { + QMessageBox::critical(this, "QtMips Error", tr("No machine to store program.")); + return; + } + machine::MemoryAccess *mem = machine->physical_address_space_rw(); + if (mem == nullptr) { + QMessageBox::critical(this, "QtMips Error", tr("No physical addresspace to store program.")); + return; + } + machine->cache_sync(); + SrcEditor *editor = current_srceditor; + QTextDocument *doc = editor->document(); + std::uint32_t address = 0x80020000; + machine::RelocExpressionList reloc; + + int ln = 1; + bool ok; + for ( QTextBlock block = doc->begin(); block.isValid(); block = block.next(), ln++) { + int pos; + QString label = ""; + QString line = block.text(); + pos = line.indexOf("#"); + if (pos >= 0) + line.truncate(pos); + pos = line.indexOf(";"); + if (pos >= 0) + line.truncate(pos); + line = line.simplified(); + pos = line.indexOf(":"); + if (pos >= 0) { + label = line.mid(0, pos); + line = line.mid(pos + 1).trimmed(); + machine->set_symbol(label, address, 4); + } + machine::Instruction inst; + inst = machine::Instruction::from_string(line, &ok, address, &reloc); + mem->write_word(address, inst.data()); + address += 4; + } + foreach(machine::RelocExpression *r, reloc) { + QString e = r->expression; + + + delete r; + } + + emit mem->external_change_notify(mem, 0, 0xffffffff, true); +} diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h index b051309..f75d31e 100644 --- a/qtmips_gui/mainwindow.h +++ b/qtmips_gui/mainwindow.h @@ -77,6 +77,7 @@ public slots: void save_source(); void save_source_as(); void close_source(); + void compile_source(); void show_registers(); void show_program(); void show_memory(); @@ -124,7 +125,6 @@ private: bool coreview_shown; SrcEditor *current_srceditor; - QActionGroup *speed_group; QSettings *settings; diff --git a/qtmips_gui/programmodel.cpp b/qtmips_gui/programmodel.cpp index 9098ab1..64dffb8 100644 --- a/qtmips_gui/programmodel.cpp +++ b/qtmips_gui/programmodel.cpp @@ -176,6 +176,9 @@ void ProgramModel::setup(machine::QtMipsMachine *machine) { stage_addr[i] = machine::STAGEADDR_NONE; if (machine != nullptr) connect(machine, SIGNAL(post_tick()), this, SLOT(check_for_updates())); + if (mem_access() != nullptr) + connect(mem_access(), SIGNAL(external_change_notify(const MemoryAccess*,std::uint32_t,std::uint32_t,bool)), + this, SLOT(check_for_updates())); emit update_all(); } |