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));
259 if (!isalpha(C.peek()) && C.peek() !=
'_')
264 auto Identifier = Range.upto(C);
271 ErrorCallbackType ErrorCallback) {
272 bool IsReference = C.remaining().startswith(
"%bb.");
273 if (!IsReference && !C.remaining().startswith(
"bb."))
276 unsigned PrefixLength = IsReference ? 4 : 3;
277 C.advance(PrefixLength);
278 if (!isdigit(C.peek())) {
280 ErrorCallback(C.location(),
"expected a number after '%bb.'");
283 auto NumberRange =
C;
284 while (isdigit(C.peek()))
287 unsigned StringOffset = PrefixLength + Number.
size();
291 if (C.peek() ==
'.') {
300 .setIntegerValue(
APSInt(Number))
301 .setStringValue(Range.upto(C).drop_front(StringOffset));
307 if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.
size())))
310 C.advance(Rule.
size());
311 auto NumberRange =
C;
312 while (isdigit(C.peek()))
314 Token.
reset(Kind, Range.upto(C)).setIntegerValue(
APSInt(NumberRange.upto(C)));
320 if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.
size())))
323 C.advance(Rule.
size());
324 auto NumberRange =
C;
325 while (isdigit(C.peek()))
328 unsigned StringOffset = Rule.
size() + Number.
size();
329 if (C.peek() ==
'.') {
335 Token.
reset(Kind, Range.upto(C))
336 .setIntegerValue(
APSInt(Number))
337 .setStringValue(Range.upto(C).drop_front(StringOffset));
358 ErrorCallbackType ErrorCallback) {
360 if (!C.remaining().startswith(Rule))
367 ErrorCallbackType ErrorCallback) {
369 if (!C.remaining().startswith(Rule))
371 if (isdigit(C.peek(Rule.
size())))
377 ErrorCallbackType ErrorCallback) {
379 if (!C.remaining().startswith(Rule))
381 if (isdigit(C.peek(Rule.
size())))
387 ErrorCallbackType ErrorCallback) {
397 auto NumberRange =
C;
398 while (isdigit(C.peek()))
401 .setIntegerValue(
APSInt(NumberRange.upto(C)));
416 .setStringValue(Range.upto(C).drop_front(1));
421 ErrorCallbackType ErrorCallback) {
422 if (C.peek() !=
'%' && C.peek() !=
'$')
425 if (C.peek() ==
'%') {
426 if (isdigit(C.peek(1)))
441 .setStringValue(Range.upto(C).drop_front(1));
446 ErrorCallbackType ErrorCallback) {
449 if (!isdigit(C.peek(1)))
454 auto NumberRange =
C;
455 while (isdigit(C.peek()))
458 .setIntegerValue(
APSInt(NumberRange.upto(C)));
463 ErrorCallbackType ErrorCallback) {
471 ErrorCallbackType ErrorCallback) {
473 if (!C.remaining().startswith(Rule))
476 C.advance(Rule.
size());
479 if (C.peek() !=
'"') {
483 if (C.peek() !=
'>') {
484 ErrorCallback(C.location(),
485 "expected the '<mcsymbol ...' to be closed by a '>'");
498 ErrorCallback(C.location(),
499 "unable to parse quoted string from opening quote");
504 if (R.peek() !=
'>') {
505 ErrorCallback(R.location(),
506 "expected the '<mcsymbol ...' to be closed by a '>'");
518 return C ==
'H' || C ==
'K' || C ==
'L' || C ==
'M';
524 while (isdigit(C.peek()))
526 if ((C.peek() ==
'e' || C.peek() ==
'E') &&
527 (isdigit(C.peek(1)) ||
528 ((C.peek(1) ==
'-' || C.peek(1) ==
'+') && isdigit(C.peek(2))))) {
530 while (isdigit(C.peek()))
538 if (C.peek() !=
'0' || (C.peek(1) !=
'x' && C.peek(1) !=
'X'))
542 unsigned PrefLen = 2;
547 while (isxdigit(C.peek()))
550 if (StrVal.
size() <= PrefLen)
560 if (!isdigit(C.peek()) && (C.peek() !=
'-' || !isdigit(C.peek(1))))
564 while (isdigit(C.peek()))
585 ErrorCallbackType ErrorCallback) {
600 "use of unknown metadata keyword '" + StrVal +
"'");
638 if (C.peek() ==
':' && C.peek(1) ==
':') {
647 Token.
reset(Kind, Range.upto(C));
661 ErrorCallbackType ErrorCallback) {
667 while (C.peek() !=
'`') {
671 "end of machine instruction reached before the closing '`'");
684 ErrorCallbackType ErrorCallback) {
688 return C.remaining();
692 return R.remaining();
694 return R.remaining();
696 return R.remaining();
698 return R.remaining();
700 return R.remaining();
702 return R.remaining();
704 return R.remaining();
706 return R.remaining();
708 return R.remaining();
710 return R.remaining();
712 return R.remaining();
714 return R.remaining();
716 return R.remaining();
718 return R.remaining();
720 return R.remaining();
722 return R.remaining();
724 return R.remaining();
726 return R.remaining();
728 return R.remaining();
730 return R.remaining();
733 ErrorCallback(
C.location(),
734 Twine(
"unexpected character '") +
Twine(
C.peek()) +
"'");
735 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)
This class represents lattice values for constants.
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)
static Cursor maybeLexMCSymbol(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.