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