42 bool isEOF()
const {
return Ptr ==
End; }
44 char peek(
int I = 0)
const {
return End -
Ptr <=
I ? 0 : Ptr[
I]; }
57 operator bool()
const {
return Ptr !=
nullptr; }
74 StringValueStorage = std::move(StrVal);
75 StringValue = StringValueStorage;
80 this->IntVal = std::move(IntVal);
86 while (isblank(C.peek()))
105 return isalpha(C) || isdigit(C) || C ==
'_' || C ==
'-' || C ==
'.' ||
114 Cursor
C = Cursor(Value.
substr(1, Value.
size() - 2));
117 Str.reserve(C.remaining().size());
119 char Char = C.peek();
121 if (C.peek(1) ==
'\\') {
127 if (isxdigit(C.peek(1)) && isxdigit(C.peek(2))) {
142 for (C.advance(); C.peek() !=
'"'; C.advance()) {
146 "end of machine instruction reached before the closing '\"'");
155 unsigned PrefixLength, ErrorCallbackType ErrorCallback) {
157 C.advance(PrefixLength);
158 if (C.peek() ==
'"') {
161 Token.
reset(Type, String)
171 Token.
reset(Type, Range.upto(C))
172 .setStringValue(Range.upto(C).drop_front(PrefixLength));
177 if ((C.peek() !=
'i' && C.peek() !=
's' && C.peek() !=
'p') ||
180 char Kind = C.peek();
183 while (isdigit(C.peek()))
186 Token.
reset(Kind ==
'i'
244 if (!isalpha(C.peek()) && C.peek() !=
'_')
249 auto Identifier = Range.upto(C);
256 ErrorCallbackType ErrorCallback) {
257 bool IsReference = C.remaining().startswith(
"%bb.");
258 if (!IsReference && !C.remaining().startswith(
"bb."))
261 unsigned PrefixLength = IsReference ? 4 : 3;
262 C.advance(PrefixLength);
263 if (!isdigit(C.peek())) {
265 ErrorCallback(C.location(),
"expected a number after '%bb.'");
268 auto NumberRange =
C;
269 while (isdigit(C.peek()))
272 unsigned StringOffset = PrefixLength + Number.
size();
273 if (C.peek() ==
'.') {
282 .setIntegerValue(
APSInt(Number))
283 .setStringValue(Range.upto(C).drop_front(StringOffset));
289 if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.
size())))
292 C.advance(Rule.
size());
293 auto NumberRange =
C;
294 while (isdigit(C.peek()))
296 Token.
reset(Kind, Range.upto(C)).setIntegerValue(
APSInt(NumberRange.upto(C)));
302 if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.
size())))
305 C.advance(Rule.
size());
306 auto NumberRange =
C;
307 while (isdigit(C.peek()))
310 unsigned StringOffset = Rule.
size() + Number.
size();
311 if (C.peek() ==
'.') {
317 Token.
reset(Kind, Range.upto(C))
318 .setIntegerValue(
APSInt(Number))
319 .setStringValue(Range.upto(C).drop_front(StringOffset));
340 ErrorCallbackType ErrorCallback) {
342 if (!C.remaining().startswith(Rule))
349 ErrorCallbackType ErrorCallback) {
351 if (!C.remaining().startswith(Rule))
353 if (isdigit(C.peek(Rule.
size())))
359 ErrorCallbackType ErrorCallback) {
361 if (!C.remaining().startswith(Rule))
363 if (isdigit(C.peek(Rule.
size())))
371 auto NumberRange =
C;
372 while (isdigit(C.peek()))
375 .setIntegerValue(
APSInt(NumberRange.upto(C)));
387 if (isdigit(C.peek(1)))
394 .setStringValue(Range.upto(C).drop_front(1));
399 ErrorCallbackType ErrorCallback) {
402 if (!isdigit(C.peek(1)))
407 auto NumberRange =
C;
408 while (isdigit(C.peek()))
411 .setIntegerValue(
APSInt(NumberRange.upto(C)));
416 ErrorCallbackType ErrorCallback) {
424 return C ==
'H' || C ==
'K' || C ==
'L' || C ==
'M';
430 while (isdigit(C.peek()))
432 if ((C.peek() ==
'e' || C.peek() ==
'E') &&
433 (isdigit(C.peek(1)) ||
434 ((C.peek(1) ==
'-' || C.peek(1) ==
'+') && isdigit(C.peek(2))))) {
436 while (isdigit(C.peek()))
444 if (C.peek() !=
'0' || (C.peek(1) !=
'x' && C.peek(1) !=
'X'))
448 unsigned PrefLen = 2;
453 while (isxdigit(C.peek()))
456 if (StrVal.
size() <= PrefLen)
466 if (!isdigit(C.peek()) && (C.peek() !=
'-' || !isdigit(C.peek(1))))
470 while (isdigit(C.peek()))
489 ErrorCallbackType ErrorCallback) {
504 "use of unknown metadata keyword '" + StrVal +
"'");
542 if (C.peek() ==
':' && C.peek(1) ==
':') {
551 Token.
reset(Kind, Range.upto(C));
565 ErrorCallbackType ErrorCallback) {
571 while (C.peek() !=
'`') {
575 "end of machine instruction reached before the closing '`'");
588 ErrorCallbackType ErrorCallback) {
592 return C.remaining();
596 return R.remaining();
598 return R.remaining();
600 return R.remaining();
602 return R.remaining();
604 return R.remaining();
606 return R.remaining();
608 return R.remaining();
610 return R.remaining();
612 return R.remaining();
614 return R.remaining();
616 return R.remaining();
618 return R.remaining();
620 return R.remaining();
622 return R.remaining();
624 return R.remaining();
626 return R.remaining();
628 return R.remaining();
630 return R.remaining();
632 return R.remaining();
635 ErrorCallback(
C.location(),
636 Twine(
"unexpected character '") +
Twine(
C.peek()) +
"'");
637 return C.remaining();
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.
static Cursor maybeLexIRBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static MIToken::TokenKind getMetadataKeywordKind(StringRef Identifier)
static bool isRegisterChar(char C)
Returns true for a character allowed in a register name.
static Cursor maybeLexIntegerOrScalarType(Cursor C, MIToken &Token)
NoneType
A simple null object to allow implicit construction of Optional<T> and similar types without having to ...
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)
LLVM_NODISCARD char back() const
back - Get the last character in the string.
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)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static bool isNewlineChar(char C)
static void advance(T &it, size_t Val)
StringRef::iterator location() const
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
static bool isValidHexFloatingPointPrefix(char C)
static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token)
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)
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
static Cursor maybeLexGlobalValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
LLVM_NODISCARD char front() const
front - Get the first character in the string.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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...
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 maybeLexNewline(Cursor C, MIToken &Token)
static const unsigned End
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)
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)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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)
static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token)
static Cursor maybeLexRegister(Cursor C, MIToken &Token)
static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule, MIToken::TokenKind Kind)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Cursor maybeLexExlaim(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
LLVM Value Representation.
static unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
A token produced by the machine instruction lexer.
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 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.