Correctly parse spaces in input strings when inserting into data segment
MODIFY
Ripes.pro
Ripes.pro
@@ -85,7 +85,8 @@ HEADERS += \
src/pipelinetable.h \
src/pipelinetablemodel.h \
src/rwjumpwidget.h \
- src/rwjumpmodel.h
+ src/rwjumpmodel.h \
+ src/lexerutilities.h
FORMS += \
src/mainwindow.ui \

MODIFY
src/assembler.cpp
src/assembler.cpp
#include "assembler.h"
#include "binutils.h"
#include "defines.h"
+#include "lexerutilities.h"
#include <QRegularExpression>
#include <QTextBlock>
@@ -581,7 +582,11 @@ void Assembler::unpackPseudoOp(const QStringList& fields, int& pos) {
void Assembler::assembleAssemblerDirective(const QStringList& fields) {
QByteArray byteArray;
if (fields[0] == QString(".string")) {
- QString string = fields[1];
+ QString string;
+ // Merge input fields
+ for (int i = 1; i < fields.length(); i++) {
+ string += fields[i];
+ }
string.remove('\"');
byteArray = string.toUtf8();
} else if (fields[0] == QString(".word")) {
@@ -591,6 +596,9 @@ void Assembler::assembleAssemblerDirective(const QStringList& fields) {
byteArray.append(val & 0xff);
val >>= 8;
}
+ } else if (fields[0] == QString(".data")) {
+ // Do nothing
+ return;
}
// Since we want aligned memory accesses, we pad the byte array to word-sized indexes (4-byte chunks)
@@ -685,7 +693,7 @@ inline QStringList splitColon(const QString& string) {
const QByteArray& Assembler::assembleBinaryFile(const QTextDocument& doc) {
// Called by codeEditor when syntax has been accepted, and the document should be assembled into binary
// Because of the previously accepted syntax, !no! error handling will be done, to ensure a fast execution
- const static auto splitter = QRegularExpression("(\\ |\\,|\\t|\\(|\\))");
+ const static auto splitter = QRegularExpression("(\\,|\\t|\\(|\\))");
int line = 0;
restart();
@@ -697,6 +705,7 @@ const QByteArray& Assembler::assembleBinaryFile(const QTextDocument& doc) {
// Split input into fields
fields = block.text().split(splitter);
fields.removeAll("");
+ fields = splitQuotes(fields);
if (!fields.isEmpty()) {
// Split label fields, and keep separator ':'
if (fields[0].contains(':')) {

MODIFY
src/syntaxhighlighter.cpp
src/syntaxhighlighter.cpp
#include <QTextDocument>
#include "defines.h"
+#include "lexerutilities.h"
FieldType::FieldType(Type type, int lowerBound, int upperBound, SyntaxHighlighter* highlighter) {
m_type = type;
@@ -549,28 +550,6 @@ namespace {
return QString("Unknown operation");
}
-QStringList splitQuotes(const QStringList& list) {
- // Manual string splitter - splits at "\ " (space) characters, unless test is delimitered by "\""
- QStringList ret;
- for (const auto& s : list) {
- QString outString;
- bool inQuote = false;
- for (int i = 0; i < s.length(); i++) {
- inQuote ^= s[i] == '"';
- if (s[i] == ' ' && !inQuote) {
- ret.append(outString);
- outString.clear();
- } else {
- outString.append(s[i]);
- if (i == s.length() - 1)
- ret.append(outString);
- }
- }
- }
- ret.removeAll("");
- return ret;
-}
-
QString SyntaxHighlighter::checkSyntax(const QString& input) {
const static auto splitter = QRegularExpression("(\\,|\\t|\\(|\\))");
QStringList fields = input.split(splitter);

Correctly parse spaces in input strings when inserting into data segment