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.
62 kw_cfi_def_cfa_register,
63 kw_cfi_def_cfa_offset,
88 // Named metadata keywords
98 MachineBasicBlockLabel,
108 FloatingPointLiteral,
120 StringRef StringValue;
121 std::string StringValueStorage;
125 MIToken() : Kind(Error) {}
127 MIToken &reset(TokenKind Kind, StringRef Range);
129 MIToken &setStringValue(StringRef StrVal);
130 MIToken &setOwnedStringValue(std::string StrVal);
131 MIToken &setIntegerValue(APSInt IntVal);
133 TokenKind kind() const { return Kind; }
135 bool isError() const { return Kind == Error; }
137 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
139 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
141 bool isRegister() const {
142 return Kind == NamedRegister || Kind == underscore ||
143 Kind == VirtualRegister;
146 bool isRegisterFlag() const {
147 return Kind == kw_implicit || Kind == kw_implicit_define ||
148 Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
149 Kind == kw_internal || Kind == kw_early_clobber ||
150 Kind == kw_debug_use;
153 bool isMemoryOperandFlag() const {
154 return Kind == kw_volatile || Kind == kw_non_temporal ||
155 Kind == kw_invariant;
158 bool is(TokenKind K) const { return Kind == K; }
160 bool isNot(TokenKind K) const { return Kind != K; }
162 StringRef::iterator location() const { return Range.begin(); }
164 StringRef range() const { return Range; }
166 /// Return the token's string value.
167 StringRef stringValue() const { return StringValue; }
169 const APSInt &integerValue() const { return IntVal; }
171 bool hasIntegerValue() const {
172 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
173 Kind == MachineBasicBlockLabel || Kind == StackObject ||
174 Kind == FixedStackObject || Kind == GlobalValue ||
175 Kind == VirtualRegister || Kind == ConstantPoolItem ||
176 Kind == JumpTableIndex || Kind == IRBlock;
180 /// Consume a single machine instruction token in the given source and return
181 /// the remaining source string.
182 StringRef lexMIToken(
183 StringRef Source, MIToken &Token,
184 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
186 } // end namespace llvm