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.
58 kw_cfi_def_cfa_register,
59 kw_cfi_def_cfa_offset,
88 MachineBasicBlockLabel,
110 StringRef StringValue;
111 std::string StringValueStorage;
115 MIToken() : Kind(Error) {}
117 MIToken &reset(TokenKind Kind, StringRef Range);
119 MIToken &setStringValue(StringRef StrVal);
120 MIToken &setOwnedStringValue(std::string StrVal);
121 MIToken &setIntegerValue(APSInt IntVal);
123 TokenKind kind() const { return Kind; }
125 bool isError() const { return Kind == Error; }
127 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
129 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
131 bool isRegister() const {
132 return Kind == NamedRegister || Kind == underscore ||
133 Kind == VirtualRegister;
136 bool isRegisterFlag() const {
137 return Kind == kw_implicit || Kind == kw_implicit_define ||
138 Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
139 Kind == kw_early_clobber || Kind == kw_debug_use;
142 bool isMemoryOperandFlag() const {
143 return Kind == kw_volatile || Kind == kw_non_temporal ||
144 Kind == kw_invariant;
147 bool is(TokenKind K) const { return Kind == K; }
149 bool isNot(TokenKind K) const { return Kind != K; }
151 StringRef::iterator location() const { return Range.begin(); }
153 StringRef range() const { return Range; }
155 /// Return the token's string value.
156 StringRef stringValue() const { return StringValue; }
158 const APSInt &integerValue() const { return IntVal; }
160 bool hasIntegerValue() const {
161 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
162 Kind == MachineBasicBlockLabel || Kind == StackObject ||
163 Kind == FixedStackObject || Kind == GlobalValue ||
164 Kind == VirtualRegister || Kind == ConstantPoolItem ||
165 Kind == JumpTableIndex || Kind == IRBlock;
169 /// Consume a single machine instruction token in the given source and return
170 /// the remaining source string.
171 StringRef lexMIToken(
172 StringRef Source, MIToken &Token,
173 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
175 } // end namespace llvm