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.
64 kw_cfi_def_cfa_register,
65 kw_cfi_def_cfa_offset,
91 // Named metadata keywords
101 MachineBasicBlockLabel,
111 FloatingPointLiteral,
124 StringRef StringValue;
125 std::string StringValueStorage;
129 MIToken() : Kind(Error) {}
131 MIToken &reset(TokenKind Kind, StringRef Range);
133 MIToken &setStringValue(StringRef StrVal);
134 MIToken &setOwnedStringValue(std::string StrVal);
135 MIToken &setIntegerValue(APSInt IntVal);
137 TokenKind kind() const { return Kind; }
139 bool isError() const { return Kind == Error; }
141 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
143 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
145 bool isRegister() const {
146 return Kind == NamedRegister || Kind == underscore ||
147 Kind == VirtualRegister;
150 bool isRegisterFlag() const {
151 return Kind == kw_implicit || Kind == kw_implicit_define ||
152 Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
153 Kind == kw_undef || Kind == kw_internal ||
154 Kind == kw_early_clobber || Kind == kw_debug_use;
157 bool isMemoryOperandFlag() const {
158 return Kind == kw_volatile || Kind == kw_non_temporal ||
159 Kind == kw_invariant;
162 bool is(TokenKind K) const { return Kind == K; }
164 bool isNot(TokenKind K) const { return Kind != K; }
166 StringRef::iterator location() const { return Range.begin(); }
168 StringRef range() const { return Range; }
170 /// Return the token's string value.
171 StringRef stringValue() const { return StringValue; }
173 const APSInt &integerValue() const { return IntVal; }
175 bool hasIntegerValue() const {
176 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
177 Kind == MachineBasicBlockLabel || Kind == StackObject ||
178 Kind == FixedStackObject || Kind == GlobalValue ||
179 Kind == VirtualRegister || Kind == ConstantPoolItem ||
180 Kind == JumpTableIndex || Kind == IRBlock || Kind == IRValue;
184 /// Consume a single machine instruction token in the given source and return
185 /// the remaining source string.
186 StringRef lexMIToken(
187 StringRef Source, MIToken &Token,
188 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
190 } // end namespace llvm