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')
248 const char *FirstNonDec =
nullptr;
249 const char *LookAhead = CurPtr;
255 FirstNonDec = LookAhead;
264 bool isHex = LexHex && (*LookAhead ==
'h' || *LookAhead ==
'H');
265 CurPtr = isHex || !FirstNonDec ? LookAhead : FirstNonDec;
289 const char *FirstNonBinary = (CurPtr[-1] !=
'0' && CurPtr[-1] !=
'1') ?
290 CurPtr - 1 :
nullptr;
291 const char *OldCurPtr = CurPtr;
293 if (*CurPtr !=
'0' && *CurPtr !=
'1' && !FirstNonBinary)
294 FirstNonBinary = CurPtr;
299 if (*CurPtr ==
'h' || *CurPtr ==
'H') {
303 }
else if (FirstNonBinary && FirstNonBinary + 1 == CurPtr &&
304 (*FirstNonBinary ==
'b' || *FirstNonBinary ==
'B'))
307 if (Radix == 2 || Radix == 16) {
312 return ReturnError(
TokStart, Radix == 2 ?
"invalid binary number" :
313 "invalid hexdecimal number");
326 if (CurPtr[-1] !=
'0' || CurPtr[0] ==
'.') {
328 bool isHex = Radix == 16;
330 if (!isHex && (*CurPtr ==
'.' || *CurPtr ==
'e')) {
332 return LexFloatLiteral();
339 return ReturnError(
TokStart, !isHex ?
"invalid decimal number" :
340 "invalid hexdecimal number");
361 const char *NumStart = CurPtr;
362 while (CurPtr[0] ==
'0' || CurPtr[0] ==
'1')
366 if (CurPtr == NumStart)
367 return ReturnError(
TokStart,
"invalid binary number");
373 return ReturnError(
TokStart,
"invalid binary number");
382 if ((*CurPtr ==
'x') || (*CurPtr ==
'X')) {
384 const char *NumStart = CurPtr;
390 if (CurPtr[0] ==
'.' || CurPtr[0] ==
'p' || CurPtr[0] ==
'P')
391 return LexHexFloatLiteral(NumStart == CurPtr);
394 if (CurPtr == NumStart)
395 return ReturnError(CurPtr-2,
"invalid hexadecimal number");
397 APInt Result(128, 0);
399 return ReturnError(
TokStart,
"invalid hexadecimal number");
415 bool isHex = Radix == 16;
418 return ReturnError(
TokStart, !isHex ?
"invalid octal number" :
419 "invalid hexdecimal number");
433 AsmToken AsmLexer::LexSingleQuote() {
434 int CurChar = getNextChar();
437 CurChar = getNextChar();
440 return ReturnError(
TokStart,
"unterminated single quote");
442 CurChar = getNextChar();
445 return ReturnError(
TokStart,
"single quote way too long");
453 char theChar = Res[2];
455 default: Value = theChar;
break;
456 case '\'': Value =
'\'';
break;
457 case 't': Value =
'\t';
break;
458 case 'n': Value =
'\n';
break;
459 case 'b': Value =
'\b';
break;
469 int CurChar = getNextChar();
471 while (CurChar !=
'"') {
472 if (CurChar ==
'\\') {
474 CurChar = getNextChar();
478 return ReturnError(
TokStart,
"unterminated string constant");
480 CurChar = getNextChar();
489 while (!isAtStartOfComment(CurPtr) &&
490 !isAtStatementSeparator(CurPtr) &&
491 *CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
497 StringRef AsmLexer::LexUntilEndOfLine() {
500 while (*CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
507 bool ShouldSkipSpace) {
514 std::string SavedErr =
getErr();
518 for (ReadCount = 0; ReadCount < Buf.
size(); ++ReadCount) {
521 Buf[ReadCount] = Token;
531 bool AsmLexer::isAtStartOfComment(
const char *Ptr) {
534 if (CommentString.
size() == 1)
535 return CommentString[0] == Ptr[0];
538 if (CommentString[1] ==
'#')
539 return CommentString[0] == Ptr[0];
541 return strncmp(Ptr, CommentString.
data(), CommentString.
size()) == 0;
544 bool AsmLexer::isAtStatementSeparator(
const char *Ptr) {
552 int CurChar = getNextChar();
554 if (!IsPeeking && CurChar ==
'#' && IsAtStartOfStatement) {
569 return LexLineComment();
573 return LexLineComment();
575 if (isAtStatementSeparator(
TokStart)) {
577 IsAtStartOfLine =
true;
578 IsAtStartOfStatement =
true;
585 if (CurChar == EOF && !IsAtStartOfStatement) {
586 IsAtStartOfLine =
true;
587 IsAtStartOfStatement =
true;
590 IsAtStartOfLine =
false;
591 bool OldIsAtStartOfStatement = IsAtStartOfStatement;
592 IsAtStartOfStatement =
false;
596 if (isalpha(CurChar) || CurChar ==
'_' || CurChar ==
'.')
597 return LexIdentifier();
600 return ReturnError(
TokStart,
"invalid character in input");
602 IsAtStartOfLine =
true;
603 IsAtStartOfStatement =
true;
608 IsAtStartOfStatement = OldIsAtStartOfStatement;
609 while (*CurPtr ==
' ' || *CurPtr ==
'\t')
616 IsAtStartOfLine =
true;
617 IsAtStartOfStatement =
true;
619 if (CurPtr != CurBuf.
end() && *CurPtr ==
'\n')
625 IsAtStartOfLine =
true;
626 IsAtStartOfStatement =
true;
643 if (*CurPtr ==
'=') {
649 if (*CurPtr ==
'>') {
655 if (*CurPtr ==
'|') {
662 if (*CurPtr ==
'&') {
668 if (*CurPtr ==
'=') {
676 unsigned OperatorLength;
678 std::tie(Operator, OperatorLength) =
708 CurPtr += OperatorLength - 1;
714 IsAtStartOfStatement = OldIsAtStartOfStatement;
717 case '\'':
return LexSingleQuote();
718 case '"':
return LexQuote();
719 case '0':
case '1':
case '2':
case '3':
case '4':
720 case '5':
case '6':
case '7':
case '8':
case '9':
AsmCommentConsumer * CommentConsumer
This class represents lattice values for constants.
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.
static unsigned doHexLookAhead(const char *&CurPtr, unsigned DefaultRadix, bool LexHex)
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 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)