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.
63 kw_cfi_def_cfa_register,
64 kw_cfi_def_cfa_offset,
89 // Named metadata keywords
99 MachineBasicBlockLabel,
109 FloatingPointLiteral,
121 StringRef StringValue;
122 std::string StringValueStorage;
126 MIToken() : Kind(Error) {}
128 MIToken &reset(TokenKind Kind, StringRef Range);
130 MIToken &setStringValue(StringRef StrVal);
131 MIToken &setOwnedStringValue(std::string StrVal);
132 MIToken &setIntegerValue(APSInt IntVal);
134 TokenKind kind() const { return Kind; }
136 bool isError() const { return Kind == Error; }
138 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
140 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
142 bool isRegister() const {
143 return Kind == NamedRegister || Kind == underscore ||
144 Kind == VirtualRegister;
147 bool isRegisterFlag() const {
148 return Kind == kw_implicit || Kind == kw_implicit_define ||
149 Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
150 Kind == kw_undef || Kind == kw_internal ||
151 Kind == kw_early_clobber || Kind == kw_debug_use;
154 bool isMemoryOperandFlag() const {
155 return Kind == kw_volatile || Kind == kw_non_temporal ||
156 Kind == kw_invariant;
159 bool is(TokenKind K) const { return Kind == K; }
161 bool isNot(TokenKind K) const { return Kind != K; }
163 StringRef::iterator location() const { return Range.begin(); }
165 StringRef range() const { return Range; }
167 /// Return the token's string value.
168 StringRef stringValue() const { return StringValue; }
170 const APSInt &integerValue() const { return IntVal; }
172 bool hasIntegerValue() const {
173 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
174 Kind == MachineBasicBlockLabel || Kind == StackObject ||
175 Kind == FixedStackObject || Kind == GlobalValue ||
176 Kind == VirtualRegister || Kind == ConstantPoolItem ||
177 Kind == JumpTableIndex || Kind == IRBlock;
181 /// Consume a single machine instruction token in the given source and return
182 /// the remaining source string.
183 StringRef lexMIToken(
184 StringRef Source, MIToken &Token,
185 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
187 } // end namespace llvm