1 //===- MILexer.cpp - Machine instructions lexer implementation ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the lexing of machine instructions.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/ADT/APSInt.h"
16 #include "llvm/ADT/None.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/Twine.h"
31 using ErrorCallbackType
=
32 function_ref
<void(StringRef::iterator Loc
, const Twine
&)>;
34 /// This class provides a way to iterate and get characters from the source
37 const char *Ptr
= nullptr;
38 const char *End
= nullptr;
43 explicit Cursor(StringRef Str
) {
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
; }
54 StringRef
remaining() const { return StringRef(Ptr
, End
- Ptr
); }
56 StringRef
upto(Cursor C
) const {
57 assert(C
.Ptr
>= Ptr
&& C
.Ptr
<= End
);
58 return StringRef(Ptr
, C
.Ptr
- Ptr
);
61 StringRef::iterator
location() const { return Ptr
; }
63 operator bool() const { return Ptr
!= nullptr; }
66 } // end anonymous namespace
68 MIToken
&MIToken::reset(TokenKind Kind
, StringRef Range
) {
74 MIToken
&MIToken::setStringValue(StringRef StrVal
) {
79 MIToken
&MIToken::setOwnedStringValue(std::string StrVal
) {
80 StringValueStorage
= std::move(StrVal
);
81 StringValue
= StringValueStorage
;
85 MIToken
&MIToken::setIntegerValue(APSInt IntVal
) {
86 this->IntVal
= std::move(IntVal
);
90 /// Skip the leading whitespace characters and return the updated cursor.
91 static Cursor
skipWhitespace(Cursor C
) {
92 while (isblank(C
.peek()))
97 static bool isNewlineChar(char C
) { return C
== '\n' || C
== '\r'; }
99 /// Skip a line comment and return the updated cursor.
100 static Cursor
skipComment(Cursor C
) {
103 while (!isNewlineChar(C
.peek()) && !C
.isEOF())
108 /// Return true if the given character satisfies the following regular
109 /// expression: [-a-zA-Z$._0-9]
110 static bool isIdentifierChar(char C
) {
111 return isalpha(C
) || isdigit(C
) || C
== '_' || C
== '-' || C
== '.' ||
115 /// Unescapes the given string value.
117 /// Expects the string value to be quoted.
118 static std::string
unescapeQuotedString(StringRef Value
) {
119 assert(Value
.front() == '"' && Value
.back() == '"');
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) == '\\') {
128 // Two '\' become one
133 if (isxdigit(C
.peek(1)) && isxdigit(C
.peek(2))) {
134 Str
+= hexDigitValue(C
.peek(1)) * 16 + hexDigitValue(C
.peek(2));
145 /// Lex a string constant using the following regular expression: \"[^\"]*\"
146 static Cursor
lexStringConstant(Cursor C
, ErrorCallbackType ErrorCallback
) {
147 assert(C
.peek() == '"');
148 for (C
.advance(); C
.peek() != '"'; C
.advance()) {
149 if (C
.isEOF() || isNewlineChar(C
.peek())) {
152 "end of machine instruction reached before the closing '\"'");
160 static Cursor
lexName(Cursor C
, MIToken
&Token
, MIToken::TokenKind Type
,
161 unsigned PrefixLength
, ErrorCallbackType ErrorCallback
) {
163 C
.advance(PrefixLength
);
164 if (C
.peek() == '"') {
165 if (Cursor R
= lexStringConstant(C
, ErrorCallback
)) {
166 StringRef String
= Range
.upto(R
);
167 Token
.reset(Type
, String
)
168 .setOwnedStringValue(
169 unescapeQuotedString(String
.drop_front(PrefixLength
)));
172 Token
.reset(MIToken::Error
, Range
.remaining());
175 while (isIdentifierChar(C
.peek()))
177 Token
.reset(Type
, Range
.upto(C
))
178 .setStringValue(Range
.upto(C
).drop_front(PrefixLength
));
182 static MIToken::TokenKind
getIdentifierKind(StringRef Identifier
) {
183 return StringSwitch
<MIToken::TokenKind
>(Identifier
)
184 .Case("_", MIToken::underscore
)
185 .Case("implicit", MIToken::kw_implicit
)
186 .Case("implicit-def", MIToken::kw_implicit_define
)
187 .Case("def", MIToken::kw_def
)
188 .Case("dead", MIToken::kw_dead
)
189 .Case("killed", MIToken::kw_killed
)
190 .Case("undef", MIToken::kw_undef
)
191 .Case("internal", MIToken::kw_internal
)
192 .Case("early-clobber", MIToken::kw_early_clobber
)
193 .Case("debug-use", MIToken::kw_debug_use
)
194 .Case("renamable", MIToken::kw_renamable
)
195 .Case("tied-def", MIToken::kw_tied_def
)
196 .Case("frame-setup", MIToken::kw_frame_setup
)
197 .Case("frame-destroy", MIToken::kw_frame_destroy
)
198 .Case("nnan", MIToken::kw_nnan
)
199 .Case("ninf", MIToken::kw_ninf
)
200 .Case("nsz", MIToken::kw_nsz
)
201 .Case("arcp", MIToken::kw_arcp
)
202 .Case("contract", MIToken::kw_contract
)
203 .Case("afn", MIToken::kw_afn
)
204 .Case("reassoc", MIToken::kw_reassoc
)
205 .Case("nuw" , MIToken::kw_nuw
)
206 .Case("nsw" , MIToken::kw_nsw
)
207 .Case("exact" , MIToken::kw_exact
)
208 .Case("debug-location", MIToken::kw_debug_location
)
209 .Case("same_value", MIToken::kw_cfi_same_value
)
210 .Case("offset", MIToken::kw_cfi_offset
)
211 .Case("rel_offset", MIToken::kw_cfi_rel_offset
)
212 .Case("def_cfa_register", MIToken::kw_cfi_def_cfa_register
)
213 .Case("def_cfa_offset", MIToken::kw_cfi_def_cfa_offset
)
214 .Case("adjust_cfa_offset", MIToken::kw_cfi_adjust_cfa_offset
)
215 .Case("escape", MIToken::kw_cfi_escape
)
216 .Case("def_cfa", MIToken::kw_cfi_def_cfa
)
217 .Case("remember_state", MIToken::kw_cfi_remember_state
)
218 .Case("restore", MIToken::kw_cfi_restore
)
219 .Case("restore_state", MIToken::kw_cfi_restore_state
)
220 .Case("undefined", MIToken::kw_cfi_undefined
)
221 .Case("register", MIToken::kw_cfi_register
)
222 .Case("window_save", MIToken::kw_cfi_window_save
)
223 .Case("blockaddress", MIToken::kw_blockaddress
)
224 .Case("intrinsic", MIToken::kw_intrinsic
)
225 .Case("target-index", MIToken::kw_target_index
)
226 .Case("half", MIToken::kw_half
)
227 .Case("float", MIToken::kw_float
)
228 .Case("double", MIToken::kw_double
)
229 .Case("x86_fp80", MIToken::kw_x86_fp80
)
230 .Case("fp128", MIToken::kw_fp128
)
231 .Case("ppc_fp128", MIToken::kw_ppc_fp128
)
232 .Case("target-flags", MIToken::kw_target_flags
)
233 .Case("volatile", MIToken::kw_volatile
)
234 .Case("non-temporal", MIToken::kw_non_temporal
)
235 .Case("dereferenceable", MIToken::kw_dereferenceable
)
236 .Case("invariant", MIToken::kw_invariant
)
237 .Case("align", MIToken::kw_align
)
238 .Case("addrspace", MIToken::kw_addrspace
)
239 .Case("stack", MIToken::kw_stack
)
240 .Case("got", MIToken::kw_got
)
241 .Case("jump-table", MIToken::kw_jump_table
)
242 .Case("constant-pool", MIToken::kw_constant_pool
)
243 .Case("call-entry", MIToken::kw_call_entry
)
244 .Case("liveout", MIToken::kw_liveout
)
245 .Case("address-taken", MIToken::kw_address_taken
)
246 .Case("landing-pad", MIToken::kw_landing_pad
)
247 .Case("liveins", MIToken::kw_liveins
)
248 .Case("successors", MIToken::kw_successors
)
249 .Case("floatpred", MIToken::kw_floatpred
)
250 .Case("intpred", MIToken::kw_intpred
)
251 .Case("pre-instr-symbol", MIToken::kw_pre_instr_symbol
)
252 .Case("post-instr-symbol", MIToken::kw_post_instr_symbol
)
253 .Case("unknown-size", MIToken::kw_unknown_size
)
254 .Default(MIToken::Identifier
);
257 static Cursor
maybeLexIdentifier(Cursor C
, MIToken
&Token
) {
258 if (!isalpha(C
.peek()) && C
.peek() != '_')
261 while (isIdentifierChar(C
.peek()))
263 auto Identifier
= Range
.upto(C
);
264 Token
.reset(getIdentifierKind(Identifier
), Identifier
)
265 .setStringValue(Identifier
);
269 static Cursor
maybeLexMachineBasicBlock(Cursor C
, MIToken
&Token
,
270 ErrorCallbackType ErrorCallback
) {
271 bool IsReference
= C
.remaining().startswith("%bb.");
272 if (!IsReference
&& !C
.remaining().startswith("bb."))
275 unsigned PrefixLength
= IsReference
? 4 : 3;
276 C
.advance(PrefixLength
); // Skip '%bb.' or 'bb.'
277 if (!isdigit(C
.peek())) {
278 Token
.reset(MIToken::Error
, C
.remaining());
279 ErrorCallback(C
.location(), "expected a number after '%bb.'");
282 auto NumberRange
= C
;
283 while (isdigit(C
.peek()))
285 StringRef Number
= NumberRange
.upto(C
);
286 unsigned StringOffset
= PrefixLength
+ Number
.size(); // Drop '%bb.<id>'
287 // TODO: The format bb.<id>.<irname> is supported only when it's not a
288 // reference. Once we deprecate the format where the irname shows up, we
289 // should only lex forward if it is a reference.
290 if (C
.peek() == '.') {
291 C
.advance(); // Skip '.'
293 while (isIdentifierChar(C
.peek()))
296 Token
.reset(IsReference
? MIToken::MachineBasicBlock
297 : MIToken::MachineBasicBlockLabel
,
299 .setIntegerValue(APSInt(Number
))
300 .setStringValue(Range
.upto(C
).drop_front(StringOffset
));
304 static Cursor
maybeLexIndex(Cursor C
, MIToken
&Token
, StringRef Rule
,
305 MIToken::TokenKind Kind
) {
306 if (!C
.remaining().startswith(Rule
) || !isdigit(C
.peek(Rule
.size())))
309 C
.advance(Rule
.size());
310 auto NumberRange
= C
;
311 while (isdigit(C
.peek()))
313 Token
.reset(Kind
, Range
.upto(C
)).setIntegerValue(APSInt(NumberRange
.upto(C
)));
317 static Cursor
maybeLexIndexAndName(Cursor C
, MIToken
&Token
, StringRef Rule
,
318 MIToken::TokenKind Kind
) {
319 if (!C
.remaining().startswith(Rule
) || !isdigit(C
.peek(Rule
.size())))
322 C
.advance(Rule
.size());
323 auto NumberRange
= C
;
324 while (isdigit(C
.peek()))
326 StringRef Number
= NumberRange
.upto(C
);
327 unsigned StringOffset
= Rule
.size() + Number
.size();
328 if (C
.peek() == '.') {
331 while (isIdentifierChar(C
.peek()))
334 Token
.reset(Kind
, Range
.upto(C
))
335 .setIntegerValue(APSInt(Number
))
336 .setStringValue(Range
.upto(C
).drop_front(StringOffset
));
340 static Cursor
maybeLexJumpTableIndex(Cursor C
, MIToken
&Token
) {
341 return maybeLexIndex(C
, Token
, "%jump-table.", MIToken::JumpTableIndex
);
344 static Cursor
maybeLexStackObject(Cursor C
, MIToken
&Token
) {
345 return maybeLexIndexAndName(C
, Token
, "%stack.", MIToken::StackObject
);
348 static Cursor
maybeLexFixedStackObject(Cursor C
, MIToken
&Token
) {
349 return maybeLexIndex(C
, Token
, "%fixed-stack.", MIToken::FixedStackObject
);
352 static Cursor
maybeLexConstantPoolItem(Cursor C
, MIToken
&Token
) {
353 return maybeLexIndex(C
, Token
, "%const.", MIToken::ConstantPoolItem
);
356 static Cursor
maybeLexSubRegisterIndex(Cursor C
, MIToken
&Token
,
357 ErrorCallbackType ErrorCallback
) {
358 const StringRef Rule
= "%subreg.";
359 if (!C
.remaining().startswith(Rule
))
361 return lexName(C
, Token
, MIToken::SubRegisterIndex
, Rule
.size(),
365 static Cursor
maybeLexIRBlock(Cursor C
, MIToken
&Token
,
366 ErrorCallbackType ErrorCallback
) {
367 const StringRef Rule
= "%ir-block.";
368 if (!C
.remaining().startswith(Rule
))
370 if (isdigit(C
.peek(Rule
.size())))
371 return maybeLexIndex(C
, Token
, Rule
, MIToken::IRBlock
);
372 return lexName(C
, Token
, MIToken::NamedIRBlock
, Rule
.size(), ErrorCallback
);
375 static Cursor
maybeLexIRValue(Cursor C
, MIToken
&Token
,
376 ErrorCallbackType ErrorCallback
) {
377 const StringRef Rule
= "%ir.";
378 if (!C
.remaining().startswith(Rule
))
380 if (isdigit(C
.peek(Rule
.size())))
381 return maybeLexIndex(C
, Token
, Rule
, MIToken::IRValue
);
382 return lexName(C
, Token
, MIToken::NamedIRValue
, Rule
.size(), ErrorCallback
);
385 static Cursor
maybeLexStringConstant(Cursor C
, MIToken
&Token
,
386 ErrorCallbackType ErrorCallback
) {
389 return lexName(C
, Token
, MIToken::StringConstant
, /*PrefixLength=*/0,
393 static Cursor
lexVirtualRegister(Cursor C
, MIToken
&Token
) {
395 C
.advance(); // Skip '%'
396 auto NumberRange
= C
;
397 while (isdigit(C
.peek()))
399 Token
.reset(MIToken::VirtualRegister
, Range
.upto(C
))
400 .setIntegerValue(APSInt(NumberRange
.upto(C
)));
404 /// Returns true for a character allowed in a register name.
405 static bool isRegisterChar(char C
) {
406 return isIdentifierChar(C
) && C
!= '.';
409 static Cursor
lexNamedVirtualRegister(Cursor C
, MIToken
&Token
) {
411 C
.advance(); // Skip '%'
412 while (isRegisterChar(C
.peek()))
414 Token
.reset(MIToken::NamedVirtualRegister
, Range
.upto(C
))
415 .setStringValue(Range
.upto(C
).drop_front(1)); // Drop the '%'
419 static Cursor
maybeLexRegister(Cursor C
, MIToken
&Token
,
420 ErrorCallbackType ErrorCallback
) {
421 if (C
.peek() != '%' && C
.peek() != '$')
424 if (C
.peek() == '%') {
425 if (isdigit(C
.peek(1)))
426 return lexVirtualRegister(C
, Token
);
428 if (isRegisterChar(C
.peek(1)))
429 return lexNamedVirtualRegister(C
, Token
);
434 assert(C
.peek() == '$');
436 C
.advance(); // Skip '$'
437 while (isRegisterChar(C
.peek()))
439 Token
.reset(MIToken::NamedRegister
, Range
.upto(C
))
440 .setStringValue(Range
.upto(C
).drop_front(1)); // Drop the '$'
444 static Cursor
maybeLexGlobalValue(Cursor C
, MIToken
&Token
,
445 ErrorCallbackType ErrorCallback
) {
448 if (!isdigit(C
.peek(1)))
449 return lexName(C
, Token
, MIToken::NamedGlobalValue
, /*PrefixLength=*/1,
452 C
.advance(1); // Skip the '@'
453 auto NumberRange
= C
;
454 while (isdigit(C
.peek()))
456 Token
.reset(MIToken::GlobalValue
, Range
.upto(C
))
457 .setIntegerValue(APSInt(NumberRange
.upto(C
)));
461 static Cursor
maybeLexExternalSymbol(Cursor C
, MIToken
&Token
,
462 ErrorCallbackType ErrorCallback
) {
465 return lexName(C
, Token
, MIToken::ExternalSymbol
, /*PrefixLength=*/1,
469 static Cursor
maybeLexMCSymbol(Cursor C
, MIToken
&Token
,
470 ErrorCallbackType ErrorCallback
) {
471 const StringRef Rule
= "<mcsymbol ";
472 if (!C
.remaining().startswith(Rule
))
475 C
.advance(Rule
.size());
477 // Try a simple unquoted name.
478 if (C
.peek() != '"') {
479 while (isIdentifierChar(C
.peek()))
481 StringRef String
= Start
.upto(C
).drop_front(Rule
.size());
482 if (C
.peek() != '>') {
483 ErrorCallback(C
.location(),
484 "expected the '<mcsymbol ...' to be closed by a '>'");
485 Token
.reset(MIToken::Error
, Start
.remaining());
490 Token
.reset(MIToken::MCSymbol
, Start
.upto(C
)).setStringValue(String
);
494 // Otherwise lex out a quoted name.
495 Cursor R
= lexStringConstant(C
, ErrorCallback
);
497 ErrorCallback(C
.location(),
498 "unable to parse quoted string from opening quote");
499 Token
.reset(MIToken::Error
, Start
.remaining());
502 StringRef String
= Start
.upto(R
).drop_front(Rule
.size());
503 if (R
.peek() != '>') {
504 ErrorCallback(R
.location(),
505 "expected the '<mcsymbol ...' to be closed by a '>'");
506 Token
.reset(MIToken::Error
, Start
.remaining());
511 Token
.reset(MIToken::MCSymbol
, Start
.upto(R
))
512 .setOwnedStringValue(unescapeQuotedString(String
));
516 static bool isValidHexFloatingPointPrefix(char C
) {
517 return C
== 'H' || C
== 'K' || C
== 'L' || C
== 'M';
520 static Cursor
lexFloatingPointLiteral(Cursor Range
, Cursor C
, MIToken
&Token
) {
522 // Skip over [0-9]*([eE][-+]?[0-9]+)?
523 while (isdigit(C
.peek()))
525 if ((C
.peek() == 'e' || C
.peek() == 'E') &&
526 (isdigit(C
.peek(1)) ||
527 ((C
.peek(1) == '-' || C
.peek(1) == '+') && isdigit(C
.peek(2))))) {
529 while (isdigit(C
.peek()))
532 Token
.reset(MIToken::FloatingPointLiteral
, Range
.upto(C
));
536 static Cursor
maybeLexHexadecimalLiteral(Cursor C
, MIToken
&Token
) {
537 if (C
.peek() != '0' || (C
.peek(1) != 'x' && C
.peek(1) != 'X'))
541 unsigned PrefLen
= 2;
542 if (isValidHexFloatingPointPrefix(C
.peek())) {
546 while (isxdigit(C
.peek()))
548 StringRef StrVal
= Range
.upto(C
);
549 if (StrVal
.size() <= PrefLen
)
552 Token
.reset(MIToken::HexLiteral
, Range
.upto(C
));
553 else // It must be 3, which means that there was a floating-point prefix.
554 Token
.reset(MIToken::FloatingPointLiteral
, Range
.upto(C
));
558 static Cursor
maybeLexNumericalLiteral(Cursor C
, MIToken
&Token
) {
559 if (!isdigit(C
.peek()) && (C
.peek() != '-' || !isdigit(C
.peek(1))))
563 while (isdigit(C
.peek()))
566 return lexFloatingPointLiteral(Range
, C
, Token
);
567 StringRef StrVal
= Range
.upto(C
);
568 Token
.reset(MIToken::IntegerLiteral
, StrVal
).setIntegerValue(APSInt(StrVal
));
572 static MIToken::TokenKind
getMetadataKeywordKind(StringRef Identifier
) {
573 return StringSwitch
<MIToken::TokenKind
>(Identifier
)
574 .Case("!tbaa", MIToken::md_tbaa
)
575 .Case("!alias.scope", MIToken::md_alias_scope
)
576 .Case("!noalias", MIToken::md_noalias
)
577 .Case("!range", MIToken::md_range
)
578 .Case("!DIExpression", MIToken::md_diexpr
)
579 .Default(MIToken::Error
);
582 static Cursor
maybeLexExlaim(Cursor C
, MIToken
&Token
,
583 ErrorCallbackType ErrorCallback
) {
588 if (isdigit(C
.peek()) || !isIdentifierChar(C
.peek())) {
589 Token
.reset(MIToken::exclaim
, Range
.upto(C
));
592 while (isIdentifierChar(C
.peek()))
594 StringRef StrVal
= Range
.upto(C
);
595 Token
.reset(getMetadataKeywordKind(StrVal
), StrVal
);
597 ErrorCallback(Token
.location(),
598 "use of unknown metadata keyword '" + StrVal
+ "'");
602 static MIToken::TokenKind
symbolToken(char C
) {
605 return MIToken::comma
;
609 return MIToken::equal
;
611 return MIToken::colon
;
613 return MIToken::lparen
;
615 return MIToken::rparen
;
617 return MIToken::lbrace
;
619 return MIToken::rbrace
;
621 return MIToken::plus
;
623 return MIToken::minus
;
625 return MIToken::less
;
627 return MIToken::greater
;
629 return MIToken::Error
;
633 static Cursor
maybeLexSymbol(Cursor C
, MIToken
&Token
) {
634 MIToken::TokenKind Kind
;
636 if (C
.peek() == ':' && C
.peek(1) == ':') {
637 Kind
= MIToken::coloncolon
;
640 Kind
= symbolToken(C
.peek());
641 if (Kind
== MIToken::Error
)
645 Token
.reset(Kind
, Range
.upto(C
));
649 static Cursor
maybeLexNewline(Cursor C
, MIToken
&Token
) {
650 if (!isNewlineChar(C
.peek()))
654 Token
.reset(MIToken::Newline
, Range
.upto(C
));
658 static Cursor
maybeLexEscapedIRValue(Cursor C
, MIToken
&Token
,
659 ErrorCallbackType ErrorCallback
) {
665 while (C
.peek() != '`') {
666 if (C
.isEOF() || isNewlineChar(C
.peek())) {
669 "end of machine instruction reached before the closing '`'");
670 Token
.reset(MIToken::Error
, Range
.remaining());
675 StringRef Value
= StrRange
.upto(C
);
677 Token
.reset(MIToken::QuotedIRValue
, Range
.upto(C
)).setStringValue(Value
);
681 StringRef
llvm::lexMIToken(StringRef Source
, MIToken
&Token
,
682 ErrorCallbackType ErrorCallback
) {
683 auto C
= skipComment(skipWhitespace(Cursor(Source
)));
685 Token
.reset(MIToken::Eof
, C
.remaining());
686 return C
.remaining();
689 if (Cursor R
= maybeLexMachineBasicBlock(C
, Token
, ErrorCallback
))
690 return R
.remaining();
691 if (Cursor R
= maybeLexIdentifier(C
, Token
))
692 return R
.remaining();
693 if (Cursor R
= maybeLexJumpTableIndex(C
, Token
))
694 return R
.remaining();
695 if (Cursor R
= maybeLexStackObject(C
, Token
))
696 return R
.remaining();
697 if (Cursor R
= maybeLexFixedStackObject(C
, Token
))
698 return R
.remaining();
699 if (Cursor R
= maybeLexConstantPoolItem(C
, Token
))
700 return R
.remaining();
701 if (Cursor R
= maybeLexSubRegisterIndex(C
, Token
, ErrorCallback
))
702 return R
.remaining();
703 if (Cursor R
= maybeLexIRBlock(C
, Token
, ErrorCallback
))
704 return R
.remaining();
705 if (Cursor R
= maybeLexIRValue(C
, Token
, ErrorCallback
))
706 return R
.remaining();
707 if (Cursor R
= maybeLexRegister(C
, Token
, ErrorCallback
))
708 return R
.remaining();
709 if (Cursor R
= maybeLexGlobalValue(C
, Token
, ErrorCallback
))
710 return R
.remaining();
711 if (Cursor R
= maybeLexExternalSymbol(C
, Token
, ErrorCallback
))
712 return R
.remaining();
713 if (Cursor R
= maybeLexMCSymbol(C
, Token
, ErrorCallback
))
714 return R
.remaining();
715 if (Cursor R
= maybeLexHexadecimalLiteral(C
, Token
))
716 return R
.remaining();
717 if (Cursor R
= maybeLexNumericalLiteral(C
, Token
))
718 return R
.remaining();
719 if (Cursor R
= maybeLexExlaim(C
, Token
, ErrorCallback
))
720 return R
.remaining();
721 if (Cursor R
= maybeLexSymbol(C
, Token
))
722 return R
.remaining();
723 if (Cursor R
= maybeLexNewline(C
, Token
))
724 return R
.remaining();
725 if (Cursor R
= maybeLexEscapedIRValue(C
, Token
, ErrorCallback
))
726 return R
.remaining();
727 if (Cursor R
= maybeLexStringConstant(C
, Token
, ErrorCallback
))
728 return R
.remaining();
730 Token
.reset(MIToken::Error
, C
.remaining());
731 ErrorCallback(C
.location(),
732 Twine("unexpected character '") + Twine(C
.peek()) + "'");
733 return C
.remaining();