LLVM  4.0.0
MILexer.cpp
Go to the documentation of this file.
1 //===- MILexer.cpp - Machine instructions lexer implementation ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the lexing of machine instructions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "MILexer.h"
15 #include "llvm/ADT/None.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/ADT/Twine.h"
19 #include <cctype>
20 
21 using namespace llvm;
22 
23 namespace {
24 
26  ErrorCallbackType;
27 
28 /// This class provides a way to iterate and get characters from the source
29 /// string.
30 class Cursor {
31  const char *Ptr;
32  const char *End;
33 
34 public:
35  Cursor(NoneType) : Ptr(nullptr), End(nullptr) {}
36 
37  explicit Cursor(StringRef Str) {
38  Ptr = Str.data();
39  End = Ptr + Str.size();
40  }
41 
42  bool isEOF() const { return Ptr == End; }
43 
44  char peek(int I = 0) const { return End - Ptr <= I ? 0 : Ptr[I]; }
45 
46  void advance(unsigned I = 1) { Ptr += I; }
47 
48  StringRef remaining() const { return StringRef(Ptr, End - Ptr); }
49 
50  StringRef upto(Cursor C) const {
51  assert(C.Ptr >= Ptr && C.Ptr <= End);
52  return StringRef(Ptr, C.Ptr - Ptr);
53  }
54 
55  StringRef::iterator location() const { return Ptr; }
56 
57  operator bool() const { return Ptr != nullptr; }
58 };
59 
60 } // end anonymous namespace
61 
63  this->Kind = Kind;
64  this->Range = Range;
65  return *this;
66 }
67 
69  StringValue = StrVal;
70  return *this;
71 }
72 
74  StringValueStorage = std::move(StrVal);
75  StringValue = StringValueStorage;
76  return *this;
77 }
78 
80  this->IntVal = std::move(IntVal);
81  return *this;
82 }
83 
84 /// Skip the leading whitespace characters and return the updated cursor.
85 static Cursor skipWhitespace(Cursor C) {
86  while (isblank(C.peek()))
87  C.advance();
88  return C;
89 }
90 
91 static bool isNewlineChar(char C) { return C == '\n' || C == '\r'; }
92 
93 /// Skip a line comment and return the updated cursor.
94 static Cursor skipComment(Cursor C) {
95  if (C.peek() != ';')
96  return C;
97  while (!isNewlineChar(C.peek()) && !C.isEOF())
98  C.advance();
99  return C;
100 }
101 
102 /// Return true if the given character satisfies the following regular
103 /// expression: [-a-zA-Z$._0-9]
104 static bool isIdentifierChar(char C) {
105  return isalpha(C) || isdigit(C) || C == '_' || C == '-' || C == '.' ||
106  C == '$';
107 }
108 
109 /// Unescapes the given string value.
110 ///
111 /// Expects the string value to be quoted.
112 static std::string unescapeQuotedString(StringRef Value) {
113  assert(Value.front() == '"' && Value.back() == '"');
114  Cursor C = Cursor(Value.substr(1, Value.size() - 2));
115 
116  std::string Str;
117  Str.reserve(C.remaining().size());
118  while (!C.isEOF()) {
119  char Char = C.peek();
120  if (Char == '\\') {
121  if (C.peek(1) == '\\') {
122  // Two '\' become one
123  Str += '\\';
124  C.advance(2);
125  continue;
126  }
127  if (isxdigit(C.peek(1)) && isxdigit(C.peek(2))) {
128  Str += hexDigitValue(C.peek(1)) * 16 + hexDigitValue(C.peek(2));
129  C.advance(3);
130  continue;
131  }
132  }
133  Str += Char;
134  C.advance();
135  }
136  return Str;
137 }
138 
139 /// Lex a string constant using the following regular expression: \"[^\"]*\"
140 static Cursor lexStringConstant(Cursor C, ErrorCallbackType ErrorCallback) {
141  assert(C.peek() == '"');
142  for (C.advance(); C.peek() != '"'; C.advance()) {
143  if (C.isEOF() || isNewlineChar(C.peek())) {
144  ErrorCallback(
145  C.location(),
146  "end of machine instruction reached before the closing '\"'");
147  return None;
148  }
149  }
150  C.advance();
151  return C;
152 }
153 
154 static Cursor lexName(Cursor C, MIToken &Token, MIToken::TokenKind Type,
155  unsigned PrefixLength, ErrorCallbackType ErrorCallback) {
156  auto Range = C;
157  C.advance(PrefixLength);
158  if (C.peek() == '"') {
159  if (Cursor R = lexStringConstant(C, ErrorCallback)) {
160  StringRef String = Range.upto(R);
161  Token.reset(Type, String)
163  unescapeQuotedString(String.drop_front(PrefixLength)));
164  return R;
165  }
166  Token.reset(MIToken::Error, Range.remaining());
167  return Range;
168  }
169  while (isIdentifierChar(C.peek()))
170  C.advance();
171  Token.reset(Type, Range.upto(C))
172  .setStringValue(Range.upto(C).drop_front(PrefixLength));
173  return C;
174 }
175 
176 static Cursor maybeLexIntegerOrScalarType(Cursor C, MIToken &Token) {
177  if ((C.peek() != 'i' && C.peek() != 's' && C.peek() != 'p') ||
178  !isdigit(C.peek(1)))
179  return None;
180  char Kind = C.peek();
181  auto Range = C;
182  C.advance(); // Skip 'i', 's', or 'p'
183  while (isdigit(C.peek()))
184  C.advance();
185 
186  Token.reset(Kind == 'i'
188  : (Kind == 's' ? MIToken::ScalarType : MIToken::PointerType),
189  Range.upto(C));
190  return C;
191 }
192 
194  return StringSwitch<MIToken::TokenKind>(Identifier)
195  .Case("_", MIToken::underscore)
196  .Case("implicit", MIToken::kw_implicit)
197  .Case("implicit-def", MIToken::kw_implicit_define)
198  .Case("def", MIToken::kw_def)
199  .Case("dead", MIToken::kw_dead)
200  .Case("killed", MIToken::kw_killed)
201  .Case("undef", MIToken::kw_undef)
202  .Case("internal", MIToken::kw_internal)
203  .Case("early-clobber", MIToken::kw_early_clobber)
204  .Case("debug-use", MIToken::kw_debug_use)
205  .Case("tied-def", MIToken::kw_tied_def)
206  .Case("frame-setup", MIToken::kw_frame_setup)
207  .Case("debug-location", MIToken::kw_debug_location)
208  .Case("same_value", MIToken::kw_cfi_same_value)
209  .Case("offset", MIToken::kw_cfi_offset)
210  .Case("def_cfa_register", MIToken::kw_cfi_def_cfa_register)
211  .Case("def_cfa_offset", MIToken::kw_cfi_def_cfa_offset)
212  .Case("def_cfa", MIToken::kw_cfi_def_cfa)
213  .Case("blockaddress", MIToken::kw_blockaddress)
214  .Case("intrinsic", MIToken::kw_intrinsic)
215  .Case("target-index", MIToken::kw_target_index)
216  .Case("half", MIToken::kw_half)
217  .Case("float", MIToken::kw_float)
218  .Case("double", MIToken::kw_double)
219  .Case("x86_fp80", MIToken::kw_x86_fp80)
220  .Case("fp128", MIToken::kw_fp128)
221  .Case("ppc_fp128", MIToken::kw_ppc_fp128)
222  .Case("target-flags", MIToken::kw_target_flags)
223  .Case("volatile", MIToken::kw_volatile)
224  .Case("non-temporal", MIToken::kw_non_temporal)
225  .Case("dereferenceable", MIToken::kw_dereferenceable)
226  .Case("invariant", MIToken::kw_invariant)
227  .Case("align", MIToken::kw_align)
228  .Case("stack", MIToken::kw_stack)
229  .Case("got", MIToken::kw_got)
230  .Case("jump-table", MIToken::kw_jump_table)
231  .Case("constant-pool", MIToken::kw_constant_pool)
232  .Case("call-entry", MIToken::kw_call_entry)
233  .Case("liveout", MIToken::kw_liveout)
234  .Case("address-taken", MIToken::kw_address_taken)
235  .Case("landing-pad", MIToken::kw_landing_pad)
236  .Case("liveins", MIToken::kw_liveins)
237  .Case("successors", MIToken::kw_successors)
238  .Case("floatpred", MIToken::kw_floatpred)
239  .Case("intpred", MIToken::kw_intpred)
241 }
242 
243 static Cursor maybeLexIdentifier(Cursor C, MIToken &Token) {
244  if (!isalpha(C.peek()) && C.peek() != '_')
245  return None;
246  auto Range = C;
247  while (isIdentifierChar(C.peek()))
248  C.advance();
249  auto Identifier = Range.upto(C);
250  Token.reset(getIdentifierKind(Identifier), Identifier)
251  .setStringValue(Identifier);
252  return C;
253 }
254 
255 static Cursor maybeLexMachineBasicBlock(Cursor C, MIToken &Token,
256  ErrorCallbackType ErrorCallback) {
257  bool IsReference = C.remaining().startswith("%bb.");
258  if (!IsReference && !C.remaining().startswith("bb."))
259  return None;
260  auto Range = C;
261  unsigned PrefixLength = IsReference ? 4 : 3;
262  C.advance(PrefixLength); // Skip '%bb.' or 'bb.'
263  if (!isdigit(C.peek())) {
264  Token.reset(MIToken::Error, C.remaining());
265  ErrorCallback(C.location(), "expected a number after '%bb.'");
266  return C;
267  }
268  auto NumberRange = C;
269  while (isdigit(C.peek()))
270  C.advance();
271  StringRef Number = NumberRange.upto(C);
272  unsigned StringOffset = PrefixLength + Number.size(); // Drop '%bb.<id>'
273  if (C.peek() == '.') {
274  C.advance(); // Skip '.'
275  ++StringOffset;
276  while (isIdentifierChar(C.peek()))
277  C.advance();
278  }
279  Token.reset(IsReference ? MIToken::MachineBasicBlock
281  Range.upto(C))
282  .setIntegerValue(APSInt(Number))
283  .setStringValue(Range.upto(C).drop_front(StringOffset));
284  return C;
285 }
286 
287 static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule,
289  if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.size())))
290  return None;
291  auto Range = C;
292  C.advance(Rule.size());
293  auto NumberRange = C;
294  while (isdigit(C.peek()))
295  C.advance();
296  Token.reset(Kind, Range.upto(C)).setIntegerValue(APSInt(NumberRange.upto(C)));
297  return C;
298 }
299 
300 static Cursor maybeLexIndexAndName(Cursor C, MIToken &Token, StringRef Rule,
302  if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.size())))
303  return None;
304  auto Range = C;
305  C.advance(Rule.size());
306  auto NumberRange = C;
307  while (isdigit(C.peek()))
308  C.advance();
309  StringRef Number = NumberRange.upto(C);
310  unsigned StringOffset = Rule.size() + Number.size();
311  if (C.peek() == '.') {
312  C.advance();
313  ++StringOffset;
314  while (isIdentifierChar(C.peek()))
315  C.advance();
316  }
317  Token.reset(Kind, Range.upto(C))
318  .setIntegerValue(APSInt(Number))
319  .setStringValue(Range.upto(C).drop_front(StringOffset));
320  return C;
321 }
322 
323 static Cursor maybeLexJumpTableIndex(Cursor C, MIToken &Token) {
324  return maybeLexIndex(C, Token, "%jump-table.", MIToken::JumpTableIndex);
325 }
326 
327 static Cursor maybeLexStackObject(Cursor C, MIToken &Token) {
328  return maybeLexIndexAndName(C, Token, "%stack.", MIToken::StackObject);
329 }
330 
331 static Cursor maybeLexFixedStackObject(Cursor C, MIToken &Token) {
332  return maybeLexIndex(C, Token, "%fixed-stack.", MIToken::FixedStackObject);
333 }
334 
335 static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token) {
336  return maybeLexIndex(C, Token, "%const.", MIToken::ConstantPoolItem);
337 }
338 
339 static Cursor maybeLexSubRegisterIndex(Cursor C, MIToken &Token,
340  ErrorCallbackType ErrorCallback) {
341  const StringRef Rule = "%subreg.";
342  if (!C.remaining().startswith(Rule))
343  return None;
344  return lexName(C, Token, MIToken::SubRegisterIndex, Rule.size(),
345  ErrorCallback);
346 }
347 
348 static Cursor maybeLexIRBlock(Cursor C, MIToken &Token,
349  ErrorCallbackType ErrorCallback) {
350  const StringRef Rule = "%ir-block.";
351  if (!C.remaining().startswith(Rule))
352  return None;
353  if (isdigit(C.peek(Rule.size())))
354  return maybeLexIndex(C, Token, Rule, MIToken::IRBlock);
355  return lexName(C, Token, MIToken::NamedIRBlock, Rule.size(), ErrorCallback);
356 }
357 
358 static Cursor maybeLexIRValue(Cursor C, MIToken &Token,
359  ErrorCallbackType ErrorCallback) {
360  const StringRef Rule = "%ir.";
361  if (!C.remaining().startswith(Rule))
362  return None;
363  if (isdigit(C.peek(Rule.size())))
364  return maybeLexIndex(C, Token, Rule, MIToken::IRValue);
365  return lexName(C, Token, MIToken::NamedIRValue, Rule.size(), ErrorCallback);
366 }
367 
368 static Cursor lexVirtualRegister(Cursor C, MIToken &Token) {
369  auto Range = C;
370  C.advance(); // Skip '%'
371  auto NumberRange = C;
372  while (isdigit(C.peek()))
373  C.advance();
374  Token.reset(MIToken::VirtualRegister, Range.upto(C))
375  .setIntegerValue(APSInt(NumberRange.upto(C)));
376  return C;
377 }
378 
379 /// Returns true for a character allowed in a register name.
380 static bool isRegisterChar(char C) {
381  return isIdentifierChar(C) && C != '.';
382 }
383 
384 static Cursor maybeLexRegister(Cursor C, MIToken &Token) {
385  if (C.peek() != '%')
386  return None;
387  if (isdigit(C.peek(1)))
388  return lexVirtualRegister(C, Token);
389  auto Range = C;
390  C.advance(); // Skip '%'
391  while (isRegisterChar(C.peek()))
392  C.advance();
393  Token.reset(MIToken::NamedRegister, Range.upto(C))
394  .setStringValue(Range.upto(C).drop_front(1)); // Drop the '%'
395  return C;
396 }
397 
398 static Cursor maybeLexGlobalValue(Cursor C, MIToken &Token,
399  ErrorCallbackType ErrorCallback) {
400  if (C.peek() != '@')
401  return None;
402  if (!isdigit(C.peek(1)))
403  return lexName(C, Token, MIToken::NamedGlobalValue, /*PrefixLength=*/1,
404  ErrorCallback);
405  auto Range = C;
406  C.advance(1); // Skip the '@'
407  auto NumberRange = C;
408  while (isdigit(C.peek()))
409  C.advance();
410  Token.reset(MIToken::GlobalValue, Range.upto(C))
411  .setIntegerValue(APSInt(NumberRange.upto(C)));
412  return C;
413 }
414 
415 static Cursor maybeLexExternalSymbol(Cursor C, MIToken &Token,
416  ErrorCallbackType ErrorCallback) {
417  if (C.peek() != '$')
418  return None;
419  return lexName(C, Token, MIToken::ExternalSymbol, /*PrefixLength=*/1,
420  ErrorCallback);
421 }
422 
423 static bool isValidHexFloatingPointPrefix(char C) {
424  return C == 'H' || C == 'K' || C == 'L' || C == 'M';
425 }
426 
427 static Cursor lexFloatingPointLiteral(Cursor Range, Cursor C, MIToken &Token) {
428  C.advance();
429  // Skip over [0-9]*([eE][-+]?[0-9]+)?
430  while (isdigit(C.peek()))
431  C.advance();
432  if ((C.peek() == 'e' || C.peek() == 'E') &&
433  (isdigit(C.peek(1)) ||
434  ((C.peek(1) == '-' || C.peek(1) == '+') && isdigit(C.peek(2))))) {
435  C.advance(2);
436  while (isdigit(C.peek()))
437  C.advance();
438  }
439  Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
440  return C;
441 }
442 
443 static Cursor maybeLexHexadecimalLiteral(Cursor C, MIToken &Token) {
444  if (C.peek() != '0' || (C.peek(1) != 'x' && C.peek(1) != 'X'))
445  return None;
446  Cursor Range = C;
447  C.advance(2);
448  unsigned PrefLen = 2;
449  if (isValidHexFloatingPointPrefix(C.peek())) {
450  C.advance();
451  PrefLen++;
452  }
453  while (isxdigit(C.peek()))
454  C.advance();
455  StringRef StrVal = Range.upto(C);
456  if (StrVal.size() <= PrefLen)
457  return None;
458  if (PrefLen == 2)
459  Token.reset(MIToken::HexLiteral, Range.upto(C));
460  else // It must be 3, which means that there was a floating-point prefix.
461  Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
462  return C;
463 }
464 
465 static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token) {
466  if (!isdigit(C.peek()) && (C.peek() != '-' || !isdigit(C.peek(1))))
467  return None;
468  auto Range = C;
469  C.advance();
470  while (isdigit(C.peek()))
471  C.advance();
472  if (C.peek() == '.')
473  return lexFloatingPointLiteral(Range, C, Token);
474  StringRef StrVal = Range.upto(C);
475  Token.reset(MIToken::IntegerLiteral, StrVal).setIntegerValue(APSInt(StrVal));
476  return C;
477 }
478 
480  return StringSwitch<MIToken::TokenKind>(Identifier)
481  .Case("!tbaa", MIToken::md_tbaa)
482  .Case("!alias.scope", MIToken::md_alias_scope)
483  .Case("!noalias", MIToken::md_noalias)
484  .Case("!range", MIToken::md_range)
486 }
487 
488 static Cursor maybeLexExlaim(Cursor C, MIToken &Token,
489  ErrorCallbackType ErrorCallback) {
490  if (C.peek() != '!')
491  return None;
492  auto Range = C;
493  C.advance(1);
494  if (isdigit(C.peek()) || !isIdentifierChar(C.peek())) {
495  Token.reset(MIToken::exclaim, Range.upto(C));
496  return C;
497  }
498  while (isIdentifierChar(C.peek()))
499  C.advance();
500  StringRef StrVal = Range.upto(C);
501  Token.reset(getMetadataKeywordKind(StrVal), StrVal);
502  if (Token.isError())
503  ErrorCallback(Token.location(),
504  "use of unknown metadata keyword '" + StrVal + "'");
505  return C;
506 }
507 
509  switch (C) {
510  case ',':
511  return MIToken::comma;
512  case '.':
513  return MIToken::dot;
514  case '=':
515  return MIToken::equal;
516  case ':':
517  return MIToken::colon;
518  case '(':
519  return MIToken::lparen;
520  case ')':
521  return MIToken::rparen;
522  case '{':
523  return MIToken::lbrace;
524  case '}':
525  return MIToken::rbrace;
526  case '+':
527  return MIToken::plus;
528  case '-':
529  return MIToken::minus;
530  case '<':
531  return MIToken::less;
532  case '>':
533  return MIToken::greater;
534  default:
535  return MIToken::Error;
536  }
537 }
538 
539 static Cursor maybeLexSymbol(Cursor C, MIToken &Token) {
541  unsigned Length = 1;
542  if (C.peek() == ':' && C.peek(1) == ':') {
543  Kind = MIToken::coloncolon;
544  Length = 2;
545  } else
546  Kind = symbolToken(C.peek());
547  if (Kind == MIToken::Error)
548  return None;
549  auto Range = C;
550  C.advance(Length);
551  Token.reset(Kind, Range.upto(C));
552  return C;
553 }
554 
555 static Cursor maybeLexNewline(Cursor C, MIToken &Token) {
556  if (!isNewlineChar(C.peek()))
557  return None;
558  auto Range = C;
559  C.advance();
560  Token.reset(MIToken::Newline, Range.upto(C));
561  return C;
562 }
563 
564 static Cursor maybeLexEscapedIRValue(Cursor C, MIToken &Token,
565  ErrorCallbackType ErrorCallback) {
566  if (C.peek() != '`')
567  return None;
568  auto Range = C;
569  C.advance();
570  auto StrRange = C;
571  while (C.peek() != '`') {
572  if (C.isEOF() || isNewlineChar(C.peek())) {
573  ErrorCallback(
574  C.location(),
575  "end of machine instruction reached before the closing '`'");
576  Token.reset(MIToken::Error, Range.remaining());
577  return C;
578  }
579  C.advance();
580  }
581  StringRef Value = StrRange.upto(C);
582  C.advance();
583  Token.reset(MIToken::QuotedIRValue, Range.upto(C)).setStringValue(Value);
584  return C;
585 }
586 
588  ErrorCallbackType ErrorCallback) {
589  auto C = skipComment(skipWhitespace(Cursor(Source)));
590  if (C.isEOF()) {
591  Token.reset(MIToken::Eof, C.remaining());
592  return C.remaining();
593  }
594 
595  if (Cursor R = maybeLexIntegerOrScalarType(C, Token))
596  return R.remaining();
597  if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback))
598  return R.remaining();
599  if (Cursor R = maybeLexIdentifier(C, Token))
600  return R.remaining();
601  if (Cursor R = maybeLexJumpTableIndex(C, Token))
602  return R.remaining();
603  if (Cursor R = maybeLexStackObject(C, Token))
604  return R.remaining();
605  if (Cursor R = maybeLexFixedStackObject(C, Token))
606  return R.remaining();
607  if (Cursor R = maybeLexConstantPoolItem(C, Token))
608  return R.remaining();
609  if (Cursor R = maybeLexSubRegisterIndex(C, Token, ErrorCallback))
610  return R.remaining();
611  if (Cursor R = maybeLexIRBlock(C, Token, ErrorCallback))
612  return R.remaining();
613  if (Cursor R = maybeLexIRValue(C, Token, ErrorCallback))
614  return R.remaining();
615  if (Cursor R = maybeLexRegister(C, Token))
616  return R.remaining();
617  if (Cursor R = maybeLexGlobalValue(C, Token, ErrorCallback))
618  return R.remaining();
619  if (Cursor R = maybeLexExternalSymbol(C, Token, ErrorCallback))
620  return R.remaining();
621  if (Cursor R = maybeLexHexadecimalLiteral(C, Token))
622  return R.remaining();
623  if (Cursor R = maybeLexNumericalLiteral(C, Token))
624  return R.remaining();
625  if (Cursor R = maybeLexExlaim(C, Token, ErrorCallback))
626  return R.remaining();
627  if (Cursor R = maybeLexSymbol(C, Token))
628  return R.remaining();
629  if (Cursor R = maybeLexNewline(C, Token))
630  return R.remaining();
631  if (Cursor R = maybeLexEscapedIRValue(C, Token, ErrorCallback))
632  return R.remaining();
633 
634  Token.reset(MIToken::Error, C.remaining());
635  ErrorCallback(C.location(),
636  Twine("unexpected character '") + Twine(C.peek()) + "'");
637  return C.remaining();
638 }
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.
Definition: StringRef.h:634
const NoneType None
Definition: None.h:23
static Cursor maybeLexIRBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:348
uint64_t Token
static MIToken::TokenKind getMetadataKeywordKind(StringRef Identifier)
Definition: MILexer.cpp:479
static bool isRegisterChar(char C)
Returns true for a character allowed in a register name.
Definition: MILexer.cpp:380
static Cursor maybeLexIntegerOrScalarType(Cursor C, MIToken &Token)
Definition: MILexer.cpp:176
NoneType
A simple null object to allow implicit construction of Optional<T> and similar types without having to ...
Definition: None.h:22
static Cursor lexName(Cursor C, MIToken &Token, MIToken::TokenKind Type, unsigned PrefixLength, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:154
static Cursor lexStringConstant(Cursor C, ErrorCallbackType ErrorCallback)
Lex a string constant using the following regular expression: "[^"]*".
Definition: MILexer.cpp:140
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:83
static Cursor maybeLexEscapedIRValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:564
LLVM_NODISCARD char back() const
back - Get the last character in the string.
Definition: StringRef.h:146
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)
Definition: MILexer.cpp:62
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
static bool isNewlineChar(char C)
Definition: MILexer.cpp:91
static void advance(T &it, size_t Val)
StringRef::iterator location() const
Definition: MILexer.h:178
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Definition: StringSwitch.h:244
static bool isValidHexFloatingPointPrefix(char C)
Definition: MILexer.cpp:423
static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token)
Definition: MILexer.cpp:465
static Cursor maybeLexMachineBasicBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:255
static Cursor lexFloatingPointLiteral(Cursor Range, Cursor C, MIToken &Token)
Definition: MILexer.cpp:427
static Cursor skipWhitespace(Cursor C)
Skip the leading whitespace characters and return the updated cursor.
Definition: MILexer.cpp:85
static Cursor maybeLexIdentifier(Cursor C, MIToken &Token)
Definition: MILexer.cpp:243
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:74
static Cursor maybeLexGlobalValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:398
LLVM_NODISCARD char front() const
front - Get the first character in the string.
Definition: StringRef.h:139
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:135
static Cursor maybeLexExternalSymbol(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:415
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
bool isError() const
Definition: MILexer.h:151
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
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).
Definition: StringRef.h:587
static Cursor maybeLexNewline(Cursor C, MIToken &Token)
Definition: MILexer.cpp:555
static const unsigned End
static Cursor maybeLexStackObject(Cursor C, MIToken &Token)
Definition: MILexer.cpp:327
static Cursor lexVirtualRegister(Cursor C, MIToken &Token)
Definition: MILexer.cpp:368
static MIToken::TokenKind symbolToken(char C)
Definition: MILexer.cpp:508
MIToken & setOwnedStringValue(std::string StrVal)
Definition: MILexer.cpp:73
static Cursor maybeLexFixedStackObject(Cursor C, MIToken &Token)
Definition: MILexer.cpp:331
static Cursor skipComment(Cursor C)
Skip a line comment and return the updated cursor.
Definition: MILexer.cpp:94
const char * iterator
Definition: StringRef.h:49
MIToken & setStringValue(StringRef StrVal)
Definition: MILexer.cpp:68
static Cursor maybeLexSymbol(Cursor C, MIToken &Token)
Definition: MILexer.cpp:539
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)
Definition: MILexer.cpp:300
static Cursor maybeLexHexadecimalLiteral(Cursor C, MIToken &Token)
Definition: MILexer.cpp:443
static Cursor maybeLexJumpTableIndex(Cursor C, MIToken &Token)
Definition: MILexer.cpp:323
static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token)
Definition: MILexer.cpp:335
static Cursor maybeLexRegister(Cursor C, MIToken &Token)
Definition: MILexer.cpp:384
#define I(x, y, z)
Definition: MD5.cpp:54
const unsigned Kind
static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule, MIToken::TokenKind Kind)
Definition: MILexer.cpp:287
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Cursor maybeLexExlaim(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:488
LLVM Value Representation.
Definition: Value.h:71
static unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
Definition: StringExtras.h:41
A token produced by the machine instruction lexer.
Definition: MILexer.h:28
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).
Definition: StringRef.h:125
static Cursor maybeLexIRValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:358
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
MIToken & setIntegerValue(APSInt IntVal)
Definition: MILexer.cpp:79
static MIToken::TokenKind getIdentifierKind(StringRef Identifier)
Definition: MILexer.cpp:193
int * Ptr
static bool isIdentifierChar(char C)
Return true if the given character satisfies the following regular expression: [-a-zA-Z$._0-9].
Definition: MILexer.cpp:104
static Cursor maybeLexSubRegisterIndex(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:339
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:411
static std::string unescapeQuotedString(StringRef Value)
Unescapes the given string value.
Definition: MILexer.cpp:112