36 const char *Ptr =
nullptr;
37 const char *End =
nullptr;
44 End = Ptr + Str.
size();
47 bool isEOF()
const {
return Ptr == End; }
49 char peek(
int I = 0)
const {
return End - Ptr <=
I ? 0 : Ptr[
I]; }
51 void advance(
unsigned I = 1) { Ptr +=
I; }
56 assert(C.Ptr >= Ptr && C.Ptr <= End);
62 operator bool()
const {
return Ptr !=
nullptr; }
79 StringValueStorage = std::move(StrVal);
80 StringValue = StringValueStorage;
85 this->IntVal = std::move(IntVal);
91 while (isblank(C.peek()))
110 return isalpha(C) || isdigit(C) || C ==
'_' || C ==
'-' || C ==
'.' ||
119 Cursor
C = Cursor(Value.
substr(1, Value.
size() - 2));
122 Str.reserve(C.remaining().size());
124 char Char = C.peek();
126 if (C.peek(1) ==
'\\') {
132 if (isxdigit(C.peek(1)) && isxdigit(C.peek(2))) {
147 for (C.advance(); C.peek() !=
'"'; C.advance()) {
151 "end of machine instruction reached before the closing '\"'");
162 C.advance(PrefixLength);
163 if (C.peek() ==
'"') {
166 Token.
reset(Type, String)
176 Token.
reset(Type, Range.upto(C))
177 .setStringValue(Range.upto(C).drop_front(PrefixLength));
262 if (!isalpha(C.peek()) && C.peek() !=
'_')
267 auto Identifier = Range.upto(C);
275 bool IsReference = C.remaining().startswith(
"%bb.");
276 if (!IsReference && !C.remaining().startswith(
"bb."))
279 unsigned PrefixLength = IsReference ? 4 : 3;
280 C.advance(PrefixLength);
281 if (!isdigit(C.peek())) {
283 ErrorCallback(C.location(),
"expected a number after '%bb.'");
286 auto NumberRange =
C;
287 while (isdigit(C.peek()))
290 unsigned StringOffset = PrefixLength + Number.
size();
294 if (C.peek() ==
'.') {
303 .setIntegerValue(
APSInt(Number))
304 .setStringValue(Range.upto(C).drop_front(StringOffset));
310 if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.
size())))
313 C.advance(Rule.
size());
314 auto NumberRange =
C;
315 while (isdigit(C.peek()))
317 Token.
reset(Kind, Range.upto(C)).setIntegerValue(
APSInt(NumberRange.upto(C)));
323 if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.
size())))
326 C.advance(Rule.
size());
327 auto NumberRange =
C;
328 while (isdigit(C.peek()))
331 unsigned StringOffset = Rule.
size() + Number.
size();
332 if (C.peek() ==
'.') {
338 Token.
reset(Kind, Range.upto(C))
339 .setIntegerValue(
APSInt(Number))
340 .setStringValue(Range.upto(C).drop_front(StringOffset));
363 if (!C.remaining().startswith(Rule))
372 if (!C.remaining().startswith(Rule))
374 if (isdigit(C.peek(Rule.
size())))
382 if (!C.remaining().startswith(Rule))
384 if (isdigit(C.peek(Rule.
size())))
400 auto NumberRange =
C;
401 while (isdigit(C.peek()))
404 .setIntegerValue(
APSInt(NumberRange.upto(C)));
419 .setStringValue(Range.upto(C).drop_front(1));
425 if (C.peek() !=
'%' && C.peek() !=
'$')
428 if (C.peek() ==
'%') {
429 if (isdigit(C.peek(1)))
444 .setStringValue(Range.upto(C).drop_front(1));
452 if (!isdigit(C.peek(1)))
457 auto NumberRange =
C;
458 while (isdigit(C.peek()))
461 .setIntegerValue(
APSInt(NumberRange.upto(C)));
476 if (!C.remaining().startswith(Rule))
479 C.advance(Rule.
size());
482 if (C.peek() !=
'"') {
486 if (C.peek() !=
'>') {
487 ErrorCallback(C.location(),
488 "expected the '<mcsymbol ...' to be closed by a '>'");
501 ErrorCallback(C.location(),
502 "unable to parse quoted string from opening quote");
507 if (R.peek() !=
'>') {
508 ErrorCallback(R.location(),
509 "expected the '<mcsymbol ...' to be closed by a '>'");
521 return C ==
'H' || C ==
'K' || C ==
'L' || C ==
'M';
527 while (isdigit(C.peek()))
529 if ((C.peek() ==
'e' || C.peek() ==
'E') &&
530 (isdigit(C.peek(1)) ||
531 ((C.peek(1) ==
'-' || C.peek(1) ==
'+') && isdigit(C.peek(2))))) {
533 while (isdigit(C.peek()))
541 if (C.peek() !=
'0' || (C.peek(1) !=
'x' && C.peek(1) !=
'X'))
545 unsigned PrefLen = 2;
550 while (isxdigit(C.peek()))
553 if (StrVal.
size() <= PrefLen)
563 if (!isdigit(C.peek()) && (C.peek() !=
'-' || !isdigit(C.peek(1))))
567 while (isdigit(C.peek()))
603 "use of unknown metadata keyword '" + StrVal +
"'");
641 if (C.peek() ==
':' && C.peek(1) ==
':') {
650 Token.
reset(Kind, Range.upto(C));
670 while (C.peek() !=
'`') {
674 "end of machine instruction reached before the closing '`'");
691 return C.remaining();
695 return R.remaining();
697 return R.remaining();
699 return R.remaining();
701 return R.remaining();
703 return R.remaining();
705 return R.remaining();
707 return R.remaining();
709 return R.remaining();
711 return R.remaining();
713 return R.remaining();
715 return R.remaining();
717 return R.remaining();
719 return R.remaining();
721 return R.remaining();
723 return R.remaining();
725 return R.remaining();
727 return R.remaining();
729 return R.remaining();
731 return R.remaining();
733 return R.remaining();
736 ErrorCallback(
C.location(),
737 Twine(
"unexpected character '") +
Twine(
C.peek()) +
"'");
738 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...
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)
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static bool isNewlineChar(char C)
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
LLVM_NODISCARD R Default(T Value)
static bool isValidHexFloatingPointPrefix(char C)
static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token)
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
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 maybeLexExclaim(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
LLVM_NODISCARD size_t size() const
size - Get the string size.
static Cursor maybeLexMCSymbol(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
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.
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.
static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token)
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
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 bool peek(struct InternalInstruction *insn, uint8_t &byte)
static std::string unescapeQuotedString(StringRef Value)
Unescapes the given string value.