Allow a list of arguments for .word assembler directive
MODIFY
src/assembler.cpp
src/assembler.cpp
@@ -600,11 +600,13 @@ void Assembler::assembleAssemblerDirective(const QStringList& fields) {
byteArray = string.toUtf8();
} else if (fields[0] == QString(".word")) {
bool ok;
- qlonglong val = getImmediate(fields[1], ok);
+ for(int i = 1; i < fields.size(); i++){
+ qlonglong val = getImmediate(fields[i], ok);
for (int i = 0; i < 4; i++) {
byteArray.append(val & 0xff);
val >>= 8;
}
+ }
} else if (fields[0] == QString(".data")) {
// Following instructions will be assembled into the data segment
m_inDataSegment = true;
@@ -714,7 +716,6 @@ 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|\\(|\\))");
int line = 0;
restart();

MODIFY
src/defines.h
src/defines.h
#include <vector>
#include "unordered_map"
+#include <QRegularExpression>
+
#define WORDSIZE 32
#define STACKSTART 0x7ffffff0
#define DATASTART 0x10000000
@@ -140,4 +142,6 @@ typedef struct {
uint32_t word = 0;
} Instruction;
+const static auto splitter = QRegularExpression("(\\,|\\t|\\(|\\))");
+
#endif // DEFINES_H

MODIFY
src/syntaxhighlighter.cpp
src/syntaxhighlighter.cpp
@@ -507,6 +507,7 @@ void SyntaxHighlighter::createSyntaxRules() {
// .byte
types.clear();
types << FieldType(Type::Immediate, -128, 255);
+ rule.hasListField = true; // a list of immediates can be provided
rule.instr = ".byte";
rule.fields = 2;
rule.inputs = types;
@@ -515,6 +516,7 @@ void SyntaxHighlighter::createSyntaxRules() {
// .2byte & half
types.clear();
types << FieldType(Type::Immediate, -32768, 65535);
+ rule.hasListField = true; // a list of immediates can be provided
rule.instr = ".2byte";
rule.fields = 2;
rule.inputs = types;
@@ -525,6 +527,7 @@ void SyntaxHighlighter::createSyntaxRules() {
// .4byte & word
types.clear();
types << FieldType(Type::Immediate, INT_MIN, INT_MAX);
+ rule.hasListField = true; // a list of immediates can be provided
rule.instr = ".4byte";
rule.fields = 2;
rule.inputs = types;
@@ -552,7 +555,6 @@ namespace {
}
QString SyntaxHighlighter::checkSyntax(const QString& input) {
- const static auto splitter = QRegularExpression("(\\,|\\t|\\(|\\))");
QStringList fields = input.split(splitter);
fields.removeAll("");
fields = splitQuotes(fields);
@@ -624,15 +626,22 @@ QString SyntaxHighlighter::checkSyntax(const QString& input) {
if (ruleIter != m_syntaxRules.end()) {
// A rule for the instruction has been found
for (const auto& rule : *ruleIter) {
- if (fields.size() == rule.fields || (rule.fields2 != -1 && fields.size() == rule.fields2)) {
+ if (fields.size() == rule.fields || (rule.fields2 != -1 && fields.size() == rule.fields2) ||
+ rule.hasListField) {
// fields size is correct, check each instruction
int nFields = fields.size();
QString currentRes = QString();
for (int index = 1; index < nFields; index++) {
// Get input rule - skipFirstField is a special case handler for jal pseudo-op when only 2
// fields are available
- auto inputRule = rule.skipFirstField && nFields == rule.fields2 ? rule.inputs[index]
- : rule.inputs[index - 1];
+ int ruleIndex = index;
+ if (rule.hasListField) {
+ // For list arguments, the last available syntax rule will be the rule for all inputs
+ ruleIndex = rule.inputs.size();
+ }
+
+ auto inputRule = rule.skipFirstField && nFields == rule.fields2 ? rule.inputs[ruleIndex]
+ : rule.inputs[ruleIndex - 1];
// If an offset is used, store line number, to re-update after all variable declarations have
// been mapped (after syntax checking the entire document)
if (inputRule.m_type == Type::Offset) {

MODIFY
src/syntaxhighlighter.h
src/syntaxhighlighter.h
@@ -52,6 +52,8 @@ private:
int fields; // n instruction fields, including the instruction
int fields2; // jal and jalr can be 2 different ops (pseudo- and base op)
bool skipFirstField = false; // jal needs to skip its first operand for its pseudo-op
+ bool hasListField = false; // .byte/.word etc. can accept a list of arguments. Last argument in the inputs
+ // fieldtype list can be a list
QList<FieldType> inputs; // list of each accepted input for the instruction, in order
};

Allow a list of arguments for .word assembler directive