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,
102 StringRef StringValue;
103 std::string StringValueStorage;
107 MIToken() : Kind(Error) {}
109 MIToken &reset(TokenKind Kind, StringRef Range);
111 MIToken &setStringValue(StringRef StrVal);
112 MIToken &setOwnedStringValue(std::string StrVal);
113 MIToken &setIntegerValue(APSInt IntVal);
115 TokenKind kind() const { return Kind; }
117 bool isError() const { return Kind == Error; }
119 bool isRegister() const {
120 return Kind == NamedRegister || Kind == underscore ||
121 Kind == VirtualRegister;
124 bool isRegisterFlag() const {
125 return Kind == kw_implicit || Kind == kw_implicit_define ||
126 Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
127 Kind == kw_early_clobber || Kind == kw_debug_use;
130 bool isMemoryOperandFlag() const {
131 return Kind == kw_volatile || Kind == kw_non_temporal ||
132 Kind == kw_invariant;
135 bool is(TokenKind K) const { return Kind == K; }
137 bool isNot(TokenKind K) const { return Kind != K; }
139 StringRef::iterator location() const { return Range.begin(); }
141 StringRef range() const { return Range; }
143 /// Return the token's string value.
144 StringRef stringValue() const { return StringValue; }
146 const APSInt &integerValue() const { return IntVal; }
148 bool hasIntegerValue() const {
149 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
150 Kind == StackObject || Kind == FixedStackObject ||
151 Kind == GlobalValue || Kind == VirtualRegister ||
152 Kind == ConstantPoolItem || Kind == JumpTableIndex ||
157 /// Consume a single machine instruction token in the given source and return
158 /// the remaining source string.
159 StringRef lexMIToken(
160 StringRef Source, MIToken &Token,
161 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
163 } // end namespace llvm