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
96 MachineBasicBlockLabel,
106 FloatingPointLiteral,
118 StringRef StringValue;
119 std::string StringValueStorage;
123 MIToken() : Kind(Error) {}
125 MIToken &reset(TokenKind Kind, StringRef Range);
127 MIToken &setStringValue(StringRef StrVal);
128 MIToken &setOwnedStringValue(std::string StrVal);
129 MIToken &setIntegerValue(APSInt IntVal);
131 TokenKind kind() const { return Kind; }
133 bool isError() const { return Kind == Error; }
135 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
137 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
139 bool isRegister() const {
140 return Kind == NamedRegister || Kind == underscore ||
141 Kind == VirtualRegister;
144 bool isRegisterFlag() const {
145 return Kind == kw_implicit || Kind == kw_implicit_define ||
146 Kind == kw_dead || Kind == kw_killed || Kind == kw_undef ||
147 Kind == kw_internal || Kind == kw_early_clobber ||
148 Kind == kw_debug_use;
151 bool isMemoryOperandFlag() const {
152 return Kind == kw_volatile || Kind == kw_non_temporal ||
153 Kind == kw_invariant;
156 bool is(TokenKind K) const { return Kind == K; }
158 bool isNot(TokenKind K) const { return Kind != K; }
160 StringRef::iterator location() const { return Range.begin(); }
162 StringRef range() const { return Range; }
164 /// Return the token's string value.
165 StringRef stringValue() const { return StringValue; }
167 const APSInt &integerValue() const { return IntVal; }
169 bool hasIntegerValue() const {
170 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
171 Kind == MachineBasicBlockLabel || Kind == StackObject ||
172 Kind == FixedStackObject || Kind == GlobalValue ||
173 Kind == VirtualRegister || Kind == ConstantPoolItem ||
174 Kind == JumpTableIndex || Kind == IRBlock;
178 /// Consume a single machine instruction token in the given source and return
179 /// the remaining source string.
180 StringRef lexMIToken(
181 StringRef Source, MIToken &Token,
182 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
184 } // end namespace llvm