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
95 MachineBasicBlockLabel,
105 FloatingPointLiteral,
117 StringRef StringValue;
118 std::string StringValueStorage;
122 MIToken() : Kind(Error) {}
124 MIToken &reset(TokenKind Kind, StringRef Range);
126 MIToken &setStringValue(StringRef StrVal);
127 MIToken &setOwnedStringValue(std::string StrVal);
128 MIToken &setIntegerValue(APSInt IntVal);
130 TokenKind kind() const { return Kind; }
132 bool isError() const { return Kind == Error; }
134 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
136 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
138 bool isRegister() const {
139 return Kind == NamedRegister || Kind == underscore ||
140 Kind == VirtualRegister;
143 bool isRegisterFlag() const {
144 return Kind == kw_implicit || Kind == kw_implicit_define ||
145 Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
146 Kind == kw_internal || Kind == kw_early_clobber ||
147 Kind == kw_debug_use;
150 bool isMemoryOperandFlag() const {
151 return Kind == kw_volatile || Kind == kw_non_temporal ||
152 Kind == kw_invariant;
155 bool is(TokenKind K) const { return Kind == K; }
157 bool isNot(TokenKind K) const { return Kind != K; }
159 StringRef::iterator location() const { return Range.begin(); }
161 StringRef range() const { return Range; }
163 /// Return the token's string value.
164 StringRef stringValue() const { return StringValue; }
166 const APSInt &integerValue() const { return IntVal; }
168 bool hasIntegerValue() const {
169 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
170 Kind == MachineBasicBlockLabel || Kind == StackObject ||
171 Kind == FixedStackObject || Kind == GlobalValue ||
172 Kind == VirtualRegister || Kind == ConstantPoolItem ||
173 Kind == JumpTableIndex || Kind == IRBlock;
177 /// Consume a single machine instruction token in the given source and return
178 /// the remaining source string.
179 StringRef lexMIToken(
180 StringRef Source, MIToken &Token,
181 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
183 } // end namespace llvm