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.
34 // Tokens with no info.
57 kw_cfi_def_cfa_register,
58 kw_cfi_def_cfa_offset,
99 StringRef StringValue;
100 std::string StringValueStorage;
104 MIToken() : Kind(Error) {}
106 MIToken &reset(TokenKind Kind, StringRef Range);
108 MIToken &setStringValue(StringRef StrVal);
109 MIToken &setOwnedStringValue(std::string StrVal);
110 MIToken &setIntegerValue(APSInt IntVal);
112 TokenKind kind() const { return Kind; }
114 bool isError() const { return Kind == Error; }
116 bool isRegister() const {
117 return Kind == NamedRegister || Kind == underscore ||
118 Kind == VirtualRegister;
121 bool isRegisterFlag() const {
122 return Kind == kw_implicit || Kind == kw_implicit_define ||
123 Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
124 Kind == kw_early_clobber || Kind == kw_debug_use;
127 bool isMemoryOperandFlag() const {
128 return Kind == kw_volatile || Kind == kw_non_temporal ||
129 Kind == kw_invariant;
132 bool is(TokenKind K) const { return Kind == K; }
134 bool isNot(TokenKind K) const { return Kind != K; }
136 StringRef::iterator location() const { return Range.begin(); }
138 StringRef range() const { return Range; }
140 /// Return the token's string value.
141 StringRef stringValue() const { return StringValue; }
143 const APSInt &integerValue() const { return IntVal; }
145 bool hasIntegerValue() const {
146 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
147 Kind == StackObject || Kind == FixedStackObject ||
148 Kind == GlobalValue || Kind == VirtualRegister ||
149 Kind == ConstantPoolItem || Kind == JumpTableIndex ||
154 /// Consume a single machine instruction token in the given source and return
155 /// the remaining source string.
156 StringRef lexMIToken(
157 StringRef Source, MIToken &Token,
158 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
160 } // end namespace llvm