@@ -72,7 +72,7 @@ class AVRAsmParser : public MCTargetAsmParser {
7272 int parseRegisterName ();
7373 int parseRegister (bool RestoreOnFailure = false );
7474 bool tryParseRegisterOperand (OperandVector &Operands);
75- bool tryParseExpression (OperandVector &Operands);
75+ bool tryParseExpression (OperandVector &Operands, int64_t offset );
7676 bool tryParseRelocExpression (OperandVector &Operands);
7777 void eatComma ();
7878
@@ -418,7 +418,7 @@ bool AVRAsmParser::tryParseRegisterOperand(OperandVector &Operands) {
418418 return false ;
419419}
420420
421- bool AVRAsmParser::tryParseExpression (OperandVector &Operands) {
421+ bool AVRAsmParser::tryParseExpression (OperandVector &Operands, int64_t offset ) {
422422 SMLoc S = Parser.getTok ().getLoc ();
423423
424424 if (!tryParseRelocExpression (Operands))
@@ -437,6 +437,11 @@ bool AVRAsmParser::tryParseExpression(OperandVector &Operands) {
437437 if (getParser ().parseExpression (Expression))
438438 return true ;
439439
440+ if (offset) {
441+ Expression = MCBinaryExpr::createAdd (
442+ Expression, MCConstantExpr::create (offset, getContext ()), getContext ());
443+ }
444+
440445 SMLoc E = SMLoc::getFromPointer (Parser.getTok ().getLoc ().getPointer () - 1 );
441446 Operands.push_back (AVROperand::CreateImm (Expression, S, E));
442447 return false ;
@@ -529,8 +534,9 @@ bool AVRAsmParser::parseOperand(OperandVector &Operands, bool maybeReg) {
529534 [[fallthrough]];
530535 case AsmToken::LParen:
531536 case AsmToken::Integer:
537+ return tryParseExpression (Operands, 0 );
532538 case AsmToken::Dot:
533- return tryParseExpression (Operands);
539+ return tryParseExpression (Operands, 2 );
534540 case AsmToken::Plus:
535541 case AsmToken::Minus: {
536542 // If the sign preceeds a number, parse the number,
@@ -540,7 +546,7 @@ bool AVRAsmParser::parseOperand(OperandVector &Operands, bool maybeReg) {
540546 case AsmToken::BigNum:
541547 case AsmToken::Identifier:
542548 case AsmToken::Real:
543- if (!tryParseExpression (Operands))
549+ if (!tryParseExpression (Operands, 0 ))
544550 return false ;
545551 break ;
546552 default :
@@ -643,6 +649,7 @@ bool AVRAsmParser::ParseInstruction(ParseInstructionInfo &Info,
643649 // These specific operands should be treated as addresses/symbols/labels,
644650 // other than registers.
645651 bool maybeReg = true ;
652+
646653 if (OperandNum == 1 ) {
647654 std::array<StringRef, 8 > Insts = {" lds" , " adiw" , " sbiw" , " ldi" };
648655 for (auto Inst : Insts) {
0 commit comments