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.
61 kw_cfi_def_cfa_register,
62 kw_cfi_def_cfa_offset,
91 MachineBasicBlockLabel,
101 FloatingPointLiteral,
113 StringRef StringValue;
114 std::string StringValueStorage;
118 MIToken() : Kind(Error) {}
120 MIToken &reset(TokenKind Kind, StringRef Range);
122 MIToken &setStringValue(StringRef StrVal);
123 MIToken &setOwnedStringValue(std::string StrVal);
124 MIToken &setIntegerValue(APSInt IntVal);
126 TokenKind kind() const { return Kind; }
128 bool isError() const { return Kind == Error; }
130 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
132 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
134 bool isRegister() const {
135 return Kind == NamedRegister || Kind == underscore ||
136 Kind == VirtualRegister;
139 bool isRegisterFlag() const {
140 return Kind == kw_implicit || Kind == kw_implicit_define ||
141 Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
142 Kind == kw_internal || Kind == kw_early_clobber ||
143 Kind == kw_debug_use;
146 bool isMemoryOperandFlag() const {
147 return Kind == kw_volatile || Kind == kw_non_temporal ||
148 Kind == kw_invariant;
151 bool is(TokenKind K) const { return Kind == K; }
153 bool isNot(TokenKind K) const { return Kind != K; }
155 StringRef::iterator location() const { return Range.begin(); }
157 StringRef range() const { return Range; }
159 /// Return the token's string value.
160 StringRef stringValue() const { return StringValue; }
162 const APSInt &integerValue() const { return IntVal; }
164 bool hasIntegerValue() const {
165 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
166 Kind == MachineBasicBlockLabel || Kind == StackObject ||
167 Kind == FixedStackObject || Kind == GlobalValue ||
168 Kind == VirtualRegister || Kind == ConstantPoolItem ||
169 Kind == JumpTableIndex || Kind == IRBlock;
173 /// Consume a single machine instruction token in the given source and return
174 /// the remaining source string.
175 StringRef lexMIToken(
176 StringRef Source, MIToken &Token,
177 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
179 } // end namespace llvm