Skip to content

Commit 03f22d8

Browse files
committed
Assembler: fix immediate parsing
1 parent 3b31be5 commit 03f22d8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/machine/instruction.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,18 +957,21 @@ static int parse_reg_from_string(const QString &str, uint *chars_taken = nullptr
957957
const QString allowed_special_chars = QStringLiteral("_+-/*|&^~");
958958

959959
/** Takes largest sequence of valid relocation expression chars and removes whitespaces */
960-
static QString read_reloc_expression(const QString &input) {
960+
static std::pair<QString, uint32_t> read_reloc_expression(const QString &input) {
961961
QString expression;
962+
uint32_t chars_taken = 0;
962963
for (QChar ch : input) {
963964
if (ch.isLetterOrNumber() || allowed_special_chars.contains(ch)) {
964965
expression.append(ch);
966+
chars_taken += 1;
965967
} else if (ch.isSpace()) {
968+
chars_taken += 1;
966969
continue;
967970
} else {
968971
break;
969972
}
970973
}
971-
return expression;
974+
return { expression, chars_taken };
972975
}
973976

974977
static void reloc_append(
@@ -981,14 +984,14 @@ static void reloc_append(
981984
const QString &filename = "",
982985
int line = 0,
983986
Instruction::Modifier pseudo_mod = machine::Instruction::Modifier::NONE) {
984-
QString expression = read_reloc_expression(fl);
987+
auto [expression, chars_taken_] = read_reloc_expression(fl);
985988
if (expression.size() > 0) {
986989
// Do not append empty relocation expressions
987990
reloc->append(new RelocExpression(
988991
inst_addr, expression, offset, adesc->min, adesc->max, &adesc->arg, filename, line,
989992
pseudo_mod));
990993
}
991-
if (chars_taken != nullptr) { *chars_taken = expression.size(); }
994+
if (chars_taken != nullptr) { *chars_taken = chars_taken_; }
992995
}
993996

994997
size_t Instruction::code_from_tokens(

0 commit comments

Comments
 (0)