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.
64 kw_cfi_def_cfa_register,
65 kw_cfi_def_cfa_offset,
91 // Named metadata keywords
101 MachineBasicBlockLabel,
111 FloatingPointLiteral,
119 QuotedIRValue // `<constant value>`
125 StringRef StringValue;
126 std::string StringValueStorage;
130 MIToken() : Kind(Error) {}
132 MIToken &reset(TokenKind Kind, StringRef Range);
134 MIToken &setStringValue(StringRef StrVal);
135 MIToken &setOwnedStringValue(std::string StrVal);
136 MIToken &setIntegerValue(APSInt IntVal);
138 TokenKind kind() const { return Kind; }
140 bool isError() const { return Kind == Error; }
142 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
144 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
146 bool isRegister() const {
147 return Kind == NamedRegister || Kind == underscore ||
148 Kind == VirtualRegister;
151 bool isRegisterFlag() const {
152 return Kind == kw_implicit || Kind == kw_implicit_define ||
153 Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
154 Kind == kw_undef || Kind == kw_internal ||
155 Kind == kw_early_clobber || Kind == kw_debug_use;
158 bool isMemoryOperandFlag() const {
159 return Kind == kw_volatile || Kind == kw_non_temporal ||
160 Kind == kw_invariant;
163 bool is(TokenKind K) const { return Kind == K; }
165 bool isNot(TokenKind K) const { return Kind != K; }
167 StringRef::iterator location() const { return Range.begin(); }
169 StringRef range() const { return Range; }
171 /// Return the token's string value.
172 StringRef stringValue() const { return StringValue; }
174 const APSInt &integerValue() const { return IntVal; }
176 bool hasIntegerValue() const {
177 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
178 Kind == MachineBasicBlockLabel || Kind == StackObject ||
179 Kind == FixedStackObject || Kind == GlobalValue ||
180 Kind == VirtualRegister || Kind == ConstantPoolItem ||
181 Kind == JumpTableIndex || Kind == IRBlock || Kind == IRValue;
185 /// Consume a single machine instruction token in the given source and return
186 /// the remaining source string.
187 StringRef lexMIToken(
188 StringRef Source, MIToken &Token,
189 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
191 } // end namespace llvm