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++;
69 AsmToken AsmLexer::LexFloatLiteral() {
71 while (isdigit(*CurPtr))
77 if (*CurPtr ==
'e' || *CurPtr ==
'E') {
79 if (*CurPtr ==
'-' || *CurPtr ==
'+')
81 while (isdigit(*CurPtr))
95 AsmToken AsmLexer::LexHexFloatLiteral(
bool NoIntDigits) {
96 assert((*CurPtr ==
'p' || *CurPtr ==
'P' || *CurPtr ==
'.') &&
97 "unexpected parse state in floating hex");
98 bool NoFracDigits =
true;
101 if (*CurPtr ==
'.') {
104 const char *FracStart = CurPtr;
105 while (isxdigit(*CurPtr))
108 NoFracDigits = CurPtr == FracStart;
111 if (NoIntDigits && NoFracDigits)
112 return ReturnError(
TokStart,
"invalid hexadecimal floating-point constant: "
113 "expected at least one significand digit");
116 if (*CurPtr !=
'p' && *CurPtr !=
'P')
117 return ReturnError(
TokStart,
"invalid hexadecimal floating-point constant: "
118 "expected exponent part 'p'");
121 if (*CurPtr ==
'+' || *CurPtr ==
'-')
125 const char *ExpStart = CurPtr;
126 while (isdigit(*CurPtr))
129 if (CurPtr == ExpStart)
130 return ReturnError(
TokStart,
"invalid hexadecimal floating-point constant: "
131 "expected at least one exponent digit");
138 return isalnum(c) || c ==
'_' || c ==
'$' || c ==
'.' ||
139 (c ==
'@' && AllowAt) || c ==
'?';
142 AsmToken AsmLexer::LexIdentifier() {
144 if (CurPtr[-1] ==
'.' && isdigit(*CurPtr)) {
146 while (isdigit(*CurPtr))
148 if (*CurPtr ==
'e' || *CurPtr ==
'E' ||
150 return LexFloatLiteral();
168 IsAtStartOfStatement =
false;
172 return LexLineComment();
174 IsAtStartOfStatement =
false;
180 const char *CommentTextStart = CurPtr;
181 while (CurPtr != CurBuf.
end()) {
191 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
198 return ReturnError(
TokStart,
"unterminated comment");
203 AsmToken AsmLexer::LexLineComment() {
208 const char *CommentTextStart = CurPtr;
209 int CurChar = getNextChar();
210 while (CurChar !=
'\n' && CurChar !=
'\r' && CurChar != EOF)
211 CurChar = getNextChar();
217 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
220 IsAtStartOfLine =
true;
222 if (IsAtStartOfStatement)
225 IsAtStartOfStatement =
true;
233 if (CurPtr[0] ==
'U')
235 if (CurPtr[0] ==
'L')
237 if (CurPtr[0] ==
'L')
243 static unsigned doLookAhead(
const char *&CurPtr,
unsigned DefaultRadix) {
244 const char *FirstHex =
nullptr;
245 const char *LookAhead = CurPtr;
247 if (isdigit(*LookAhead)) {
249 }
else if (isxdigit(*LookAhead)) {
251 FirstHex = LookAhead;
257 bool isHex = *LookAhead ==
'h' || *LookAhead ==
'H';
258 CurPtr = isHex || !FirstHex ? LookAhead : FirstHex;
281 if (IsParsingMSInlineAsm && isdigit(CurPtr[-1])) {
282 const char *FirstNonBinary = (CurPtr[-1] !=
'0' && CurPtr[-1] !=
'1') ?
283 CurPtr - 1 :
nullptr;
284 const char *OldCurPtr = CurPtr;
285 while (isxdigit(*CurPtr)) {
286 if (*CurPtr !=
'0' && *CurPtr !=
'1' && !FirstNonBinary)
287 FirstNonBinary = CurPtr;
292 if (*CurPtr ==
'h' || *CurPtr ==
'H') {
296 }
else if (FirstNonBinary && FirstNonBinary + 1 == CurPtr &&
297 (*FirstNonBinary ==
'b' || *FirstNonBinary ==
'B'))
300 if (Radix == 2 || Radix == 16) {
304 if (Result.drop_back().getAsInteger(Radix,
Value))
305 return ReturnError(
TokStart, Radix == 2 ?
"invalid binary number" :
306 "invalid hexdecimal number");
319 if (CurPtr[-1] !=
'0' || CurPtr[0] ==
'.') {
321 bool isHex = Radix == 16;
323 if (!isHex && (*CurPtr ==
'.' || *CurPtr ==
'e')) {
325 return LexFloatLiteral();
331 if (Result.getAsInteger(Radix,
Value))
332 return ReturnError(
TokStart, !isHex ?
"invalid decimal number" :
333 "invalid hexdecimal number");
336 if (Radix == 2 || Radix == 16)
346 if (!IsParsingMSInlineAsm && ((*CurPtr ==
'b') || (*CurPtr ==
'B'))) {
349 if (!isdigit(CurPtr[0])) {
354 const char *NumStart = CurPtr;
355 while (CurPtr[0] ==
'0' || CurPtr[0] ==
'1')
359 if (CurPtr == NumStart)
360 return ReturnError(
TokStart,
"invalid binary number");
365 if (Result.substr(2).getAsInteger(2,
Value))
366 return ReturnError(
TokStart,
"invalid binary number");
375 if ((*CurPtr ==
'x') || (*CurPtr ==
'X')) {
377 const char *NumStart = CurPtr;
378 while (isxdigit(CurPtr[0]))
383 if (CurPtr[0] ==
'.' || CurPtr[0] ==
'p' || CurPtr[0] ==
'P')
384 return LexHexFloatLiteral(NumStart == CurPtr);
387 if (CurPtr == NumStart)
388 return ReturnError(CurPtr-2,
"invalid hexadecimal number");
390 APInt Result(128, 0);
392 return ReturnError(
TokStart,
"invalid hexadecimal number");
395 if (!IsParsingMSInlineAsm && (*CurPtr ==
'h' || *CurPtr ==
'H'))
408 bool isHex = Radix == 16;
410 if (Result.getAsInteger(Radix,
Value))
411 return ReturnError(
TokStart, !isHex ?
"invalid octal number" :
412 "invalid hexdecimal number");
426 AsmToken AsmLexer::LexSingleQuote() {
427 int CurChar = getNextChar();
430 CurChar = getNextChar();
433 return ReturnError(
TokStart,
"unterminated single quote");
435 CurChar = getNextChar();
438 return ReturnError(
TokStart,
"single quote way too long");
446 char theChar = Res[2];
448 default: Value = theChar;
break;
449 case '\'': Value =
'\'';
break;
450 case 't': Value =
'\t';
break;
451 case 'n': Value =
'\n';
break;
452 case 'b': Value =
'\b';
break;
462 int CurChar = getNextChar();
464 while (CurChar !=
'"') {
465 if (CurChar ==
'\\') {
467 CurChar = getNextChar();
471 return ReturnError(
TokStart,
"unterminated string constant");
473 CurChar = getNextChar();
482 while (!isAtStartOfComment(CurPtr) &&
483 !isAtStatementSeparator(CurPtr) &&
484 *CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
490 StringRef AsmLexer::LexUntilEndOfLine() {
493 while (*CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
500 bool ShouldSkipSpace) {
507 std::string SavedErr =
getErr();
511 for (ReadCount = 0; ReadCount < Buf.
size(); ++ReadCount) {
514 Buf[ReadCount] = Token;
524 bool AsmLexer::isAtStartOfComment(
const char *
Ptr) {
527 if (CommentString.
size() == 1)
528 return CommentString[0] == Ptr[0];
531 if (CommentString[1] ==
'#')
532 return CommentString[0] == Ptr[0];
534 return strncmp(Ptr, CommentString.
data(), CommentString.
size()) == 0;
537 bool AsmLexer::isAtStatementSeparator(
const char *Ptr) {
545 int CurChar = getNextChar();
547 if (!IsPeeking && CurChar ==
'#' && IsAtStartOfStatement) {
562 return LexLineComment();
566 return LexLineComment();
568 if (isAtStatementSeparator(
TokStart)) {
570 IsAtStartOfLine =
true;
571 IsAtStartOfStatement =
true;
578 if (CurChar == EOF && !IsAtStartOfStatement) {
579 IsAtStartOfLine =
true;
580 IsAtStartOfStatement =
true;
583 IsAtStartOfLine =
false;
584 bool OldIsAtStartOfStatement = IsAtStartOfStatement;
585 IsAtStartOfStatement =
false;
589 if (isalpha(CurChar) || CurChar ==
'_' || CurChar ==
'.')
590 return LexIdentifier();
593 return ReturnError(
TokStart,
"invalid character in input");
595 IsAtStartOfLine =
true;
596 IsAtStartOfStatement =
true;
601 IsAtStartOfStatement = OldIsAtStartOfStatement;
602 while (*CurPtr ==
' ' || *CurPtr ==
'\t')
610 IsAtStartOfLine =
true;
611 IsAtStartOfStatement =
true;
629 if (*CurPtr ==
'=') {
635 if (*CurPtr ==
'|') {
642 if (*CurPtr ==
'&') {
648 if (*CurPtr ==
'=') {
656 unsigned OperatorLength;
658 std::tie(Operator, OperatorLength) =
688 CurPtr += OperatorLength - 1;
694 IsAtStartOfStatement = OldIsAtStartOfStatement;
697 case '\'':
return LexSingleQuote();
698 case '"':
return LexQuote();
699 case '0':
case '1':
case '2':
case '3':
case '4':
700 case '5':
case '6':
case '7':
case '8':
case '9':
AsmCommentConsumer * CommentConsumer
StringRef getCommentString() const
void setBuffer(StringRef Buf, const char *ptr=nullptr)
Target independent representation for an assembler token.
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
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 LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
size_t size() const
size - Get the array 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...
static AsmToken intToken(StringRef Ref, APInt &Value)
const std::string & getErr()
Get the current error string.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
bool hasMipsExpressions() const
void UnLex(AsmToken const &Token)
This is a utility class that provides an abstraction for the common functionality between Instruction...
bool is(TokenKind K) const
StringRef LexUntilEndOfStatement() override
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)
const char * getSeparatorString() const
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.
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).
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)