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.
78 kw_cfi_def_cfa_register,
79 kw_cfi_def_cfa_offset,
80 kw_cfi_adjust_cfa_offset,
84 kw_cfi_remember_state,
117 // Named metadata keywords
127 NamedVirtualRegister,
128 MachineBasicBlockLabel,
138 FloatingPointLiteral,
147 QuotedIRValue, // `<constant value>`
153 TokenKind Kind = Error;
155 StringRef StringValue;
156 std::string StringValueStorage;
162 MIToken &reset(TokenKind Kind, StringRef Range);
164 MIToken &setStringValue(StringRef StrVal);
165 MIToken &setOwnedStringValue(std::string StrVal);
166 MIToken &setIntegerValue(APSInt IntVal);
168 TokenKind kind() const { return Kind; }
170 bool isError() const { return Kind == Error; }
172 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
174 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
176 bool isRegister() const {
177 return Kind == NamedRegister || Kind == underscore ||
178 Kind == NamedVirtualRegister || Kind == VirtualRegister;
181 bool isRegisterFlag() const {
182 return Kind == kw_implicit || Kind == kw_implicit_define ||
183 Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
184 Kind == kw_undef || Kind == kw_internal ||
185 Kind == kw_early_clobber || Kind == kw_debug_use ||
186 Kind == kw_renamable;
189 bool isMemoryOperandFlag() const {
190 return Kind == kw_volatile || Kind == kw_non_temporal ||
191 Kind == kw_dereferenceable || Kind == kw_invariant ||
192 Kind == StringConstant;
195 bool is(TokenKind K) const { return Kind == K; }
197 bool isNot(TokenKind K) const { return Kind != K; }
199 StringRef::iterator location() const { return Range.begin(); }
201 StringRef range() const { return Range; }
203 /// Return the token's string value.
204 StringRef stringValue() const { return StringValue; }
206 const APSInt &integerValue() const { return IntVal; }
208 bool hasIntegerValue() const {
209 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
210 Kind == MachineBasicBlockLabel || Kind == StackObject ||
211 Kind == FixedStackObject || Kind == GlobalValue ||
212 Kind == VirtualRegister || Kind == ConstantPoolItem ||
213 Kind == JumpTableIndex || Kind == IRBlock || Kind == IRValue;
217 /// Consume a single machine instruction token in the given source and return
218 /// the remaining source string.
219 StringRef lexMIToken(
220 StringRef Source, MIToken &Token,
221 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
223 } // end namespace llvm
225 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H