LLVM  5.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 
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);
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 maybeLexStringConstant(Cursor C, MIToken &Token,
369  ErrorCallbackType ErrorCallback) {
370  if (C.peek() != '"')
371  return None;
372  return lexName(C, Token, MIToken::StringConstant, /*PrefixLength=*/0,
373  ErrorCallback);
374 }
375 
376 static Cursor lexVirtualRegister(Cursor C, MIToken &Token) {
377  auto Range = C;
378  C.advance(); // Skip '%'
379  auto NumberRange = C;
380  while (isdigit(C.peek()))
381  C.advance();
382  Token.reset(MIToken::VirtualRegister, Range.upto(C))
383  .setIntegerValue(APSInt(NumberRange.upto(C)));
384  return C;
385 }
386 
387 /// Returns true for a character allowed in a register name.
388 static bool isRegisterChar(char C) {
389  return isIdentifierChar(C) && C != '.';
390 }
391 
392 static Cursor maybeLexRegister(Cursor C, MIToken &Token) {
393  if (C.peek() != '%')
394  return None;
395  if (isdigit(C.peek(1)))
396  return lexVirtualRegister(C, Token);
397  auto Range = C;
398  C.advance(); // Skip '%'
399  while (isRegisterChar(C.peek()))
400  C.advance();
401  Token.reset(MIToken::NamedRegister, Range.upto(C))
402  .setStringValue(Range.upto(C).drop_front(1)); // Drop the '%'
403  return C;
404 }
405 
406 static Cursor maybeLexGlobalValue(Cursor C, MIToken &Token,
407  ErrorCallbackType ErrorCallback) {
408  if (C.peek() != '@')
409  return None;
410  if (!isdigit(C.peek(1)))
411  return lexName(C, Token, MIToken::NamedGlobalValue, /*PrefixLength=*/1,
412  ErrorCallback);
413  auto Range = C;
414  C.advance(1); // Skip the '@'
415  auto NumberRange = C;
416  while (isdigit(C.peek()))
417  C.advance();
418  Token.reset(MIToken::GlobalValue, Range.upto(C))
419  .setIntegerValue(APSInt(NumberRange.upto(C)));
420  return C;
421 }
422 
423 static Cursor maybeLexExternalSymbol(Cursor C, MIToken &Token,
424  ErrorCallbackType ErrorCallback) {
425  if (C.peek() != '$')
426  return None;
427  return lexName(C, Token, MIToken::ExternalSymbol, /*PrefixLength=*/1,
428  ErrorCallback);
429 }
430 
431 static bool isValidHexFloatingPointPrefix(char C) {
432  return C == 'H' || C == 'K' || C == 'L' || C == 'M';
433 }
434 
435 static Cursor lexFloatingPointLiteral(Cursor Range, Cursor C, MIToken &Token) {
436  C.advance();
437  // Skip over [0-9]*([eE][-+]?[0-9]+)?
438  while (isdigit(C.peek()))
439  C.advance();
440  if ((C.peek() == 'e' || C.peek() == 'E') &&
441  (isdigit(C.peek(1)) ||
442  ((C.peek(1) == '-' || C.peek(1) == '+') && isdigit(C.peek(2))))) {
443  C.advance(2);
444  while (isdigit(C.peek()))
445  C.advance();
446  }
447  Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
448  return C;
449 }
450 
451 static Cursor maybeLexHexadecimalLiteral(Cursor C, MIToken &Token) {
452  if (C.peek() != '0' || (C.peek(1) != 'x' && C.peek(1) != 'X'))
453  return None;
454  Cursor Range = C;
455  C.advance(2);
456  unsigned PrefLen = 2;
457  if (isValidHexFloatingPointPrefix(C.peek())) {
458  C.advance();
459  PrefLen++;
460  }
461  while (isxdigit(C.peek()))
462  C.advance();
463  StringRef StrVal = Range.upto(C);
464  if (StrVal.size() <= PrefLen)
465  return None;
466  if (PrefLen == 2)
467  Token.reset(MIToken::HexLiteral, Range.upto(C));
468  else // It must be 3, which means that there was a floating-point prefix.
469  Token.reset(MIToken::FloatingPointLiteral, Range.upto(C));
470  return C;
471 }
472 
473 static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token) {
474  if (!isdigit(C.peek()) && (C.peek() != '-' || !isdigit(C.peek(1))))
475  return None;
476  auto Range = C;
477  C.advance();
478  while (isdigit(C.peek()))
479  C.advance();
480  if (C.peek() == '.')
481  return lexFloatingPointLiteral(Range, C, Token);
482  StringRef StrVal = Range.upto(C);
483  Token.reset(MIToken::IntegerLiteral, StrVal).setIntegerValue(APSInt(StrVal));
484  return C;
485 }
486 
489  .Case("!tbaa", MIToken::md_tbaa)
490  .Case("!alias.scope", MIToken::md_alias_scope)
491  .Case("!noalias", MIToken::md_noalias)
492  .Case("!range", MIToken::md_range)
494 }
495 
496 static Cursor maybeLexExlaim(Cursor C, MIToken &Token,
497  ErrorCallbackType ErrorCallback) {
498  if (C.peek() != '!')
499  return None;
500  auto Range = C;
501  C.advance(1);
502  if (isdigit(C.peek()) || !isIdentifierChar(C.peek())) {
503  Token.reset(MIToken::exclaim, Range.upto(C));
504  return C;
505  }
506  while (isIdentifierChar(C.peek()))
507  C.advance();
508  StringRef StrVal = Range.upto(C);
509  Token.reset(getMetadataKeywordKind(StrVal), StrVal);
510  if (Token.isError())
511  ErrorCallback(Token.location(),
512  "use of unknown metadata keyword '" + StrVal + "'");
513  return C;
514 }
515 
517  switch (C) {
518  case ',':
519  return MIToken::comma;
520  case '.':
521  return MIToken::dot;
522  case '=':
523  return MIToken::equal;
524  case ':':
525  return MIToken::colon;
526  case '(':
527  return MIToken::lparen;
528  case ')':
529  return MIToken::rparen;
530  case '{':
531  return MIToken::lbrace;
532  case '}':
533  return MIToken::rbrace;
534  case '+':
535  return MIToken::plus;
536  case '-':
537  return MIToken::minus;
538  case '<':
539  return MIToken::less;
540  case '>':
541  return MIToken::greater;
542  default:
543  return MIToken::Error;
544  }
545 }
546 
547 static Cursor maybeLexSymbol(Cursor C, MIToken &Token) {
549  unsigned Length = 1;
550  if (C.peek() == ':' && C.peek(1) == ':') {
551  Kind = MIToken::coloncolon;
552  Length = 2;
553  } else
554  Kind = symbolToken(C.peek());
555  if (Kind == MIToken::Error)
556  return None;
557  auto Range = C;
558  C.advance(Length);
559  Token.reset(Kind, Range.upto(C));
560  return C;
561 }
562 
563 static Cursor maybeLexNewline(Cursor C, MIToken &Token) {
564  if (!isNewlineChar(C.peek()))
565  return None;
566  auto Range = C;
567  C.advance();
568  Token.reset(MIToken::Newline, Range.upto(C));
569  return C;
570 }
571 
572 static Cursor maybeLexEscapedIRValue(Cursor C, MIToken &Token,
573  ErrorCallbackType ErrorCallback) {
574  if (C.peek() != '`')
575  return None;
576  auto Range = C;
577  C.advance();
578  auto StrRange = C;
579  while (C.peek() != '`') {
580  if (C.isEOF() || isNewlineChar(C.peek())) {
581  ErrorCallback(
582  C.location(),
583  "end of machine instruction reached before the closing '`'");
584  Token.reset(MIToken::Error, Range.remaining());
585  return C;
586  }
587  C.advance();
588  }
589  StringRef Value = StrRange.upto(C);
590  C.advance();
591  Token.reset(MIToken::QuotedIRValue, Range.upto(C)).setStringValue(Value);
592  return C;
593 }
594 
596  ErrorCallbackType ErrorCallback) {
597  auto C = skipComment(skipWhitespace(Cursor(Source)));
598  if (C.isEOF()) {
599  Token.reset(MIToken::Eof, C.remaining());
600  return C.remaining();
601  }
602 
603  if (Cursor R = maybeLexIntegerOrScalarType(C, Token))
604  return R.remaining();
605  if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback))
606  return R.remaining();
607  if (Cursor R = maybeLexIdentifier(C, Token))
608  return R.remaining();
609  if (Cursor R = maybeLexJumpTableIndex(C, Token))
610  return R.remaining();
611  if (Cursor R = maybeLexStackObject(C, Token))
612  return R.remaining();
613  if (Cursor R = maybeLexFixedStackObject(C, Token))
614  return R.remaining();
615  if (Cursor R = maybeLexConstantPoolItem(C, Token))
616  return R.remaining();
617  if (Cursor R = maybeLexSubRegisterIndex(C, Token, ErrorCallback))
618  return R.remaining();
619  if (Cursor R = maybeLexIRBlock(C, Token, ErrorCallback))
620  return R.remaining();
621  if (Cursor R = maybeLexIRValue(C, Token, ErrorCallback))
622  return R.remaining();
623  if (Cursor R = maybeLexRegister(C, Token))
624  return R.remaining();
625  if (Cursor R = maybeLexGlobalValue(C, Token, ErrorCallback))
626  return R.remaining();
627  if (Cursor R = maybeLexExternalSymbol(C, Token, ErrorCallback))
628  return R.remaining();
629  if (Cursor R = maybeLexHexadecimalLiteral(C, Token))
630  return R.remaining();
631  if (Cursor R = maybeLexNumericalLiteral(C, Token))
632  return R.remaining();
633  if (Cursor R = maybeLexExlaim(C, Token, ErrorCallback))
634  return R.remaining();
635  if (Cursor R = maybeLexSymbol(C, Token))
636  return R.remaining();
637  if (Cursor R = maybeLexNewline(C, Token))
638  return R.remaining();
639  if (Cursor R = maybeLexEscapedIRValue(C, Token, ErrorCallback))
640  return R.remaining();
641  if (Cursor R = maybeLexStringConstant(C, Token, ErrorCallback))
642  return R.remaining();
643 
644  Token.reset(MIToken::Error, C.remaining());
645  ErrorCallback(C.location(),
646  Twine("unexpected character '") + Twine(C.peek()) + "'");
647  return C.remaining();
648 }
static Cursor maybeLexStringConstant(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:368
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:645
const NoneType None
Definition: None.h:24
static Cursor maybeLexIRBlock(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:348
static MIToken::TokenKind getMetadataKeywordKind(StringRef Identifier)
Definition: MILexer.cpp:487
static bool isRegisterChar(char C)
Returns true for a character allowed in a register name.
Definition: MILexer.cpp:388
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:23
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:89
static Cursor maybeLexEscapedIRValue(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:572
LLVM_NODISCARD char back() const
back - Get the last character in the string.
Definition: StringRef.h:149
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
StringRef::iterator location() const
Definition: MILexer.h:180
LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(const T &Value) const
Definition: StringSwitch.h:244
static bool isValidHexFloatingPointPrefix(char C)
Definition: MILexer.cpp:431
static Cursor maybeLexNumericalLiteral(Cursor C, MIToken &Token)
Definition: MILexer.cpp:473
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:435
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:406
LLVM_NODISCARD char front() const
front - Get the first character in the string.
Definition: StringRef.h:142
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
static Cursor maybeLexExternalSymbol(Cursor C, MIToken &Token, ErrorCallbackType ErrorCallback)
Definition: MILexer.cpp:423
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
bool isError() const
Definition: MILexer.h:152
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
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:598
static Cursor maybeLexNewline(Cursor C, MIToken &Token)
Definition: MILexer.cpp:563
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:376
static MIToken::TokenKind symbolToken(char C)
Definition: MILexer.cpp:516
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
MIToken & setStringValue(StringRef StrVal)
Definition: MILexer.cpp:68
static Cursor maybeLexSymbol(Cursor C, MIToken &Token)
Definition: MILexer.cpp:547
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:451
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:392
#define C
Definition: LargeTest.cpp:25
#define I(x, y, z)
Definition: MD5.cpp:58
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:496
LLVM Value Representation.
Definition: Value.h:73
static unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
Definition: StringExtras.h:55
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:128
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:49
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:417
static std::string unescapeQuotedString(StringRef Value)
Unescapes the given string value.
Definition: MILexer.cpp:112