45 CurPtr = CurBuf.
begin();
52 AsmToken AsmLexer::ReturnError(
const char *Loc,
const std::string &Msg) {
58 int AsmLexer::getNextChar() {
59 if (CurPtr == CurBuf.
end())
61 return (
unsigned char)*CurPtr++;
67 AsmToken AsmLexer::LexFloatLiteral() {
72 if (*CurPtr ==
'-' || *CurPtr ==
'+')
73 return ReturnError(CurPtr,
"Invalid sign in float literal");
76 if ((*CurPtr ==
'e' || *CurPtr ==
'E')) {
79 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)) {
151 *CurPtr ==
'e' || *CurPtr ==
'E')
152 return LexFloatLiteral();
170 IsAtStartOfStatement =
false;
174 return LexLineComment();
176 IsAtStartOfStatement =
false;
182 const char *CommentTextStart = CurPtr;
183 while (CurPtr != CurBuf.
end()) {
193 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
200 return ReturnError(
TokStart,
"unterminated comment");
205 AsmToken AsmLexer::LexLineComment() {
210 const char *CommentTextStart = CurPtr;
211 int CurChar = getNextChar();
212 while (CurChar !=
'\n' && CurChar !=
'\r' && CurChar != EOF)
213 CurChar = getNextChar();
214 if (CurChar ==
'\r' && CurPtr != CurBuf.
end() && *CurPtr ==
'\n')
221 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
224 IsAtStartOfLine =
true;
226 if (IsAtStartOfStatement)
229 IsAtStartOfStatement =
true;
237 if (CurPtr[0] ==
'U')
239 if (CurPtr[0] ==
'L')
241 if (CurPtr[0] ==
'L')
249 const char *FirstNonDec =
nullptr;
250 const char *LookAhead = CurPtr;
256 FirstNonDec = LookAhead;
265 bool isHex = LexHex && (*LookAhead ==
'h' || *LookAhead ==
'H');
266 CurPtr = isHex || !FirstNonDec ? LookAhead : FirstNonDec;
290 const char *FirstNonBinary = (CurPtr[-1] !=
'0' && CurPtr[-1] !=
'1') ?
291 CurPtr - 1 :
nullptr;
292 const char *OldCurPtr = CurPtr;
294 if (*CurPtr !=
'0' && *CurPtr !=
'1' && !FirstNonBinary)
295 FirstNonBinary = CurPtr;
300 if (*CurPtr ==
'h' || *CurPtr ==
'H') {
304 }
else if (FirstNonBinary && FirstNonBinary + 1 == CurPtr &&
305 (*FirstNonBinary ==
'b' || *FirstNonBinary ==
'B'))
308 if (Radix == 2 || Radix == 16) {
313 return ReturnError(
TokStart, Radix == 2 ?
"invalid binary number" :
314 "invalid hexdecimal number");
327 if (CurPtr[-1] !=
'0' || CurPtr[0] ==
'.') {
329 bool isHex = Radix == 16;
331 if (!isHex && (*CurPtr ==
'.' || *CurPtr ==
'e' || *CurPtr ==
'E')) {
334 return LexFloatLiteral();
341 return ReturnError(
TokStart, !isHex ?
"invalid decimal number" :
342 "invalid hexdecimal number");
363 const char *NumStart = CurPtr;
364 while (CurPtr[0] ==
'0' || CurPtr[0] ==
'1')
368 if (CurPtr == NumStart)
369 return ReturnError(
TokStart,
"invalid binary number");
375 return ReturnError(
TokStart,
"invalid binary number");
384 if ((*CurPtr ==
'x') || (*CurPtr ==
'X')) {
386 const char *NumStart = CurPtr;
392 if (CurPtr[0] ==
'.' || CurPtr[0] ==
'p' || CurPtr[0] ==
'P')
393 return LexHexFloatLiteral(NumStart == CurPtr);
396 if (CurPtr == NumStart)
397 return ReturnError(CurPtr-2,
"invalid hexadecimal number");
399 APInt Result(128, 0);
401 return ReturnError(
TokStart,
"invalid hexadecimal number");
417 bool isHex = Radix == 16;
420 return ReturnError(
TokStart, !isHex ?
"invalid octal number" :
421 "invalid hexdecimal number");
435 AsmToken AsmLexer::LexSingleQuote() {
436 int CurChar = getNextChar();
439 CurChar = getNextChar();
442 return ReturnError(
TokStart,
"unterminated single quote");
444 CurChar = getNextChar();
447 return ReturnError(
TokStart,
"single quote way too long");
455 char theChar = Res[2];
457 default: Value = theChar;
break;
458 case '\'': Value =
'\'';
break;
459 case 't': Value =
'\t';
break;
460 case 'n': Value =
'\n';
break;
461 case 'b': Value =
'\b';
break;
471 int CurChar = getNextChar();
473 while (CurChar !=
'"') {
474 if (CurChar ==
'\\') {
476 CurChar = getNextChar();
480 return ReturnError(
TokStart,
"unterminated string constant");
482 CurChar = getNextChar();
491 while (!isAtStartOfComment(CurPtr) &&
492 !isAtStatementSeparator(CurPtr) &&
493 *CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
499 StringRef AsmLexer::LexUntilEndOfLine() {
502 while (*CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
509 bool ShouldSkipSpace) {
516 std::string SavedErr =
getErr();
520 for (ReadCount = 0; ReadCount < Buf.
size(); ++ReadCount) {
523 Buf[ReadCount] = Token;
533 bool AsmLexer::isAtStartOfComment(
const char *Ptr) {
536 if (CommentString.
size() == 1)
537 return CommentString[0] == Ptr[0];
540 if (CommentString[1] ==
'#')
541 return CommentString[0] == Ptr[0];
543 return strncmp(Ptr, CommentString.
data(), CommentString.
size()) == 0;
546 bool AsmLexer::isAtStatementSeparator(
const char *Ptr) {
554 int CurChar = getNextChar();
556 if (!IsPeeking && CurChar ==
'#' && IsAtStartOfStatement) {
571 return LexLineComment();
575 return LexLineComment();
577 if (isAtStatementSeparator(
TokStart)) {
579 IsAtStartOfLine =
true;
580 IsAtStartOfStatement =
true;
587 if (CurChar == EOF && !IsAtStartOfStatement) {
588 IsAtStartOfLine =
true;
589 IsAtStartOfStatement =
true;
592 IsAtStartOfLine =
false;
593 bool OldIsAtStartOfStatement = IsAtStartOfStatement;
594 IsAtStartOfStatement =
false;
598 if (isalpha(CurChar) || CurChar ==
'_' || CurChar ==
'.')
599 return LexIdentifier();
602 return ReturnError(
TokStart,
"invalid character in input");
604 IsAtStartOfLine =
true;
605 IsAtStartOfStatement =
true;
610 IsAtStartOfStatement = OldIsAtStartOfStatement;
611 while (*CurPtr ==
' ' || *CurPtr ==
'\t')
618 IsAtStartOfLine =
true;
619 IsAtStartOfStatement =
true;
621 if (CurPtr != CurBuf.
end() && *CurPtr ==
'\n')
627 IsAtStartOfLine =
true;
628 IsAtStartOfStatement =
true;
645 if (*CurPtr ==
'=') {
651 if (*CurPtr ==
'>') {
657 if (*CurPtr ==
'|') {
664 if (*CurPtr ==
'&') {
670 if (*CurPtr ==
'=') {
678 unsigned OperatorLength;
680 std::tie(Operator, OperatorLength) =
710 CurPtr += OperatorLength - 1;
716 IsAtStartOfStatement = OldIsAtStartOfStatement;
719 case '\'':
return LexSingleQuote();
720 case '"':
return LexQuote();
721 case '0':
case '1':
case '2':
case '3':
case '4':
722 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 bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
static unsigned doHexLookAhead(const char *&CurPtr, unsigned DefaultRadix, bool LexHex)
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.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
This file implements a class to represent arbitrary precision integral constant values and operations...
static bool startswith(StringRef Magic, const char(&S)[N])
size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true) override
Look ahead an arbitrary number of tokens.
LLVM_NODISCARD size_t size() const
size - Get the string size.
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.
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.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
LLVM_NODISCARD StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
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)