1 //===- MILexer.h - Lexer for machine instructions ---------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file declares the function that lexes the machine instruction source
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
15 #define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
17 #include "llvm/ADT/APSInt.h"
18 #include "llvm/ADT/StringRef.h"
25 /// A token produced by the machine instruction lexer.
33 // Tokens with no info.
77 kw_debug_instr_number
,
81 kw_cfi_def_cfa_register
,
82 kw_cfi_def_cfa_offset
,
83 kw_cfi_adjust_cfa_offset
,
86 kw_cfi_llvm_def_aspace_cfa
,
88 kw_cfi_remember_state
,
93 kw_cfi_aarch64_negate_ra_sign_state
,
119 kw_inlineasm_br_indirect_target
,
127 kw_post_instr_symbol
,
128 kw_heap_alloc_marker
,
136 // Named metadata keywords
147 NamedVirtualRegister
,
148 MachineBasicBlockLabel
,
159 FloatingPointLiteral
,
169 QuotedIRValue
, // `<constant value>`
175 TokenKind Kind
= Error
;
177 StringRef StringValue
;
178 std::string StringValueStorage
;
184 MIToken
&reset(TokenKind Kind
, StringRef Range
);
186 MIToken
&setStringValue(StringRef StrVal
);
187 MIToken
&setOwnedStringValue(std::string StrVal
);
188 MIToken
&setIntegerValue(APSInt IntVal
);
190 TokenKind
kind() const { return Kind
; }
192 bool isError() const { return Kind
== Error
; }
194 bool isNewlineOrEOF() const { return Kind
== Newline
|| Kind
== Eof
; }
196 bool isErrorOrEOF() const { return Kind
== Error
|| Kind
== Eof
; }
198 bool isRegister() const {
199 return Kind
== NamedRegister
|| Kind
== underscore
||
200 Kind
== NamedVirtualRegister
|| Kind
== VirtualRegister
;
203 bool isRegisterFlag() const {
204 return Kind
== kw_implicit
|| Kind
== kw_implicit_define
||
205 Kind
== kw_def
|| Kind
== kw_dead
|| Kind
== kw_killed
||
206 Kind
== kw_undef
|| Kind
== kw_internal
||
207 Kind
== kw_early_clobber
|| Kind
== kw_debug_use
||
208 Kind
== kw_renamable
;
211 bool isMemoryOperandFlag() const {
212 return Kind
== kw_volatile
|| Kind
== kw_non_temporal
||
213 Kind
== kw_dereferenceable
|| Kind
== kw_invariant
||
214 Kind
== StringConstant
;
217 bool is(TokenKind K
) const { return Kind
== K
; }
219 bool isNot(TokenKind K
) const { return Kind
!= K
; }
221 StringRef::iterator
location() const { return Range
.begin(); }
223 StringRef
range() const { return Range
; }
225 /// Return the token's string value.
226 StringRef
stringValue() const { return StringValue
; }
228 const APSInt
&integerValue() const { return IntVal
; }
230 bool hasIntegerValue() const {
231 return Kind
== IntegerLiteral
|| Kind
== MachineBasicBlock
||
232 Kind
== MachineBasicBlockLabel
|| Kind
== StackObject
||
233 Kind
== FixedStackObject
|| Kind
== GlobalValue
||
234 Kind
== VirtualRegister
|| Kind
== ConstantPoolItem
||
235 Kind
== JumpTableIndex
|| Kind
== IRBlock
|| Kind
== IRValue
;
239 /// Consume a single machine instruction token in the given source and return
240 /// the remaining source string.
241 StringRef
lexMIToken(
242 StringRef Source
, MIToken
&Token
,
243 function_ref
<void(StringRef::iterator
, const Twine
&)> ErrorCallback
);
245 } // end namespace llvm
247 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H