LLVM  8.0.1
MILexer.h
Go to the documentation of this file.
1 //===- MILexer.h - Lexer for machine instructions ---------------*- C++ -*-===//
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 declares the function that lexes the machine instruction source
11 // string.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
16 #define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
17 
18 #include "llvm/ADT/APSInt.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/StringRef.h"
21 #include <string>
22 
23 namespace llvm {
24 
25 class Twine;
26 
27 /// A token produced by the machine instruction lexer.
28 struct MIToken {
29  enum TokenKind {
30  // Markers
31  Eof,
34 
35  // Tokens with no info.
41  dot,
51 
52  // Keywords
123 
124  // Named metadata keywords
131 
132  // Identifier tokens
144 
145  // Other tokens
156  QuotedIRValue, // `<constant value>`
159  };
160 
161 private:
162  TokenKind Kind = Error;
163  StringRef Range;
164  StringRef StringValue;
165  std::string StringValueStorage;
166  APSInt IntVal;
167 
168 public:
169  MIToken() = default;
170 
171  MIToken &reset(TokenKind Kind, StringRef Range);
172 
174  MIToken &setOwnedStringValue(std::string StrVal);
175  MIToken &setIntegerValue(APSInt IntVal);
176 
177  TokenKind kind() const { return Kind; }
178 
179  bool isError() const { return Kind == Error; }
180 
181  bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
182 
183  bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
184 
185  bool isRegister() const {
186  return Kind == NamedRegister || Kind == underscore ||
187  Kind == NamedVirtualRegister || Kind == VirtualRegister;
188  }
189 
190  bool isRegisterFlag() const {
191  return Kind == kw_implicit || Kind == kw_implicit_define ||
192  Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
193  Kind == kw_undef || Kind == kw_internal ||
194  Kind == kw_early_clobber || Kind == kw_debug_use ||
195  Kind == kw_renamable;
196  }
197 
198  bool isMemoryOperandFlag() const {
199  return Kind == kw_volatile || Kind == kw_non_temporal ||
200  Kind == kw_dereferenceable || Kind == kw_invariant ||
201  Kind == StringConstant;
202  }
203 
204  bool is(TokenKind K) const { return Kind == K; }
205 
206  bool isNot(TokenKind K) const { return Kind != K; }
207 
208  StringRef::iterator location() const { return Range.begin(); }
209 
210  StringRef range() const { return Range; }
211 
212  /// Return the token's string value.
213  StringRef stringValue() const { return StringValue; }
214 
215  const APSInt &integerValue() const { return IntVal; }
216 
217  bool hasIntegerValue() const {
218  return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
219  Kind == MachineBasicBlockLabel || Kind == StackObject ||
220  Kind == FixedStackObject || Kind == GlobalValue ||
221  Kind == VirtualRegister || Kind == ConstantPoolItem ||
222  Kind == JumpTableIndex || Kind == IRBlock || Kind == IRValue;
223  }
224 };
225 
226 /// Consume a single machine instruction token in the given source and return
227 /// the remaining source string.
229  StringRef Source, MIToken &Token,
230  function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
231 
232 } // end namespace llvm
233 
234 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
StringRef stringValue() const
Return the token&#39;s string value.
Definition: MILexer.h:213
bool is(TokenKind K) const
Definition: MILexer.h:204
bool isError() const
Definition: MILexer.h:179
This class represents lattice values for constants.
Definition: AllocatorList.h:24
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:117
bool isMemoryOperandFlag() const
Definition: MILexer.h:198
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:68
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
bool isNot(TokenKind K) const
Definition: MILexer.h:206
bool isNewlineOrEOF() const
Definition: MILexer.h:181
const APSInt & integerValue() const
Definition: MILexer.h:215
MIToken & setOwnedStringValue(std::string StrVal)
Definition: MILexer.cpp:79
bool isErrorOrEOF() const
Definition: MILexer.h:183
MIToken()=default
bool hasIntegerValue() const
Definition: MILexer.h:217
TokenKind kind() const
Definition: MILexer.h:177
MIToken & setStringValue(StringRef StrVal)
Definition: MILexer.cpp:74
StringRef range() const
Definition: MILexer.h:210
StringRef::iterator location() const
Definition: MILexer.h:208
iterator begin() const
Definition: StringRef.h:106
bool isRegisterFlag() const
Definition: MILexer.h:190
bool isRegister() const
Definition: MILexer.h:185
A token produced by the machine instruction lexer.
Definition: MILexer.h:28
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MIToken & setIntegerValue(APSInt IntVal)
Definition: MILexer.cpp:85