Index: lib/Target/ARM64/AsmParser/ARM64AsmParser.cpp =================================================================== --- lib/Target/ARM64/AsmParser/ARM64AsmParser.cpp +++ lib/Target/ARM64/AsmParser/ARM64AsmParser.cpp @@ -2004,8 +2004,10 @@ SMLoc S = getLoc(); const AsmToken &Tok = Parser.getTok(); // Either an identifier for named values or a 5-bit immediate. - if (Tok.is(AsmToken::Hash)) { - Parser.Lex(); // Eat hash token. + bool Hash = Tok.is(AsmToken::Hash); + if (Hash || Tok.is(AsmToken::Integer)) { + if (Hash) + Parser.Lex(); // Eat hash token. const MCExpr *ImmVal; if (getParser().parseExpression(ImmVal)) return MatchOperand_ParseFail; @@ -2131,9 +2133,11 @@ ARM64AsmParser::tryParseFPImm(OperandVector &Operands) { SMLoc S = getLoc(); - if (Parser.getTok().isNot(AsmToken::Hash)) - return MatchOperand_NoMatch; - Parser.Lex(); // Eat the '#'. + bool Hash = false; + if (Parser.getTok().is(AsmToken::Hash)) { + Parser.Lex(); // Eat '#' + Hash = true; + } // Handle negation, as that still comes through as a separate token. bool isNegative = false; @@ -2179,6 +2183,9 @@ return MatchOperand_Success; } + if (!Hash) + return MatchOperand_NoMatch; + TokError("invalid floating point immediate"); return MatchOperand_ParseFail; } @@ -2270,9 +2277,12 @@ Parser.Lex(); // We expect a number here. - if (getLexer().isNot(AsmToken::Hash)) + bool Hash = getLexer().is(AsmToken::Hash); + if (!Hash && getLexer().isNot(AsmToken::Integer)) return TokError("immediate value expected for shifter operand"); - Parser.Lex(); // Eat the '#'. + + if (Hash) + Parser.Lex(); // Eat the '#'. SMLoc ExprLoc = getLoc(); const MCExpr *ImmVal; @@ -2331,14 +2341,16 @@ return false; } - if (getLexer().isNot(AsmToken::Hash)) { + bool Hash = getLexer().is(AsmToken::Hash); + if (!Hash && getLexer().isNot(AsmToken::Integer)) { SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1); Operands.push_back( ARM64Operand::CreateExtend(ExtOp, 0, S, E, getContext())); return false; } - Parser.Lex(); // Eat the '#'. + if (Hash) + Parser.Lex(); // Eat the '#'. const MCExpr *ImmVal; if (getParser().parseExpression(ImmVal)) @@ -2588,9 +2600,11 @@ const AsmToken &Tok = Parser.getTok(); // Can be either a #imm style literal or an option name - if (Tok.is(AsmToken::Hash)) { + bool Hash = Tok.is(AsmToken::Hash); + if (Hash || Tok.is(AsmToken::Integer)) { // Immediate operand. - Parser.Lex(); // Eat the '#' + if (Hash) + Parser.Lex(); // Eat the '#' const MCExpr *ImmVal; SMLoc ExprLoc = getLoc(); if (getParser().parseExpression(ImmVal)) @@ -3174,13 +3188,15 @@ Parser.Lex(); // Eat the extend op. + bool Hash = getLexer().is(AsmToken::Hash); if (getLexer().is(AsmToken::RBrac)) { // No immediate operand. if (ExtOp == ARM64_AM::UXTX) return Error(ExtLoc, "LSL extend requires immediate operand"); - } else if (getLexer().is(AsmToken::Hash)) { + } else if (Hash || getLexer().is(AsmToken::Integer)) { // Immediate operand. - Parser.Lex(); // Eat the '#' + if (Hash) + Parser.Lex(); // Eat the '#' const MCExpr *ImmVal; SMLoc ExprLoc = getLoc(); if (getParser().parseExpression(ImmVal)) @@ -3208,8 +3224,10 @@ return false; // Immediate expressions. - } else if (Parser.getTok().is(AsmToken::Hash)) { - Parser.Lex(); // Eat hash token. + } else if (Parser.getTok().is(AsmToken::Hash) || + Parser.getTok().is(AsmToken::Integer)) { + if (Parser.getTok().is(AsmToken::Hash)) + Parser.Lex(); // Eat hash token. if (parseSymbolicImmVal(OffsetExpr)) return true; @@ -3482,10 +3500,13 @@ Operands.push_back(ARM64Operand::CreateImm(IdVal, S, E, getContext())); return false; } + case AsmToken::Integer: + case AsmToken::Real: case AsmToken::Hash: { // #42 -> immediate. S = getLoc(); - Parser.Lex(); + if (getLexer().is(AsmToken::Hash)) + Parser.Lex(); // The only Real that should come through here is a literal #0.0 for // the fcmp[e] r, #0.0 instructions. They expect raw token operands, Index: test/MC/ARM64/optional-hash.s =================================================================== --- /dev/null +++ test/MC/ARM64/optional-hash.s @@ -0,0 +1,31 @@ +; RUN: llvm-mc -triple arm64-apple-darwin -show-encoding < %s | FileCheck %s +.text +; parseOperand check +; CHECK: add sp, sp, #32 ; encoding: [0xff,0x83,0x00,0x91] + add sp, sp, 32 + +; Optional shift +; CHECK: adds x3, x4, #4194304 ; encoding: [0x83,0x00,0x50,0xb1] +adds x3, x4, 1024, lsl 12 + +; Optional extend +; CHECK: add sp, x2, x3 ; encoding: [0x5f,0x60,0x23,0x8b] +add sp, x2, x3, uxtx 0 + +; FP immediates +; CHECK: fmov s1, #1.250000e-01 ; encoding: [0x01,0x10,0x28,0x1e] +fmov s1, 0.125 + +; Barrier operand +; CHECK: dmb osh ; encoding: [0xbf,0x33,0x03,0xd5] +dmb 3 + +; Prefetch and memory + +; Single register inside [] +; CHECK: ldnp w3, w2, [x15, #16] ; encoding: [0xe3,0x09,0x42,0x28] +ldnp w3, w2, [x15, 16] + +; Memory, two registers inside [] +; CHECK: prfm pstl3strm, [x4, x5, lsl #3] ; encoding: [0x95,0x78,0xa5,0xf8] +prfm pstl3strm, [x4, x5, lsl 3]