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
,
118 kw_inlineasm_br_indirect_target
,
126 kw_post_instr_symbol
,
127 kw_heap_alloc_marker
,
131 kw_ir_block_address_taken
,
132 kw_machine_block_address_taken
,
137 // Named metadata keywords
148 NamedVirtualRegister
,
149 MachineBasicBlockLabel
,
160 FloatingPointLiteral
,
170 QuotedIRValue
, // `<constant value>`
176 TokenKind Kind
= Error
;
178 StringRef StringValue
;
179 std::string StringValueStorage
;
185 MIToken
&reset(TokenKind Kind
, StringRef Range
);
187 MIToken
&setStringValue(StringRef StrVal
);
188 MIToken
&setOwnedStringValue(std::string StrVal
);
189 MIToken
&setIntegerValue(APSInt IntVal
);
191 TokenKind
kind() const { return Kind
; }
193 bool isError() const { return Kind
== Error
; }
195 bool isNewlineOrEOF() const { return Kind
== Newline
|| Kind
== Eof
; }
197 bool isErrorOrEOF() const { return Kind
== Error
|| Kind
== Eof
; }
199 bool isRegister() const {
200 return Kind
== NamedRegister
|| Kind
== underscore
||
201 Kind
== NamedVirtualRegister
|| Kind
== VirtualRegister
;
204 bool isRegisterFlag() const {
205 return Kind
== kw_implicit
|| Kind
== kw_implicit_define
||
206 Kind
== kw_def
|| Kind
== kw_dead
|| Kind
== kw_killed
||
207 Kind
== kw_undef
|| Kind
== kw_internal
||
208 Kind
== kw_early_clobber
|| Kind
== kw_debug_use
||
209 Kind
== kw_renamable
;
212 bool isMemoryOperandFlag() const {
213 return Kind
== kw_volatile
|| Kind
== kw_non_temporal
||
214 Kind
== kw_dereferenceable
|| Kind
== kw_invariant
||
215 Kind
== StringConstant
;
218 bool is(TokenKind K
) const { return Kind
== K
; }
220 bool isNot(TokenKind K
) const { return Kind
!= K
; }
222 StringRef::iterator
location() const { return Range
.begin(); }
224 StringRef
range() const { return Range
; }
226 /// Return the token's string value.
227 StringRef
stringValue() const { return StringValue
; }
229 const APSInt
&integerValue() const { return IntVal
; }
231 bool hasIntegerValue() const {
232 return Kind
== IntegerLiteral
|| Kind
== MachineBasicBlock
||
233 Kind
== MachineBasicBlockLabel
|| Kind
== StackObject
||
234 Kind
== FixedStackObject
|| Kind
== GlobalValue
||
235 Kind
== VirtualRegister
|| Kind
== ConstantPoolItem
||
236 Kind
== JumpTableIndex
|| Kind
== IRBlock
|| Kind
== IRValue
;
240 /// Consume a single machine instruction token in the given source and return
241 /// the remaining source string.
242 StringRef
lexMIToken(
243 StringRef Source
, MIToken
&Token
,
244 function_ref
<void(StringRef::iterator
, const Twine
&)> ErrorCallback
);
246 } // end namespace llvm
248 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H