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.
81 kw_debug_instr_number
,
86 kw_cfi_def_cfa_register
,
87 kw_cfi_def_cfa_offset
,
88 kw_cfi_adjust_cfa_offset
,
91 kw_cfi_llvm_def_aspace_cfa
,
93 kw_cfi_remember_state
,
98 kw_cfi_aarch64_negate_ra_sign_state
,
124 kw_inlineasm_br_indirect_target
,
132 kw_post_instr_symbol
,
133 kw_heap_alloc_marker
,
140 kw_ir_block_address_taken
,
141 kw_machine_block_address_taken
,
148 // Named metadata keywords
159 NamedVirtualRegister
,
160 MachineBasicBlockLabel
,
171 FloatingPointLiteral
,
181 QuotedIRValue
, // `<constant value>`
187 TokenKind Kind
= Error
;
189 StringRef StringValue
;
190 std::string StringValueStorage
;
196 MIToken
&reset(TokenKind Kind
, StringRef Range
);
198 MIToken
&setStringValue(StringRef StrVal
);
199 MIToken
&setOwnedStringValue(std::string StrVal
);
200 MIToken
&setIntegerValue(APSInt IntVal
);
202 TokenKind
kind() const { return Kind
; }
204 bool isError() const { return Kind
== Error
; }
206 bool isNewlineOrEOF() const { return Kind
== Newline
|| Kind
== Eof
; }
208 bool isErrorOrEOF() const { return Kind
== Error
|| Kind
== Eof
; }
210 bool isRegister() const {
211 return Kind
== NamedRegister
|| Kind
== underscore
||
212 Kind
== NamedVirtualRegister
|| Kind
== VirtualRegister
;
215 bool isRegisterFlag() const {
216 return Kind
== kw_implicit
|| Kind
== kw_implicit_define
||
217 Kind
== kw_def
|| Kind
== kw_dead
|| Kind
== kw_killed
||
218 Kind
== kw_undef
|| Kind
== kw_internal
||
219 Kind
== kw_early_clobber
|| Kind
== kw_debug_use
||
220 Kind
== kw_renamable
;
223 bool isMemoryOperandFlag() const {
224 return Kind
== kw_volatile
|| Kind
== kw_non_temporal
||
225 Kind
== kw_dereferenceable
|| Kind
== kw_invariant
||
226 Kind
== StringConstant
;
229 bool is(TokenKind K
) const { return Kind
== K
; }
231 bool isNot(TokenKind K
) const { return Kind
!= K
; }
233 StringRef::iterator
location() const { return Range
.begin(); }
235 StringRef
range() const { return Range
; }
237 /// Return the token's string value.
238 StringRef
stringValue() const { return StringValue
; }
240 const APSInt
&integerValue() const { return IntVal
; }
242 bool hasIntegerValue() const {
243 return Kind
== IntegerLiteral
|| Kind
== MachineBasicBlock
||
244 Kind
== MachineBasicBlockLabel
|| Kind
== StackObject
||
245 Kind
== FixedStackObject
|| Kind
== GlobalValue
||
246 Kind
== VirtualRegister
|| Kind
== ConstantPoolItem
||
247 Kind
== JumpTableIndex
|| Kind
== IRBlock
|| Kind
== IRValue
;
251 /// Consume a single machine instruction token in the given source and return
252 /// the remaining source string.
253 StringRef
lexMIToken(
254 StringRef Source
, MIToken
&Token
,
255 function_ref
<void(StringRef::iterator
, const Twine
&)> ErrorCallback
);
257 } // end namespace llvm
259 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H