46 CurPtr = CurBuf.
begin();
53 AsmToken AsmLexer::ReturnError(
const char *Loc,
const std::string &Msg) {
59 int AsmLexer::getNextChar() {
60 if (CurPtr == CurBuf.
end())
62 return (
unsigned char)*CurPtr++;
70 AsmToken AsmLexer::LexFloatLiteral() {
78 if (*CurPtr ==
'e' || *CurPtr ==
'E') {
80 if (*CurPtr ==
'-' || *CurPtr ==
'+')
96 AsmToken AsmLexer::LexHexFloatLiteral(
bool NoIntDigits) {
97 assert((*CurPtr ==
'p' || *CurPtr ==
'P' || *CurPtr ==
'.') &&
98 "unexpected parse state in floating hex");
99 bool NoFracDigits =
true;
102 if (*CurPtr ==
'.') {
105 const char *FracStart = CurPtr;
109 NoFracDigits = CurPtr == FracStart;
112 if (NoIntDigits && NoFracDigits)
113 return ReturnError(
TokStart,
"invalid hexadecimal floating-point constant: " 114 "expected at least one significand digit");
117 if (*CurPtr !=
'p' && *CurPtr !=
'P')
118 return ReturnError(
TokStart,
"invalid hexadecimal floating-point constant: " 119 "expected exponent part 'p'");
122 if (*CurPtr ==
'+' || *CurPtr ==
'-')
126 const char *ExpStart = CurPtr;
130 if (CurPtr == ExpStart)
131 return ReturnError(
TokStart,
"invalid hexadecimal floating-point constant: " 132 "expected at least one exponent digit");
139 return isAlnum(c) || c ==
'_' || c ==
'$' || c ==
'.' ||
140 (c ==
'@' && AllowAt) || c ==
'?';
143 AsmToken AsmLexer::LexIdentifier() {
145 if (CurPtr[-1] ==
'.' &&
isDigit(*CurPtr)) {
149 if (*CurPtr ==
'e' || *CurPtr ==
'E' ||
151 return LexFloatLiteral();
169 IsAtStartOfStatement =
false;
173 return LexLineComment();
175 IsAtStartOfStatement =
false;
181 const char *CommentTextStart = CurPtr;
182 while (CurPtr != CurBuf.
end()) {
192 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
199 return ReturnError(
TokStart,
"unterminated comment");
204 AsmToken AsmLexer::LexLineComment() {
209 const char *CommentTextStart = CurPtr;
210 int CurChar = getNextChar();
211 while (CurChar !=
'\n' && CurChar !=
'\r' && CurChar != EOF)
212 CurChar = getNextChar();
213 if (CurChar ==
'\r' && CurPtr != CurBuf.
end() && *CurPtr ==
'\n')
220 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
223 IsAtStartOfLine =
true;
225 if (IsAtStartOfStatement)
228 IsAtStartOfStatement =
true;
236 if (CurPtr[0] ==
'U')
238 if (CurPtr[0] ==
'L')
240 if (CurPtr[0] ==
'L')
246 static unsigned doLookAhead(
const char *&CurPtr,
unsigned DefaultRadix) {
247 const char *FirstHex =
nullptr;
248 const char *LookAhead = CurPtr;
254 FirstHex = LookAhead;
260 bool isHex = *LookAhead ==
'h' || *LookAhead ==
'H';
261 CurPtr = isHex || !FirstHex ? LookAhead : FirstHex;
284 if (IsParsingMSInlineAsm && isdigit(CurPtr[-1])) {
285 const char *FirstNonBinary = (CurPtr[-1] !=
'0' && CurPtr[-1] !=
'1') ?
286 CurPtr - 1 :
nullptr;
287 const char *OldCurPtr = CurPtr;
289 if (*CurPtr !=
'0' && *CurPtr !=
'1' && !FirstNonBinary)
290 FirstNonBinary = CurPtr;
295 if (*CurPtr ==
'h' || *CurPtr ==
'H') {
299 }
else if (FirstNonBinary && FirstNonBinary + 1 == CurPtr &&
300 (*FirstNonBinary ==
'b' || *FirstNonBinary ==
'B'))
303 if (Radix == 2 || Radix == 16) {
308 return ReturnError(
TokStart, Radix == 2 ?
"invalid binary number" :
309 "invalid hexdecimal number");
322 if (CurPtr[-1] !=
'0' || CurPtr[0] ==
'.') {
324 bool isHex = Radix == 16;
326 if (!isHex && (*CurPtr ==
'.' || *CurPtr ==
'e')) {
328 return LexFloatLiteral();
335 return ReturnError(
TokStart, !isHex ?
"invalid decimal number" :
336 "invalid hexdecimal number");
339 if (Radix == 2 || Radix == 16)
349 if (!IsParsingMSInlineAsm && ((*CurPtr ==
'b') || (*CurPtr ==
'B'))) {
357 const char *NumStart = CurPtr;
358 while (CurPtr[0] ==
'0' || CurPtr[0] ==
'1')
362 if (CurPtr == NumStart)
363 return ReturnError(
TokStart,
"invalid binary number");
369 return ReturnError(
TokStart,
"invalid binary number");
378 if ((*CurPtr ==
'x') || (*CurPtr ==
'X')) {
380 const char *NumStart = CurPtr;
386 if (CurPtr[0] ==
'.' || CurPtr[0] ==
'p' || CurPtr[0] ==
'P')
387 return LexHexFloatLiteral(NumStart == CurPtr);
390 if (CurPtr == NumStart)
391 return ReturnError(CurPtr-2,
"invalid hexadecimal number");
395 return ReturnError(
TokStart,
"invalid hexadecimal number");
398 if (!IsParsingMSInlineAsm && (*CurPtr ==
'h' || *CurPtr ==
'H'))
411 bool isHex = Radix == 16;
414 return ReturnError(
TokStart, !isHex ?
"invalid octal number" :
415 "invalid hexdecimal number");
429 AsmToken AsmLexer::LexSingleQuote() {
430 int CurChar = getNextChar();
433 CurChar = getNextChar();
436 return ReturnError(
TokStart,
"unterminated single quote");
438 CurChar = getNextChar();
441 return ReturnError(
TokStart,
"single quote way too long");
449 char theChar = Res[2];
451 default: Value = theChar;
break;
452 case '\'': Value =
'\'';
break;
453 case 't': Value =
'\t';
break;
454 case 'n': Value =
'\n';
break;
455 case 'b': Value =
'\b';
break;
465 int CurChar = getNextChar();
467 while (CurChar !=
'"') {
468 if (CurChar ==
'\\') {
470 CurChar = getNextChar();
474 return ReturnError(
TokStart,
"unterminated string constant");
476 CurChar = getNextChar();
485 while (!isAtStartOfComment(CurPtr) &&
486 !isAtStatementSeparator(CurPtr) &&
487 *CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
493 StringRef AsmLexer::LexUntilEndOfLine() {
496 while (*CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
503 bool ShouldSkipSpace) {
510 std::string SavedErr =
getErr();
514 for (ReadCount = 0; ReadCount < Buf.
size(); ++ReadCount) {
517 Buf[ReadCount] = Token;
527 bool AsmLexer::isAtStartOfComment(
const char *
Ptr) {
530 if (CommentString.
size() == 1)
531 return CommentString[0] == Ptr[0];
534 if (CommentString[1] ==
'#')
535 return CommentString[0] == Ptr[0];
537 return strncmp(Ptr, CommentString.
data(), CommentString.
size()) == 0;
540 bool AsmLexer::isAtStatementSeparator(
const char *Ptr) {
548 int CurChar = getNextChar();
550 if (!IsPeeking && CurChar ==
'#' && IsAtStartOfStatement) {
565 return LexLineComment();
569 return LexLineComment();
571 if (isAtStatementSeparator(
TokStart)) {
573 IsAtStartOfLine =
true;
574 IsAtStartOfStatement =
true;
581 if (CurChar == EOF && !IsAtStartOfStatement) {
582 IsAtStartOfLine =
true;
583 IsAtStartOfStatement =
true;
586 IsAtStartOfLine =
false;
587 bool OldIsAtStartOfStatement = IsAtStartOfStatement;
588 IsAtStartOfStatement =
false;
592 if (isalpha(CurChar) || CurChar ==
'_' || CurChar ==
'.')
593 return LexIdentifier();
596 return ReturnError(
TokStart,
"invalid character in input");
598 IsAtStartOfLine =
true;
599 IsAtStartOfStatement =
true;
604 IsAtStartOfStatement = OldIsAtStartOfStatement;
605 while (*CurPtr ==
' ' || *CurPtr ==
'\t')
612 IsAtStartOfLine =
true;
613 IsAtStartOfStatement =
true;
615 if (CurPtr != CurBuf.
end() && *CurPtr ==
'\n')
621 IsAtStartOfLine =
true;
622 IsAtStartOfStatement =
true;
640 if (*CurPtr ==
'=') {
646 if (*CurPtr ==
'|') {
653 if (*CurPtr ==
'&') {
659 if (*CurPtr ==
'=') {
667 unsigned OperatorLength;
669 std::tie(Operator, OperatorLength) =
699 CurPtr += OperatorLength - 1;
705 IsAtStartOfStatement = OldIsAtStartOfStatement;
708 case '\'':
return LexSingleQuote();
709 case '"':
return LexQuote();
710 case '0':
case '1':
case '2':
case '3':
case '4':
711 case '5':
case '6':
case '7':
case '8':
case '9':
AsmCommentConsumer * CommentConsumer
Compute iterated dominance frontiers using a linear time algorithm.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
void setBuffer(StringRef Buf, const char *ptr=nullptr)
The access may reference the value stored in memory.
Target independent representation for an assembler token.
This file implements a class to represent arbitrary precision integral constant values and operations...
static bool startswith(StringRef Magic, const char(&S)[N])
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true) override
Look ahead an arbitrary number of tokens.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
This class is intended to be used as a base class for asm properties and features specific to the tar...
A switch()-like statement whose cases are string literals.
void SetError(SMLoc errLoc, const std::string &err)
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
size_t size() const
size - Get the array size.
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
const char * getSeparatorString() const
static AsmToken intToken(StringRef Ref, APInt &Value)
StringRef getCommentString() const
const std::string & getErr()
Get the current error string.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
bool hasMipsExpressions() const
void UnLex(AsmToken const &Token)
This is a utility class that provides an abstraction for the common functionality between Instruction...
StringRef LexUntilEndOfStatement() override
bool is(TokenKind K) const
Class for arbitrary precision integers.
A utility class that uses RAII to save and restore the value of a variable.
static unsigned doLookAhead(const char *&CurPtr, unsigned DefaultRadix)
static SMLoc getFromPointer(const char *Ptr)
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
AsmToken LexToken() override
LexToken - Read the next token and return its code.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
SMLoc getErrLoc()
Get the current error location.
This file provides utility classes that use RAII to save and restore values.
static void SkipIgnoredIntegerSuffix(const char *&CurPtr)
StringRef - Represent a constant reference to a string, i.e.
Represents a location in source code.
static bool IsIdentifierChar(char c, bool AllowAt)
LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@?]*.
AsmLexer(const MCAsmInfo &MAI)