31 using ErrorCallbackType =
37 const char *
Ptr =
nullptr;
38 const char *End =
nullptr;
45 End = Ptr + Str.
size();
48 bool isEOF()
const {
return Ptr == End; }
50 char peek(
int I = 0)
const {
return End - Ptr <=
I ? 0 : Ptr[
I]; }
52 void advance(
unsigned I = 1) { Ptr +=
I; }
57 assert(C.Ptr >= Ptr && C.Ptr <= End);
63 operator bool()
const {
return Ptr !=
nullptr; }
80 StringValueStorage = std::move(StrVal);
81 StringValue = StringValueStorage;
86 this->IntVal = std::move(IntVal);
92 while (isblank(C.peek()))
111 return isalpha(C) || isdigit(C) || C ==
'_' || C ==
'-' || C ==
'.' ||
120 Cursor
C = Cursor(Value.
substr(1, Value.
size() - 2));
123 Str.reserve(C.remaining().size());
125 char Char = C.peek();
127 if (C.peek(1) ==
'\\') {
133 if (isxdigit(C.peek(1)) && isxdigit(C.peek(2))) {
148 for (C.advance(); C.peek() !=
'"'; C.advance()) {
152 "end of machine instruction reached before the closing '\"'");
161 unsigned PrefixLength, ErrorCallbackType ErrorCallback) {
163 C.advance(PrefixLength);
164 if (C.peek() ==
'"') {
167 Token.
reset(Type, String)
177 Token.
reset(Type, Range.upto(C))
178 .setStringValue(Range.upto(C).drop_front(PrefixLength));
252 if (!isalpha(C.peek()) && C.peek() !=
'_')
264 ErrorCallbackType ErrorCallback) {
265 bool IsReference = C.remaining().startswith(
"%bb.");
266 if (!IsReference && !C.remaining().startswith(
"bb."))
269 unsigned PrefixLength = IsReference ? 4 : 3;
270 C.advance(PrefixLength);
271 if (!isdigit(C.peek())) {
273 ErrorCallback(C.location(),
"expected a number after '%bb.'");
276 auto NumberRange =
C;
277 while (isdigit(C.peek()))
280 unsigned StringOffset = PrefixLength + Number.
size();
284 if (C.peek() ==
'.') {
293 .setIntegerValue(
APSInt(Number))
294 .setStringValue(Range.upto(C).drop_front(StringOffset));
300 if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.
size())))
303 C.advance(Rule.
size());
304 auto NumberRange =
C;
305 while (isdigit(C.peek()))
307 Token.
reset(Kind, Range.upto(C)).setIntegerValue(
APSInt(NumberRange.upto(C)));
313 if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.
size())))
316 C.advance(Rule.
size());
317 auto NumberRange =
C;
318 while (isdigit(C.peek()))
321 unsigned StringOffset = Rule.
size() + Number.
size();
322 if (C.peek() ==
'.') {
328 Token.
reset(Kind, Range.upto(C))
329 .setIntegerValue(
APSInt(Number))
330 .setStringValue(Range.upto(C).drop_front(StringOffset));
351 ErrorCallbackType ErrorCallback) {
353 if (!C.remaining().startswith(Rule))
360 ErrorCallbackType ErrorCallback) {
362 if (!C.remaining().startswith(Rule))
364 if (isdigit(C.peek(Rule.
size())))
370 ErrorCallbackType ErrorCallback) {
372 if (!C.remaining().startswith(Rule))
374 if (isdigit(C.peek(Rule.
size())))
380 ErrorCallbackType ErrorCallback) {
390 auto NumberRange =
C;
391 while (isdigit(C.peek()))
394 .setIntegerValue(
APSInt(NumberRange.upto(C)));
409 .setStringValue(Range.upto(C).drop_front(1));
414 ErrorCallbackType ErrorCallback) {
415 if (C.peek() !=
'%' && C.peek() !=
'$')
418 if (C.peek() ==
'%') {
419 if (isdigit(C.peek(1)))
434 .setStringValue(Range.upto(C).drop_front(1));
439 ErrorCallbackType ErrorCallback) {
442 if (!isdigit(C.peek(1)))
447 auto NumberRange =
C;
448 while (isdigit(C.peek()))
451 .setIntegerValue(
APSInt(NumberRange.upto(C)));
456 ErrorCallbackType ErrorCallback) {
464 return C ==
'H' || C ==
'K' || C ==
'L' || C ==
'M';
470 while (isdigit(C.peek()))
472 if ((C.peek() ==
'e' || C.peek() ==
'E') &&
473 (isdigit(C.peek(1)) ||
474 ((C.peek(1) ==
'-' || C.peek(1) ==
'+') && isdigit(C.peek(2))))) {
476 while (isdigit(C.peek()))
484 if (C.peek() !=
'0' || (C.peek(1) !=
'x' && C.peek(1) !=
'X'))
488 unsigned PrefLen = 2;
493 while (isxdigit(C.peek()))
496 if (StrVal.
size() <= PrefLen)
506 if (!isdigit(C.peek()) && (C.peek() !=
'-' || !isdigit(C.peek(1))))
510 while (isdigit(C.peek()))
530 ErrorCallbackType ErrorCallback) {
545 "use of unknown metadata keyword '" + StrVal +
"'");
583 if (C.peek() ==
':' && C.peek(1) ==
':') {
592 Token.
reset(Kind, Range.upto(C));
606 ErrorCallbackType ErrorCallback) {
612 while (C.peek() !=
'`') {
616 "end of machine instruction reached before the closing '`'");
629 ErrorCallbackType ErrorCallback) {
633 return C.remaining();
637 return R.remaining();
639 return R.remaining();
641 return R.remaining();
643 return R.remaining();
645 return R.remaining();
647 return R.remaining();
649 return R.remaining();
651 return R.remaining();
653 return R.remaining();
655 return R.remaining();
657 return R.remaining();
659 return R.remaining();
661 return R.remaining();
663 return R.remaining();
665 return R.remaining();
667 return R.remaining();
669 return R.remaining();
671 return R.remaining();
673 return R.remaining();
676 ErrorCallback(
C.location(),
677 Twine(
"unexpected character '") +
Twine(
C.peek()) +
"'");
678 return C.remaining();
static Cursor maybeLexStringConstant(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexIRBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static MIToken::TokenKind getMetadataKeywordKind(StringRef Identifier)
Compute iterated dominance frontiers using a linear time algorithm.
static bool isRegisterChar(char C)
Returns true for a character allowed in a register name.
static Cursor lexNamedVirtualRegister(Cursor C, MIToken &Token)
NoneType
A simple null object to allow implicit construction of Optional<T> and similar types without having t...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static Cursor lexName(Cursor C, MIToken &Token, MIToken::TokenKind Type, unsigned PrefixLength, ErrorCallbackType ErrorCallback)
static Cursor lexStringConstant(Cursor C, ErrorCallbackType ErrorCallback)
Lex a string constant using the following regular expression: "[^"]*".
An efficient, type-erasing, non-owning reference to a callable.
static Cursor maybeLexEscapedIRValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
StringRef lexMIToken(StringRef Source, MIToken &Token, function_ref< void(StringRef::iterator, const Twine &)> ErrorCallback)
Consume a single machine instruction token in the given source and return the remaining source string...
MIToken & reset(TokenKind Kind, StringRef Range)
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).
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static bool isNewlineChar(char C)
static bool isValidHexFloatingPointPrefix(char C)
static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
static Cursor maybeLexMachineBasicBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor lexFloatingPointLiteral(Cursor Range, Cursor C, MIToken &Token)
static Cursor skipWhitespace(Cursor C)
Skip the leading whitespace characters and return the updated cursor.
static Cursor maybeLexIdentifier(Cursor C, MIToken &Token)
static Cursor maybeLexGlobalValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
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).
static Cursor maybeLexExternalSymbol(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
A switch()-like statement whose cases are string literals.
The instances of the Type class are immutable: once they are created, they are never changed...
static Cursor maybeLexNewline(Cursor C, MIToken &Token)
static Cursor maybeLexStackObject(Cursor C, MIToken &Token)
static Cursor lexVirtualRegister(Cursor C, MIToken &Token)
static MIToken::TokenKind symbolToken(char C)
MIToken & setOwnedStringValue(std::string StrVal)
LLVM_NODISCARD char back() const
back - Get the last character in the string.
static Cursor maybeLexFixedStackObject(Cursor C, MIToken &Token)
static Cursor skipComment(Cursor C)
Skip a line comment and return the updated cursor.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
MIToken & setStringValue(StringRef StrVal)
static Cursor maybeLexSymbol(Cursor C, MIToken &Token)
StringRef::iterator location() const
static Cursor maybeLexIndexAndName(Cursor C, MIToken &Token, StringRef Rule, MIToken::TokenKind Kind)
static Cursor maybeLexHexadecimalLiteral(Cursor C, MIToken &Token)
static Cursor maybeLexJumpTableIndex(Cursor C, MIToken &Token)
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token)
static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule, MIToken::TokenKind Kind)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM_NODISCARD char front() const
front - Get the first character in the string.
static Cursor maybeLexExlaim(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
LLVM Value Representation.
A token produced by the machine instruction lexer.
static Cursor maybeLexRegister(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexIRValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
StringRef - Represent a constant reference to a string, i.e.
MIToken & setIntegerValue(APSInt IntVal)
static MIToken::TokenKind getIdentifierKind(StringRef Identifier)
static bool isIdentifierChar(char C)
Return true if the given character satisfies the following regular expression: [-a-zA-Z$._0-9].
static Cursor maybeLexSubRegisterIndex(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
LocationClass< Ty > location(Ty &L)
static std::string unescapeQuotedString(StringRef Value)
Unescapes the given string value.