aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qtmips_gui/mainwindow.cpp17
-rw-r--r--qtmips_gui/srceditor.cpp23
-rw-r--r--qtmips_gui/srceditor.h2
-rw-r--r--qtmips_machine/qtmipsmachine.cpp4
-rw-r--r--qtmips_machine/qtmipsmachine.h2
5 files changed, 43 insertions, 5 deletions
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp
index 58a0173..e3ad8dd 100644
--- a/qtmips_gui/mainwindow.cpp
+++ b/qtmips_gui/mainwindow.cpp
@@ -51,6 +51,11 @@
#include "gotosymboldialog.h"
#include "fixmatheval.h"
+#ifdef __EMSCRIPTEN__
+#include <QFileInfo>
+#include "qhtml5file.h"
+#endif
+
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
machine = nullptr;
corescene = nullptr;
@@ -491,6 +496,7 @@ void MainWindow::new_source() {
}
void MainWindow::open_source() {
+#ifndef __EMSCRIPTEN__
QString file_name = "";
file_name = QFileDialog::getOpenFileName(this, tr("Open File"), "", "Source Files (*.asm *.S *.s)");
@@ -506,6 +512,15 @@ void MainWindow::open_source() {
delete(editor);
}
}
+#else
+ QHtml5File::load("*", [&](const QByteArray &content, const QString &filename) {
+ SrcEditor *editor = new SrcEditor();
+ editor->loadByteArray(content, filename);
+ central_window->addTab(editor, editor->title());
+ central_window->setCurrentWidget(editor);
+ connect(editor, SIGNAL(destroyed(QObject*)), this, SLOT(tab_widget_destroyed(QObject*)));
+ });
+#endif
}
void MainWindow::save_source_as() {
@@ -584,7 +599,7 @@ static std::uint64_t string_to_uint64(QString str, int base,
}
void MainWindow::compile_source() {
- SymbolTableDb symtab(machine->symbol_table());
+ SymbolTableDb symtab(machine->symbol_table(true));
int error_line = 0;
if (current_srceditor == nullptr)
return;
diff --git a/qtmips_gui/srceditor.cpp b/qtmips_gui/srceditor.cpp
index 2f4d3a6..e8bdb85 100644
--- a/qtmips_gui/srceditor.cpp
+++ b/qtmips_gui/srceditor.cpp
@@ -41,12 +41,21 @@
#include "srceditor.h"
-SrcEditor::SrcEditor(QWidget *parent) : Super(parent) {
+void SrcEditor::setup_common() {
+ QFont font;
+ font.setFamily("Courier");
+ font.setFixedPitch(true);
+ font.setPointSize(10);
+ setFont(font);
tname = "Unknown";
}
+SrcEditor::SrcEditor(QWidget *parent) : Super(parent) {
+ setup_common();
+}
+
SrcEditor::SrcEditor(const QString &text, QWidget *parent) : Super(text, parent) {
- tname = "Unknown";
+ setup_common();
}
SrcEditor::~SrcEditor() {
@@ -74,6 +83,16 @@ bool SrcEditor::loadFile(QString filename) {
}
}
+bool SrcEditor::loadByteArray(const QByteArray &content, QString filename) {
+ setPlainText(QString::fromUtf8(content.data(), content.size()));
+ if (!filename.isEmpty()) {
+ QFileInfo fi(filename);
+ fname = filename;
+ tname = fi.fileName();
+ }
+ return true;
+}
+
bool SrcEditor::saveFile(QString filename) {
if (filename.isEmpty())
filename = this->filename();
diff --git a/qtmips_gui/srceditor.h b/qtmips_gui/srceditor.h
index a727f99..9d25be7 100644
--- a/qtmips_gui/srceditor.h
+++ b/qtmips_gui/srceditor.h
@@ -51,8 +51,10 @@ public:
QString title();
bool loadFile(QString filename);
bool saveFile(QString filename = "");
+ bool loadByteArray(const QByteArray &content, QString filename = "");
void setCursorToLine(int ln);
private:
+ void setup_common();
QString fname;
QString tname;
};
diff --git a/qtmips_machine/qtmipsmachine.cpp b/qtmips_machine/qtmipsmachine.cpp
index 68eeeca..e838429 100644
--- a/qtmips_machine/qtmipsmachine.cpp
+++ b/qtmips_machine/qtmipsmachine.cpp
@@ -214,7 +214,9 @@ LcdDisplay *QtMipsMachine::peripheral_lcd_display() {
return perip_lcd_display;
}
-const SymbolTable *QtMipsMachine::symbol_table() {
+const SymbolTable *QtMipsMachine::symbol_table(bool create) {
+ if (create && (symtab == nullptr))
+ symtab = new SymbolTable;
return symtab;
}
diff --git a/qtmips_machine/qtmipsmachine.h b/qtmips_machine/qtmipsmachine.h
index ef96e09..e5bbdb3 100644
--- a/qtmips_machine/qtmipsmachine.h
+++ b/qtmips_machine/qtmipsmachine.h
@@ -76,7 +76,7 @@ public:
SerialPort *serial_port();
PeripSpiLed *peripheral_spi_led();
LcdDisplay *peripheral_lcd_display();
- const SymbolTable *symbol_table();
+ const SymbolTable *symbol_table(bool create = false);
void set_symbol(QString name, std::uint32_t value, std::uint32_t size,
unsigned char info = 0, unsigned char other = 0);
const Core *core();