1 //===- MILexer.h - Lexer for machine instructions ---------------*- C++ -*-===//
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 declares the function that lexes the machine instruction source
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
16 #define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
18 #include "llvm/ADT/APSInt.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/StringRef.h"
27 /// A token produced by the machine instruction lexer.
35 // Tokens with no info.
70 kw_cfi_def_cfa_register,
71 kw_cfi_def_cfa_offset,
72 kw_cfi_adjust_cfa_offset,
76 kw_cfi_remember_state,
108 // Named metadata keywords
119 MachineBasicBlockLabel,
131 FloatingPointLiteral,
140 QuotedIRValue, // `<constant value>`
146 TokenKind Kind = Error;
148 StringRef StringValue;
149 std::string StringValueStorage;
155 MIToken &reset(TokenKind Kind, StringRef Range);
157 MIToken &setStringValue(StringRef StrVal);
158 MIToken &setOwnedStringValue(std::string StrVal);
159 MIToken &setIntegerValue(APSInt IntVal);
161 TokenKind kind() const { return Kind; }
163 bool isError() const { return Kind == Error; }
165 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
167 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
169 bool isRegister() const {
170 return Kind == NamedRegister || Kind == underscore ||
171 Kind == VirtualRegister;
174 bool isRegisterFlag() const {
175 return Kind == kw_implicit || Kind == kw_implicit_define ||
176 Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
177 Kind == kw_undef || Kind == kw_internal ||
178 Kind == kw_early_clobber || Kind == kw_debug_use ||
179 Kind == kw_renamable;
182 bool isMemoryOperandFlag() const {
183 return Kind == kw_volatile || Kind == kw_non_temporal ||
184 Kind == kw_dereferenceable || Kind == kw_invariant ||
185 Kind == StringConstant;
188 bool is(TokenKind K) const { return Kind == K; }
190 bool isNot(TokenKind K) const { return Kind != K; }
192 StringRef::iterator location() const { return Range.begin(); }
194 StringRef range() const { return Range; }
196 /// Return the token's string value.
197 StringRef stringValue() const { return StringValue; }
199 const APSInt &integerValue() const { return IntVal; }
201 bool hasIntegerValue() const {
202 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
203 Kind == MachineBasicBlockLabel || Kind == StackObject ||
204 Kind == FixedStackObject || Kind == GlobalValue ||
205 Kind == VirtualRegister || Kind == ConstantPoolItem ||
206 Kind == JumpTableIndex || Kind == IRBlock || Kind == IRValue;
210 /// Consume a single machine instruction token in the given source and return
211 /// the remaining source string.
212 StringRef lexMIToken(
213 StringRef Source, MIToken &Token,
214 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
216 } // end namespace llvm
218 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H