42 bool EndStatementAtEOF) {
48 CurPtr = CurBuf.
begin();
51 this->EndStatementAtEOF = EndStatementAtEOF;
56AsmToken AsmLexer::ReturnError(
const char *Loc,
const std::string &Msg) {
62int AsmLexer::getNextChar() {
63 if (CurPtr == CurBuf.
end())
65 return (
unsigned char)*CurPtr++;
68int AsmLexer::peekNextChar() {
69 if (CurPtr == CurBuf.
end())
71 return (
unsigned char)*CurPtr;
77AsmToken AsmLexer::LexFloatLiteral() {
82 if (*CurPtr ==
'-' || *CurPtr ==
'+')
83 return ReturnError(CurPtr,
"invalid sign in float literal");
86 if ((*CurPtr ==
'e' || *CurPtr ==
'E')) {
89 if (*CurPtr ==
'-' || *CurPtr ==
'+')
106AsmToken AsmLexer::LexHexFloatLiteral(
bool NoIntDigits) {
107 assert((*CurPtr ==
'p' || *CurPtr ==
'P' || *CurPtr ==
'.') &&
108 "unexpected parse state in floating hex");
109 bool NoFracDigits =
true;
112 if (*CurPtr ==
'.') {
115 const char *FracStart = CurPtr;
119 NoFracDigits = CurPtr == FracStart;
122 if (NoIntDigits && NoFracDigits)
123 return ReturnError(
TokStart,
"invalid hexadecimal floating-point constant: "
124 "expected at least one significand digit");
127 if (*CurPtr !=
'p' && *CurPtr !=
'P')
128 return ReturnError(
TokStart,
"invalid hexadecimal floating-point constant: "
129 "expected exponent part 'p'");
132 if (*CurPtr ==
'+' || *CurPtr ==
'-')
136 const char *ExpStart = CurPtr;
140 if (CurPtr == ExpStart)
141 return ReturnError(
TokStart,
"invalid hexadecimal floating-point constant: "
142 "expected at least one exponent digit");
149 return isAlnum(
C) ||
C ==
'_' ||
C ==
'$' ||
C ==
'.' ||
C ==
'?' ||
150 (AllowAt &&
C ==
'@') || (AllowHash &&
C ==
'#');
155 if (CurPtr[-1] ==
'.' &&
isDigit(*CurPtr)) {
162 *CurPtr ==
'e' || *CurPtr ==
'E')
163 return LexFloatLiteral();
181 IsAtStartOfStatement =
false;
187 IsAtStartOfStatement =
false;
191 return LexLineComment();
193 IsAtStartOfStatement =
false;
199 const char *CommentTextStart = CurPtr;
200 while (CurPtr != CurBuf.
end()) {
210 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
217 return ReturnError(
TokStart,
"unterminated comment");
222AsmToken AsmLexer::LexLineComment() {
227 const char *CommentTextStart = CurPtr;
228 int CurChar = getNextChar();
229 while (CurChar !=
'\n' && CurChar !=
'\r' && CurChar != EOF)
230 CurChar = getNextChar();
231 const char *NewlinePtr = CurPtr;
232 if (CurChar ==
'\r' && CurPtr != CurBuf.
end() && *CurPtr ==
'\n')
239 StringRef(CommentTextStart, NewlinePtr - 1 - CommentTextStart));
242 IsAtStartOfLine =
true;
244 if (IsAtStartOfStatement)
247 IsAtStartOfStatement =
true;
255 if (CurPtr[0] ==
'U' || CurPtr[0] ==
'u')
257 if (CurPtr[0] ==
'L' || CurPtr[0] ==
'l')
259 if (CurPtr[0] ==
'L' || CurPtr[0] ==
'l')
267 const char *FirstNonDec =
nullptr;
268 const char *LookAhead = CurPtr;
274 FirstNonDec = LookAhead;
283 bool isHex = LexHex && (*LookAhead ==
'h' || *LookAhead ==
'H');
284 CurPtr = isHex || !FirstNonDec ? LookAhead : FirstNonDec;
290static const char *
findLastDigit(
const char *CurPtr,
unsigned DefaultRadix) {
291 while (hexDigitValue(*CurPtr) < DefaultRadix) {
298 if (
Value.isIntN(64))
312 return "hexadecimal";
314 return "base-" + std::to_string(Radix);
331 const char *FirstNonBinary =
332 (CurPtr[-1] !=
'0' && CurPtr[-1] !=
'1') ? CurPtr - 1 :
nullptr;
333 const char *FirstNonDecimal =
334 (CurPtr[-1] <
'0' || CurPtr[-1] >
'9') ? CurPtr - 1 :
nullptr;
335 const char *OldCurPtr = CurPtr;
339 if (!FirstNonDecimal) {
340 FirstNonDecimal = CurPtr;
351 if (!FirstNonBinary) {
352 FirstNonBinary = CurPtr;
361 if (*CurPtr ==
'.') {
365 return LexFloatLiteral();
374 if (*CurPtr ==
'h' || *CurPtr ==
'H') {
378 }
else if (*CurPtr ==
't' || *CurPtr ==
'T') {
382 }
else if (*CurPtr ==
'o' || *CurPtr ==
'O' || *CurPtr ==
'q' ||
387 }
else if (*CurPtr ==
'y' || *CurPtr ==
'Y') {
391 }
else if (FirstNonDecimal && FirstNonDecimal + 1 == CurPtr &&
393 (*FirstNonDecimal ==
'd' || *FirstNonDecimal ==
'D')) {
395 }
else if (FirstNonBinary && FirstNonBinary + 1 == CurPtr &&
397 (*FirstNonBinary ==
'b' || *FirstNonBinary ==
'B')) {
435 const char *NumStart = CurPtr;
440 if (
StringRef(NumStart, CurPtr - NumStart).getAsInteger(16, Result))
441 return ReturnError(
TokStart,
"invalid hexadecimal number");
448 const char *NumStart = CurPtr;
449 while (*CurPtr ==
'0' || *CurPtr ==
'1')
453 if (
StringRef(NumStart, CurPtr - NumStart).getAsInteger(2, Result))
454 return ReturnError(
TokStart,
"invalid binary number");
467 bool IsHex = Radix == 16;
469 if (!IsHex && (*CurPtr ==
'.' || *CurPtr ==
'e' || *CurPtr ==
'E')) {
472 return LexFloatLiteral();
498 const char *NumStart = CurPtr;
499 while (CurPtr[0] ==
'0' || CurPtr[0] ==
'1')
503 if (CurPtr == NumStart)
504 return ReturnError(
TokStart,
"invalid binary number");
510 return ReturnError(
TokStart,
"invalid binary number");
519 if ((*CurPtr ==
'x') || (*CurPtr ==
'X')) {
521 const char *NumStart = CurPtr;
527 if (CurPtr[0] ==
'.' || CurPtr[0] ==
'p' || CurPtr[0] ==
'P')
528 return LexHexFloatLiteral(NumStart == CurPtr);
531 if (CurPtr == NumStart)
532 return ReturnError(CurPtr-2,
"invalid hexadecimal number");
536 return ReturnError(
TokStart,
"invalid hexadecimal number");
568AsmToken AsmLexer::LexSingleQuote() {
569 int CurChar = getNextChar();
572 return ReturnError(
TokStart,
"invalid usage of character literals");
575 while (CurChar != EOF) {
576 if (CurChar !=
'\'') {
577 CurChar = getNextChar();
578 }
else if (peekNextChar() ==
'\'') {
582 CurChar = getNextChar();
588 return ReturnError(
TokStart,
"unterminated string constant");
593 CurChar = getNextChar();
596 return ReturnError(
TokStart,
"unterminated single quote");
598 CurChar = getNextChar();
601 return ReturnError(
TokStart,
"single quote way too long");
609 char theChar = Res[2];
611 default:
Value = theChar;
break;
612 case '\'':
Value =
'\'';
break;
613 case 't':
Value =
'\t';
break;
614 case 'n':
Value =
'\n';
break;
615 case 'b':
Value =
'\b';
break;
616 case 'f':
Value =
'\f';
break;
617 case 'r':
Value =
'\r';
break;
627 int CurChar = getNextChar();
629 return ReturnError(
TokStart,
"invalid usage of string literals");
632 while (CurChar != EOF) {
633 if (CurChar !=
'"') {
634 CurChar = getNextChar();
635 }
else if (peekNextChar() ==
'"') {
639 CurChar = getNextChar();
645 return ReturnError(
TokStart,
"unterminated string constant");
649 while (CurChar !=
'"') {
650 if (CurChar ==
'\\') {
652 CurChar = getNextChar();
656 return ReturnError(
TokStart,
"unterminated string constant");
658 CurChar = getNextChar();
667 while (!isAtStartOfComment(CurPtr) &&
668 !isAtStatementSeparator(CurPtr) &&
669 *CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
678 while (*CurPtr !=
'\n' && *CurPtr !=
'\r' && CurPtr != CurBuf.
end()) {
685 bool ShouldSkipSpace) {
692 std::string SavedErr =
getErr();
696 for (ReadCount = 0; ReadCount < Buf.
size(); ++ReadCount) {
699 Buf[ReadCount] = Token;
709bool AsmLexer::isAtStartOfComment(
const char *
Ptr) {
715 if (CommentString.
size() == 1)
716 return CommentString[0] ==
Ptr[0];
719 if (CommentString[1] ==
'#')
720 return CommentString[0] ==
Ptr[0];
722 return strncmp(
Ptr, CommentString.
data(), CommentString.
size()) == 0;
725bool AsmLexer::isAtStatementSeparator(
const char *
Ptr) {
733 int CurChar = getNextChar();
735 if (!IsPeeking && CurChar ==
'#' && IsAtStartOfStatement) {
752 return LexLineComment();
756 return LexLineComment();
758 if (isAtStatementSeparator(
TokStart)) {
760 IsAtStartOfLine =
true;
761 IsAtStartOfStatement =
true;
768 if (CurChar == EOF && !IsAtStartOfStatement && EndStatementAtEOF) {
769 IsAtStartOfLine =
true;
770 IsAtStartOfStatement =
true;
773 IsAtStartOfLine =
false;
774 bool OldIsAtStartOfStatement = IsAtStartOfStatement;
775 IsAtStartOfStatement =
false;
782 if (isalpha(CurChar) || CurChar ==
'_' || CurChar ==
'.')
783 return LexIdentifier();
786 return ReturnError(
TokStart,
"invalid character in input");
788 if (EndStatementAtEOF) {
789 IsAtStartOfLine =
true;
790 IsAtStartOfStatement =
true;
796 IsAtStartOfStatement = OldIsAtStartOfStatement;
797 while (*CurPtr ==
' ' || *CurPtr ==
'\t')
804 IsAtStartOfLine =
true;
805 IsAtStartOfStatement =
true;
807 if (CurPtr != CurBuf.
end() && *CurPtr ==
'\n')
813 IsAtStartOfLine =
true;
814 IsAtStartOfStatement =
true;
831 return LexIdentifier();
836 return LexIdentifier();
840 return LexIdentifier();
844 return LexIdentifier();
848 if (*CurPtr ==
'=') {
854 if (*CurPtr ==
'>') {
860 if (*CurPtr ==
'|') {
867 if (*CurPtr ==
'&') {
873 if (*CurPtr ==
'=') {
885 unsigned OperatorLength;
887 std::tie(
Operator, OperatorLength) =
917 CurPtr += OperatorLength - 1;
923 IsAtStartOfStatement = OldIsAtStartOfStatement;
925 case '\'':
return LexSingleQuote();
926 case '"':
return LexQuote();
927 case '0':
case '1':
case '2':
case '3':
case '4':
928 case '5':
case '6':
case '7':
case '8':
case '9':
This file implements a class to represent arbitrary precision integral constant values and operations...
static std::string radixName(unsigned Radix)
static void SkipIgnoredIntegerSuffix(const char *&CurPtr)
static unsigned doHexLookAhead(const char *&CurPtr, unsigned DefaultRadix, bool LexHex)
static AsmToken intToken(StringRef Ref, APInt &Value)
static const char * findLastDigit(const char *CurPtr, unsigned DefaultRadix)
static bool isIdentifierChar(char C)
Return true if the given character satisfies the following regular expression: [-a-zA-Z$....
static bool isDigit(const char C)
static bool isHexDigit(const char C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides utility classes that use RAII to save and restore values.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Class for arbitrary precision integers.
size_t size() const
size - Get the array size.
size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true) override
Look ahead an arbitrary number of tokens.
AsmLexer(const MCAsmInfo &MAI)
StringRef LexUntilEndOfStatement() override
void setBuffer(StringRef Buf, const char *ptr=nullptr, bool EndStatementAtEOF=true)
AsmToken LexToken() override
LexToken - Read the next token and return its code.
Target independent representation for an assembler token.
bool is(TokenKind K) const
This class is intended to be used as a base class for asm properties and features specific to the tar...
bool getRestrictCommentStringToStartOfStatement() const
bool doesAllowDollarAtStartOfIdentifier() const
bool hasMipsExpressions() const
bool shouldUseMotorolaIntegers() const
StringRef getCommentString() const
const char * getSeparatorString() const
bool doesAllowAtAtStartOfIdentifier() const
bool doesAllowHashAtStartOfIdentifier() const
bool shouldAllowAdditionalComments() const
bool doesAllowQuestionAtStartOfIdentifier() const
void UnLex(AsmToken const &Token)
AsmCommentConsumer * CommentConsumer
SMLoc getErrLoc()
Get the current error location.
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
void SetError(SMLoc errLoc, const std::string &err)
bool AllowHashInIdentifier
const std::string & getErr()
Get the current error string.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
This is a utility class that provides an abstraction for the common functionality between Instruction...
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
A switch()-like statement whose cases are string literals.
LLVM Value Representation.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
@ Ref
The access may reference the value stored in memory.
@ Default
The result values are uniform if and only if all operands are uniform.
A utility class that uses RAII to save and restore the value of a variable.