1 //===- MILexer.h - Lexer for machine instructions -------------------------===//
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/StringRef.h"
20 #include "llvm/ADT/STLExtras.h"
27 /// A token produced by the machine instruction lexer.
35 // Tokens with no info.
60 kw_cfi_def_cfa_register,
61 kw_cfi_def_cfa_offset,
90 MachineBasicBlockLabel,
100 FloatingPointLiteral,
112 StringRef StringValue;
113 std::string StringValueStorage;
117 MIToken() : Kind(Error) {}
119 MIToken &reset(TokenKind Kind, StringRef Range);
121 MIToken &setStringValue(StringRef StrVal);
122 MIToken &setOwnedStringValue(std::string StrVal);
123 MIToken &setIntegerValue(APSInt IntVal);
125 TokenKind kind() const { return Kind; }
127 bool isError() const { return Kind == Error; }
129 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
131 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
133 bool isRegister() const {
134 return Kind == NamedRegister || Kind == underscore ||
135 Kind == VirtualRegister;
138 bool isRegisterFlag() const {
139 return Kind == kw_implicit || Kind == kw_implicit_define ||
140 Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
141 Kind == kw_early_clobber || Kind == kw_debug_use;
144 bool isMemoryOperandFlag() const {
145 return Kind == kw_volatile || Kind == kw_non_temporal ||
146 Kind == kw_invariant;
149 bool is(TokenKind K) const { return Kind == K; }
151 bool isNot(TokenKind K) const { return Kind != K; }
153 StringRef::iterator location() const { return Range.begin(); }
155 StringRef range() const { return Range; }
157 /// Return the token's string value.
158 StringRef stringValue() const { return StringValue; }
160 const APSInt &integerValue() const { return IntVal; }
162 bool hasIntegerValue() const {
163 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
164 Kind == MachineBasicBlockLabel || Kind == StackObject ||
165 Kind == FixedStackObject || Kind == GlobalValue ||
166 Kind == VirtualRegister || Kind == ConstantPoolItem ||
167 Kind == JumpTableIndex || Kind == IRBlock;
171 /// Consume a single machine instruction token in the given source and return
172 /// the remaining source string.
173 StringRef lexMIToken(
174 StringRef Source, MIToken &Token,
175 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
177 } // end namespace llvm