aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qtmips_asm/simpleasm.cpp22
-rw-r--r--qtmips_asm/simpleasm.h4
-rw-r--r--qtmips_gui/mainwindow.cpp75
-rw-r--r--qtmips_gui/mainwindow.h3
4 files changed, 99 insertions, 5 deletions
diff --git a/qtmips_asm/simpleasm.cpp b/qtmips_asm/simpleasm.cpp
index 223b34d..8695624 100644
--- a/qtmips_asm/simpleasm.cpp
+++ b/qtmips_asm/simpleasm.cpp
@@ -114,6 +114,7 @@ bool SimpleAsm::process_line(QString line, QString filename,
bool maybe_label = true;
bool final = false;
bool separator;
+ bool space_separated = false;
int token_beg = -1;
int token_last = -1;
int operand_num = -1;
@@ -129,6 +130,11 @@ bool SimpleAsm::process_line(QString line, QString filename,
if (line.mid(pos).startsWith("#include")) {
if ((line.count() > pos + 8) && !line.at(pos + 8).isSpace())
final = true;
+ } else if (line.mid(pos).startsWith("#pragma")) {
+ if ((line.count() > pos + 7) && !line.at(pos + 7).isSpace())
+ final = true;
+ else
+ space_separated = true;
} else {
final = true;
}
@@ -140,7 +146,9 @@ bool SimpleAsm::process_line(QString line, QString filename,
if (line.at(pos + 1) == '/')
final = true;
}
- separator = final || (maybe_label && (ch == ':')) || ((operand_num >= 0) && (ch == ','));
+ separator = final || (maybe_label && (ch == ':')) ||
+ ((operand_num >= 0) && ((ch == ',') ||
+ (space_separated && ch.isSpace() && (token_beg != -1))));
if (maybe_label && (ch == ':')) {
maybe_label = false;
if (token_beg == -1) {
@@ -235,6 +243,9 @@ bool SimpleAsm::process_line(QString line, QString filename,
return true;
}
+ if (op == "#PRAGMA") {
+ return process_pragma(operands, filename, line_number, error_ptr);
+ }
if (op == "#INCLUDE") {
bool res = true;
QString incname;
@@ -633,3 +644,12 @@ bool SimpleAsm::finish(QString *error_ptr) {
return !error_occured;
}
+
+bool SimpleAsm::process_pragma(QStringList &operands, QString filename,
+ int line_number, QString *error_ptr) {
+ (void)operands;
+ (void)filename;
+ (void)line_number;
+ (void)error_ptr;
+ return true;
+}
diff --git a/qtmips_asm/simpleasm.h b/qtmips_asm/simpleasm.h
index ac06ca1..8f74577 100644
--- a/qtmips_asm/simpleasm.h
+++ b/qtmips_asm/simpleasm.h
@@ -74,11 +74,13 @@ public:
virtual bool process_file(QString filename, QString *error_ptr = nullptr);
bool finish(QString *error_ptr = nullptr);
protected:
+ virtual bool process_pragma(QStringList &operands, QString filename = "",
+ int line_number = 0, QString *error_ptr = nullptr);
bool error_occured;
bool fatal_occured;
+ SymbolTableDb *symtab;
private:
QStringList include_stack;
- SymbolTableDb *symtab;
machine::MemoryAccess *mem;
machine::RelocExpressionList reloc;
std::uint32_t address;
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp
index 09fe660..2b1a92b 100644
--- a/qtmips_gui/mainwindow.cpp
+++ b/qtmips_gui/mainwindow.cpp
@@ -42,6 +42,7 @@
#include <QFileInfo>
#include <QMessageBox>
#include <QTextDocument>
+#include <QMetaObject>
#include <iostream>
#include "mainwindow.h"
@@ -373,11 +374,12 @@ void MainWindow::print_action() {
#endif // QTMIPS_WITH_PRINTING
}
-#define SHOW_HANDLER(NAME, DEFAULT_AREA) void MainWindow::show_##NAME() { \
+#define SHOW_HANDLER(NAME, DEFAULT_AREA) \
+ void MainWindow::show_##NAME() { \
show_dockwidget(NAME, DEFAULT_AREA); \
} \
-SHOW_HANDLER(registers, Qt::RightDockWidgetArea)
+SHOW_HANDLER(registers, Qt::TopDockWidgetArea)
SHOW_HANDLER(program, Qt::LeftDockWidgetArea)
SHOW_HANDLER(memory, Qt::RightDockWidgetArea)
SHOW_HANDLER(cache_program, Qt::RightDockWidgetArea)
@@ -385,7 +387,7 @@ SHOW_HANDLER(cache_data, Qt::RightDockWidgetArea)
SHOW_HANDLER(peripherals, Qt::RightDockWidgetArea)
SHOW_HANDLER(terminal, Qt::RightDockWidgetArea)
SHOW_HANDLER(lcd_display, Qt::RightDockWidgetArea)
-SHOW_HANDLER(cop0dock, Qt::RightDockWidgetArea)
+SHOW_HANDLER(cop0dock, Qt::TopDockWidgetArea)
SHOW_HANDLER(messages, Qt::BottomDockWidgetArea)
#undef SHOW_HANDLER
@@ -871,6 +873,73 @@ bool SimpleAsmWithEditorCheck::process_file(QString filename, QString *error_ptr
return !error_occured;
}
+bool SimpleAsmWithEditorCheck::process_pragma(QStringList &operands, QString filename,
+ int line_number, QString *error_ptr) {
+ (void)error_ptr;
+#if 0
+ static const QMap<QString, QDockWidget *MainWindow::*> pragma_how_map = {
+ {QString("registers"), static_cast<QDockWidget *MainWindow::*>(&MainWindow::registers)},
+ };
+#endif
+ if ((operands.count() < 2) || QString::compare(operands.at(0), "qtmips", Qt::CaseInsensitive))
+ return true;
+ QString op = operands.at(1).toLower();
+ if (op == "show") {
+ if (operands.count() < 3)
+ return true;
+ QString show_method = "show_" + operands.at(2);
+ QString show_method_sig = show_method + "()";
+ if (mainwindow->metaObject()->indexOfMethod(show_method_sig.toLatin1().data()) == -1) {
+ emit report_message(messagetype::MSG_WARNING, filename, line_number, 0,
+ "#pragma qtmisp show - unknown object " + operands.at(2), "");
+ return true;
+ }
+ QMetaObject::invokeMethod(mainwindow, show_method.toLatin1().data());
+ return true;
+ }
+ if (op == "tab") {
+ if ((operands.count() < 3) || error_occured)
+ return true;
+ if (!QString::compare(operands.at(2), "core", Qt::CaseInsensitive) &&
+ (mainwindow->central_window != nullptr) && (mainwindow->coreview != nullptr)) {
+ mainwindow->central_window->setCurrentWidget(mainwindow->coreview);
+ }
+ return true;
+ }
+ if (op == "focus") {
+ bool ok;
+ if (operands.count() < 4)
+ return true;
+ fixmatheval::FmeExpression expression;
+ fixmatheval::FmeValue value;
+ QString error;
+ ok = expression.parse(operands.at(3), error);
+ if (!ok) {
+ emit report_message(messagetype::MSG_WARNING, filename, line_number, 0, "epression parse error " + error, "");
+ return true;
+ }
+ ok = expression.eval(value, symtab, error);
+ if (!ok) {
+ emit report_message(messagetype::MSG_WARNING, filename, line_number, 0, "epression evaluation error " + error, "");
+ return true;
+ }
+ if (!QString::compare(operands.at(2), "memory", Qt::CaseInsensitive) && (mainwindow->memory != nullptr)) {
+ QMetaObject::invokeMethod(mainwindow->memory, "focus_addr", Qt::AutoConnection, Q_ARG(std::uint32_t, value));
+ return true;
+ }
+ if (!QString::compare(operands.at(2), "program", Qt::CaseInsensitive) && (mainwindow->program != nullptr)) {
+ QMetaObject::invokeMethod(mainwindow->program, "focus_addr", Qt::AutoConnection, Q_ARG(std::uint32_t, value));
+ return true;
+ }
+ emit report_message(messagetype::MSG_WARNING, filename, line_number, 0,
+ "unknown #pragma qtmisp focus unknown object " + operands.at(2), "");
+ return true;
+ }
+ emit report_message(messagetype::MSG_WARNING, filename, line_number, 0,
+ "unknown #pragma qtmisp " + op, "");
+ return true;
+}
+
void MainWindow::compile_source() {
bool error_occured = false;
if (current_srceditor == nullptr)
diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h
index 976c21e..712faf4 100644
--- a/qtmips_gui/mainwindow.h
+++ b/qtmips_gui/mainwindow.h
@@ -175,6 +175,9 @@ public:
SimpleAsmWithEditorCheck(MainWindow *a_mainwindow, QObject *parent = nullptr) :
Super(parent), mainwindow(a_mainwindow) {}
bool process_file(QString filename, QString *error_ptr = nullptr) override;
+protected:
+ virtual bool process_pragma(QStringList &operands, QString filename = "",
+ int line_number = 0, QString *error_ptr = nullptr) override;
private:
MainWindow *mainwindow;
};