From b62686b24fbb65d0810475e24aba7a5c4ee3e05e Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Mon, 1 Jul 2019 18:37:54 +0200 Subject: Minimal prototype of integrated assembler. The labels are parsed and stored into symbol table but expressions dependent on symbols values are not evaluated. Signed-off-by: Pavel Pisa --- qtmips_gui/MainWindow.ui | 15 ++++++++++++ qtmips_gui/mainwindow.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++ qtmips_gui/mainwindow.h | 2 +- qtmips_gui/programmodel.cpp | 3 +++ 4 files changed, 76 insertions(+), 1 deletion(-) (limited to 'qtmips_gui') 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 @@ + @@ -239,6 +240,20 @@ Ctrl+C + + + false + + + Compile Source + + + Compile source and update memory + + + Ctrl+C + + 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 #include #include +#include +#include #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(); } -- cgit v1.2.3