aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qtmips_gui/qtmips_gui.pro6
-rw-r--r--qtmips_gui/srceditor.cpp4
-rw-r--r--qtmips_gui/srceditor.h2
-rw-r--r--qtmips_machine/instruction.cpp14
-rw-r--r--qtmips_machine/instruction.h3
5 files changed, 26 insertions, 3 deletions
diff --git a/qtmips_gui/qtmips_gui.pro b/qtmips_gui/qtmips_gui.pro
index 1075f96..ae4f525 100644
--- a/qtmips_gui/qtmips_gui.pro
+++ b/qtmips_gui/qtmips_gui.pro
@@ -74,7 +74,8 @@ SOURCES += \
hinttabledelegate.cpp \
coreview/minimux.cpp \
srceditor.cpp \
- fixmatheval.cpp
+ fixmatheval.cpp \
+ highlighter.cpp
HEADERS += \
mainwindow.h \
@@ -119,7 +120,8 @@ HEADERS += \
hinttabledelegate.h \
coreview/minimux.h \
srceditor.h \
- fixmatheval.h
+ fixmatheval.h \
+ highlighter.h
wasm: SOURCES += \
qhtml5file_html5.cpp
diff --git a/qtmips_gui/srceditor.cpp b/qtmips_gui/srceditor.cpp
index e8bdb85..bb6da16 100644
--- a/qtmips_gui/srceditor.cpp
+++ b/qtmips_gui/srceditor.cpp
@@ -40,6 +40,7 @@
#include <QTextBlock>
#include "srceditor.h"
+#include "highlighter.h"
void SrcEditor::setup_common() {
QFont font;
@@ -48,6 +49,7 @@ void SrcEditor::setup_common() {
font.setPointSize(10);
setFont(font);
tname = "Unknown";
+ highlighter = new Highlighter(document());
}
SrcEditor::SrcEditor(QWidget *parent) : Super(parent) {
@@ -59,7 +61,7 @@ SrcEditor::SrcEditor(const QString &text, QWidget *parent) : Super(text, parent)
}
SrcEditor::~SrcEditor() {
-
+ delete highlighter;
}
QString SrcEditor::filename() {
diff --git a/qtmips_gui/srceditor.h b/qtmips_gui/srceditor.h
index 9d25be7..1c2e677 100644
--- a/qtmips_gui/srceditor.h
+++ b/qtmips_gui/srceditor.h
@@ -39,6 +39,7 @@
#include <QTextEdit>
#include <QString>
#include "qtmipsmachine.h"
+#include "highlighter.h"
class SrcEditor : public QTextEdit {
Q_OBJECT
@@ -54,6 +55,7 @@ public:
bool loadByteArray(const QByteArray &content, QString filename = "");
void setCursorToLine(int ln);
private:
+ Highlighter *highlighter;
void setup_common();
QString fname;
QString tname;
diff --git a/qtmips_machine/instruction.cpp b/qtmips_machine/instruction.cpp
index 502fa81..6792aa6 100644
--- a/qtmips_machine/instruction.cpp
+++ b/qtmips_machine/instruction.cpp
@@ -1073,6 +1073,9 @@ ssize_t Instruction::code_from_string(std::uint32_t *code, size_t buffsize,
std::uint32_t inst_addr, RelocExpressionList *reloc,
int line, bool pseudo_opt, int options)
{
+ if (str_to_instruction_code_map.isEmpty())
+ instruction_from_string_build_base();
+
int field = 0;
std::uint32_t inst_code = 0;
auto i = str_to_instruction_code_map.lowerBound(inst_base);
@@ -1321,3 +1324,14 @@ bool Instruction::update(std::int64_t val, RelocExpression *relocexp) {
dt |= (val << relocexp->lsb_bit) & mask;
return true;
}
+
+void Instruction::append_recognized_instructions(QStringList &list) {
+ if (str_to_instruction_code_map.isEmpty())
+ instruction_from_string_build_base();
+
+ foreach (const QString &str, str_to_instruction_code_map.keys())
+ list.append(str);
+ list.append("LA");
+ list.append("LI");
+ list.append("NOP");
+}
diff --git a/qtmips_machine/instruction.h b/qtmips_machine/instruction.h
index 76fca87..101d82f 100644
--- a/qtmips_machine/instruction.h
+++ b/qtmips_machine/instruction.h
@@ -38,6 +38,7 @@
#include <QObject>
#include <QString>
+#include <QStringList>
#include <QVector>
#include "machinedefs.h"
@@ -159,6 +160,8 @@ public:
int line = 0, bool pseudo_opt = false, int options = 0);
bool update(std::int64_t val, RelocExpression *relocexp);
+
+ static void append_recognized_instructions(QStringList &list);
private:
std::uint32_t dt;
};