31 const char *Ptr =
nullptr;
32 const char *End =
nullptr;
35 Cursor(std::nullopt_t) {}
37 explicit Cursor(StringRef Str) {
39 End = Ptr + Str.size();
42 bool isEOF()
const {
return Ptr == End; }
44 char peek(
int I = 0)
const {
return End - Ptr <=
I ? 0 : Ptr[
I]; }
46 void advance(
unsigned I = 1) { Ptr +=
I; }
48 StringRef remaining()
const {
return StringRef(Ptr, End - Ptr); }
50 StringRef upto(Cursor
C)
const {
51 assert(
C.Ptr >= Ptr &&
C.Ptr <= End);
52 return StringRef(Ptr,
C.Ptr - Ptr);
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 if (
C.peek() !=
'/' ||
C.peek(1) !=
'*')
108 while (
C.peek() !=
'*' ||
C.peek(1) !=
'/')
119 return isalpha(
C) || isdigit(
C) ||
C ==
'_' ||
C ==
'-' ||
C ==
'.' ||
128 Cursor
C = Cursor(
Value.substr(1,
Value.size() - 2));
131 Str.reserve(
C.remaining().size());
133 char Char =
C.peek();
135 if (
C.peek(1) ==
'\\') {
141 if (isxdigit(
C.peek(1)) && isxdigit(
C.peek(2))) {
156 for (
C.advance();
C.peek() !=
'"';
C.advance()) {
160 "end of machine instruction reached before the closing '\"'");
171 C.advance(PrefixLength);
172 if (
C.peek() ==
'"') {
241 .
Case(
"negate_ra_sign_state",
243 .
Case(
"negate_ra_sign_state_with_pc",
271 .
Case(
"inlineasm-br-indirect-target",
291 .
Case(
"machine-block-address-taken",
299 if (!isalpha(
C.peek()) &&
C.peek() !=
'_')
304 auto Identifier =
Range.upto(
C);
312 bool IsReference =
C.remaining().starts_with(
"%bb.");
313 if (!IsReference && !
C.remaining().starts_with(
"bb."))
316 unsigned PrefixLength = IsReference ? 4 : 3;
317 C.advance(PrefixLength);
318 if (!isdigit(
C.peek())) {
320 ErrorCallback(
C.location(),
"expected a number after '%bb.'");
323 auto NumberRange =
C;
324 while (isdigit(
C.peek()))
327 unsigned StringOffset = PrefixLength +
Number.size();
331 if (
C.peek() ==
'.') {
347 if (!
C.remaining().starts_with(Rule) || !isdigit(
C.peek(Rule.
size())))
350 C.advance(Rule.
size());
351 auto NumberRange =
C;
352 while (isdigit(
C.peek()))
360 if (!
C.remaining().starts_with(Rule) || !isdigit(
C.peek(Rule.
size())))
363 C.advance(Rule.
size());
364 auto NumberRange =
C;
365 while (isdigit(
C.peek()))
368 unsigned StringOffset = Rule.
size() +
Number.size();
369 if (
C.peek() ==
'.') {
400 if (!
C.remaining().starts_with(Rule))
409 if (!
C.remaining().starts_with(Rule))
411 if (isdigit(
C.peek(Rule.
size())))
419 if (!
C.remaining().starts_with(Rule))
421 if (isdigit(
C.peek(Rule.
size())))
437 auto NumberRange =
C;
438 while (isdigit(
C.peek()))
462 if (
C.peek() !=
'%' &&
C.peek() !=
'$')
465 if (
C.peek() ==
'%') {
466 if (isdigit(
C.peek(1)))
489 if (!isdigit(
C.peek(1)))
494 auto NumberRange =
C;
495 while (isdigit(
C.peek()))
513 if (!
C.remaining().starts_with(Rule))
516 C.advance(Rule.
size());
519 if (
C.peek() !=
'"') {
523 if (
C.peek() !=
'>') {
524 ErrorCallback(
C.location(),
525 "expected the '<mcsymbol ...' to be closed by a '>'");
538 ErrorCallback(
C.location(),
539 "unable to parse quoted string from opening quote");
544 if (R.peek() !=
'>') {
545 ErrorCallback(R.location(),
546 "expected the '<mcsymbol ...' to be closed by a '>'");
558 return C ==
'H' ||
C ==
'K' ||
C ==
'L' ||
C ==
'M' ||
C ==
'R';
564 while (isdigit(
C.peek()))
566 if ((
C.peek() ==
'e' ||
C.peek() ==
'E') &&
567 (isdigit(
C.peek(1)) ||
568 ((
C.peek(1) ==
'-' ||
C.peek(1) ==
'+') && isdigit(
C.peek(2))))) {
570 while (isdigit(
C.peek()))
578 if (
C.peek() !=
'0' || (
C.peek(1) !=
'x' &&
C.peek(1) !=
'X'))
582 unsigned PrefLen = 2;
587 while (isxdigit(
C.peek()))
590 if (StrVal.size() <= PrefLen)
600 if (!isdigit(
C.peek()) && (
C.peek() !=
'-' || !isdigit(
C.peek(1))))
604 while (isdigit(
C.peek()))
641 "use of unknown metadata keyword '" + StrVal +
"'");
679 if (
C.peek() ==
':' &&
C.peek(1) ==
':') {
708 while (
C.peek() !=
'`') {
712 "end of machine instruction reached before the closing '`'");
729 return C.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();
757 return R.remaining();
759 return R.remaining();
761 return R.remaining();
763 return R.remaining();
765 return R.remaining();
767 return R.remaining();
769 return R.remaining();
771 return R.remaining();
773 return R.remaining();
776 ErrorCallback(
C.location(),
777 Twine(
"unexpected character '") +
Twine(
C.peek()) +
"'");
778 return C.remaining();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Cursor maybeLexEscapedIRValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor skipComment(Cursor C)
Skip a line comment and return the updated cursor.
static bool isRegisterChar(char C)
Returns true for a character allowed in a register name.
static Cursor lexStringConstant(Cursor C, ErrorCallbackType ErrorCallback)
Lex a string constant using the following regular expression: "[^"]*".
static bool isNewlineChar(char C)
static MIToken::TokenKind symbolToken(char C)
static bool isValidHexFloatingPointPrefix(char C)
static MIToken::TokenKind getIdentifierKind(StringRef Identifier)
static Cursor maybeLexIRBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexSymbol(Cursor C, MIToken &Token)
static Cursor maybeLexJumpTableIndex(Cursor C, MIToken &Token)
static Cursor maybeLexRegister(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexHexadecimalLiteral(Cursor C, MIToken &Token)
static Cursor lexVirtualRegister(Cursor C, MIToken &Token)
static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token)
static Cursor maybeLexExclaim(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor lexNamedVirtualRegister(Cursor C, MIToken &Token)
static std::string unescapeQuotedString(StringRef Value)
Unescapes the given string value.
static Cursor maybeLexIndexAndName(Cursor C, MIToken &Token, StringRef Rule, MIToken::TokenKind Kind)
static Cursor maybeLexNewline(Cursor C, MIToken &Token)
static Cursor maybeLexMCSymbol(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor skipMachineOperandComment(Cursor C)
Machine operands can have comments, enclosed between /* and /.
static MIToken::TokenKind getMetadataKeywordKind(StringRef Identifier)
static Cursor maybeLexIdentifier(Cursor C, MIToken &Token)
static Cursor maybeLexStackObject(Cursor C, MIToken &Token)
static Cursor skipWhitespace(Cursor C)
Skip the leading whitespace characters and return the updated cursor.
static Cursor maybeLexExternalSymbol(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static bool isIdentifierChar(char C)
Return true if the given character satisfies the following regular expression: [-a-zA-Z$....
static Cursor lexName(Cursor C, MIToken &Token, MIToken::TokenKind Type, unsigned PrefixLength, ErrorCallbackType ErrorCallback)
static Cursor maybeLexGlobalValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexIRValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexFixedStackObject(Cursor C, MIToken &Token)
static Cursor maybeLexMachineBasicBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexStringConstant(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor maybeLexSubRegisterIndex(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
static Cursor lexFloatingPointLiteral(Cursor Range, Cursor C, MIToken &Token)
static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token)
static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule, MIToken::TokenKind Kind)
function_ref< bool(StringRef::iterator Loc, const Twine &)> ErrorCallbackType
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static bool peek(struct InternalInstruction *insn, uint8_t &byte)
An arbitrary precision integer that knows its signedness.
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
@ C
The default llvm calling convention, compatible with C.
LocationClass< Ty > location(Ty &L)
This is an optimization pass for GlobalISel generic memory operations.
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
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...
A token produced by the machine instruction lexer.
MIToken & setStringValue(StringRef StrVal)
@ kw_cfi_aarch64_negate_ra_sign_state
@ kw_cfi_llvm_def_aspace_cfa
@ kw_inlineasm_br_indirect_target
@ kw_cfi_aarch64_negate_ra_sign_state_with_pc
@ kw_cfi_def_cfa_register
@ kw_cfi_adjust_cfa_offset
@ kw_machine_block_address_taken
@ kw_ir_block_address_taken
MIToken & setIntegerValue(APSInt IntVal)
MIToken & reset(TokenKind Kind, StringRef Range)
MIToken & setOwnedStringValue(std::string StrVal)
StringRef::iterator location() const