Go to the documentation of this file.
32 const char *Ptr =
nullptr;
33 const char *End =
nullptr;
40 End = Ptr + Str.size();
43 bool isEOF()
const {
return Ptr == End; }
45 char peek(
int I = 0)
const {
return End - Ptr <=
I ? 0 : Ptr[
I]; }
47 void advance(
unsigned I = 1) { Ptr +=
I; }
52 assert(
C.Ptr >= Ptr &&
C.Ptr <= End);
58 operator bool()
const {
return Ptr !=
nullptr; }
76 StringValue = StringValueStorage;
87 while (isblank(
C.peek()))
106 if (
C.peek() !=
'/' ||
C.peek(1) !=
'*')
109 while (
C.peek() !=
'*' ||
C.peek(1) !=
'/')
120 return isalpha(
C) || isdigit(
C) ||
C ==
'_' ||
C ==
'-' ||
C ==
'.' ||
129 Cursor
C = Cursor(
Value.substr(1,
Value.size() - 2));
132 Str.reserve(
C.remaining().size());
134 char Char =
C.peek();
136 if (
C.peek(1) ==
'\\') {
142 if (isxdigit(
C.peek(1)) && isxdigit(
C.peek(2))) {
143 Str += hexDigitValue(
C.peek(1)) * 16 + hexDigitValue(
C.peek(2));
157 for (
C.advance();
C.peek() !=
'"';
C.advance()) {
161 "end of machine instruction reached before the closing '\"'");
172 C.advance(PrefixLength);
173 if (
C.peek() ==
'"') {
235 .
Case(
"negate_ra_sign_state",
263 .
Case(
"inlineasm-br-indirect-target",
282 if (!isalpha(
C.peek()) &&
C.peek() !=
'_')
287 auto Identifier = Range.upto(
C);
295 bool IsReference =
C.remaining().startswith(
"%bb.");
296 if (!IsReference && !
C.remaining().startswith(
"bb."))
299 unsigned PrefixLength = IsReference ? 4 : 3;
300 C.advance(PrefixLength);
301 if (!isdigit(
C.peek())) {
303 ErrorCallback(
C.location(),
"expected a number after '%bb.'");
306 auto NumberRange =
C;
307 while (isdigit(
C.peek()))
310 unsigned StringOffset = PrefixLength +
Number.size();
314 if (
C.peek() ==
'.') {
330 if (!
C.remaining().startswith(Rule) || !isdigit(
C.peek(Rule.
size())))
333 C.advance(Rule.
size());
334 auto NumberRange =
C;
335 while (isdigit(
C.peek()))
343 if (!
C.remaining().startswith(Rule) || !isdigit(
C.peek(Rule.
size())))
346 C.advance(Rule.
size());
347 auto NumberRange =
C;
348 while (isdigit(
C.peek()))
351 unsigned StringOffset = Rule.
size() +
Number.size();
352 if (
C.peek() ==
'.') {
383 if (!
C.remaining().startswith(Rule))
392 if (!
C.remaining().startswith(Rule))
394 if (isdigit(
C.peek(Rule.
size())))
402 if (!
C.remaining().startswith(Rule))
404 if (isdigit(
C.peek(Rule.
size())))
420 auto NumberRange =
C;
421 while (isdigit(
C.peek()))
445 if (
C.peek() !=
'%' &&
C.peek() !=
'$')
448 if (
C.peek() ==
'%') {
449 if (isdigit(
C.peek(1)))
472 if (!isdigit(
C.peek(1)))
477 auto NumberRange =
C;
478 while (isdigit(
C.peek()))
496 if (!
C.remaining().startswith(Rule))
499 C.advance(Rule.
size());
502 if (
C.peek() !=
'"') {
506 if (
C.peek() !=
'>') {
507 ErrorCallback(
C.location(),
508 "expected the '<mcsymbol ...' to be closed by a '>'");
521 ErrorCallback(
C.location(),
522 "unable to parse quoted string from opening quote");
527 if (R.peek() !=
'>') {
528 ErrorCallback(R.location(),
529 "expected the '<mcsymbol ...' to be closed by a '>'");
541 return C ==
'H' ||
C ==
'K' ||
C ==
'L' ||
C ==
'M' ||
C ==
'R';
547 while (isdigit(
C.peek()))
549 if ((
C.peek() ==
'e' ||
C.peek() ==
'E') &&
550 (isdigit(
C.peek(1)) ||
551 ((
C.peek(1) ==
'-' ||
C.peek(1) ==
'+') && isdigit(
C.peek(2))))) {
553 while (isdigit(
C.peek()))
561 if (
C.peek() !=
'0' || (
C.peek(1) !=
'x' &&
C.peek(1) !=
'X'))
565 unsigned PrefLen = 2;
570 while (isxdigit(
C.peek()))
573 if (
StrVal.size() <= PrefLen)
583 if (!isdigit(
C.peek()) && (
C.peek() !=
'-' || !isdigit(
C.peek(1))))
587 while (isdigit(
C.peek()))
623 "use of unknown metadata keyword '" +
StrVal +
"'");
661 if (
C.peek() ==
':' &&
C.peek(1) ==
':') {
690 while (
C.peek() !=
'`') {
694 "end of machine instruction reached before the closing '`'");
711 return C.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();
735 return R.remaining();
737 return R.remaining();
739 return R.remaining();
741 return R.remaining();
743 return R.remaining();
745 return R.remaining();
747 return R.remaining();
749 return R.remaining();
751 return R.remaining();
753 return R.remaining();
755 return R.remaining();
758 ErrorCallback(
C.location(),
759 Twine(
"unexpected character '") +
Twine(
C.peek()) +
"'");
760 return C.remaining();
StringSwitch & Case(StringLiteral S, T Value)
static Cursor maybeLexGlobalValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor lexNamedVirtualRegister(Cursor C, MIToken &Token)
This is an optimization pass for GlobalISel generic memory operations.
static Cursor maybeLexExclaim(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor lexName(Cursor C, MIToken &Token, MIToken::TokenKind Type, unsigned PrefixLength, ErrorCallbackType ErrorCallback)
static Cursor maybeLexJumpTableIndex(Cursor C, MIToken &Token)
static Cursor maybeLexFixedStackObject(Cursor C, MIToken &Token)
LocationClass< Ty > location(Ty &L)
LLVM_NODISCARD R Default(T Value)
static Cursor skipWhitespace(Cursor C)
Skip the leading whitespace characters and return the updated cursor.
static bool isNewlineChar(char C)
static Cursor lexFloatingPointLiteral(Cursor Range, Cursor C, MIToken &Token)
static MIToken::TokenKind getIdentifierKind(StringRef Identifier)
The instances of the Type class are immutable: once they are created, they are never changed.
@ kw_inlineasm_br_indirect_target
static Cursor maybeLexRegister(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
A token produced by the machine instruction lexer.
static bool peek(struct InternalInstruction *insn, uint8_t &byte)
@ kw_cfi_def_cfa_register
static Cursor maybeLexMachineBasicBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
@ kw_cfi_llvm_def_aspace_cfa
static Cursor skipMachineOperandComment(Cursor C)
Machine operands can have comments, enclosed between /* and /.
(vector float) vec_cmpeq(*A, *B) C
static MIToken::TokenKind symbolToken(char C)
static Cursor maybeLexIRValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
An arbitrary precision integer that knows its signedness.
MIToken & setStringValue(StringRef StrVal)
An efficient, type-erasing, non-owning reference to a callable.
static Cursor maybeLexSubRegisterIndex(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
@ kw_cfi_adjust_cfa_offset
static Cursor maybeLexStringConstant(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
NoneType
A simple null object to allow implicit construction of Optional<T> and similar types without having t...
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token)
static Cursor maybeLexEscapedIRValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static bool isRegisterChar(char C)
Returns true for a character allowed in a register name.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Cursor lexVirtualRegister(Cursor C, MIToken &Token)
StringRef - Represent a constant reference to a string, i.e.
static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule, MIToken::TokenKind Kind)
@ kw_cfi_aarch64_negate_ra_sign_state
static std::string unescapeQuotedString(StringRef Value)
Unescapes the given string value.
static Cursor maybeLexMCSymbol(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexIndexAndName(Cursor C, MIToken &Token, StringRef Rule, MIToken::TokenKind Kind)
static Cursor skipComment(Cursor C)
Skip a line comment and return the updated cursor.
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
MIToken & setIntegerValue(APSInt IntVal)
static bool isValidHexFloatingPointPrefix(char C)
static MIToken::TokenKind getMetadataKeywordKind(StringRef Identifier)
static Cursor maybeLexSymbol(Cursor C, MIToken &Token)
static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token)
static Cursor maybeLexHexadecimalLiteral(Cursor C, MIToken &Token)
StringRef::iterator location() const
static Cursor maybeLexIRBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexIdentifier(Cursor C, MIToken &Token)
static Cursor maybeLexNewline(Cursor C, MIToken &Token)
static Cursor maybeLexStackObject(Cursor C, MIToken &Token)
A switch()-like statement whose cases are string literals.
static bool isIdentifierChar(char C)
Return true if the given character satisfies the following regular expression: [-a-zA-Z$....
MIToken & reset(TokenKind Kind, StringRef Range)
MIToken & setOwnedStringValue(std::string StrVal)
static Cursor lexStringConstant(Cursor C, ErrorCallbackType ErrorCallback)
Lex a string constant using the following regular expression: "[^"]*".
static Cursor maybeLexExternalSymbol(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...
LLVM Value Representation.