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/STLExtras.h"
19 #include "llvm/ADT/StringRef.h"
26 /// A token produced by the machine instruction lexer.
34 // Tokens with no info.
81 kw_cfi_def_cfa_register
,
82 kw_cfi_def_cfa_offset
,
83 kw_cfi_adjust_cfa_offset
,
87 kw_cfi_remember_state
,
92 kw_cfi_aarch64_negate_ra_sign_state
,
122 kw_post_instr_symbol
,
125 // Named metadata keywords
136 NamedVirtualRegister
,
137 MachineBasicBlockLabel
,
148 FloatingPointLiteral
,
158 QuotedIRValue
, // `<constant value>`
164 TokenKind Kind
= Error
;
166 StringRef StringValue
;
167 std::string StringValueStorage
;
173 MIToken
&reset(TokenKind Kind
, StringRef Range
);
175 MIToken
&setStringValue(StringRef StrVal
);
176 MIToken
&setOwnedStringValue(std::string StrVal
);
177 MIToken
&setIntegerValue(APSInt IntVal
);
179 TokenKind
kind() const { return Kind
; }
181 bool isError() const { return Kind
== Error
; }
183 bool isNewlineOrEOF() const { return Kind
== Newline
|| Kind
== Eof
; }
185 bool isErrorOrEOF() const { return Kind
== Error
|| Kind
== Eof
; }
187 bool isRegister() const {
188 return Kind
== NamedRegister
|| Kind
== underscore
||
189 Kind
== NamedVirtualRegister
|| Kind
== VirtualRegister
;
192 bool isRegisterFlag() const {
193 return Kind
== kw_implicit
|| Kind
== kw_implicit_define
||
194 Kind
== kw_def
|| Kind
== kw_dead
|| Kind
== kw_killed
||
195 Kind
== kw_undef
|| Kind
== kw_internal
||
196 Kind
== kw_early_clobber
|| Kind
== kw_debug_use
||
197 Kind
== kw_renamable
;
200 bool isMemoryOperandFlag() const {
201 return Kind
== kw_volatile
|| Kind
== kw_non_temporal
||
202 Kind
== kw_dereferenceable
|| Kind
== kw_invariant
||
203 Kind
== StringConstant
;
206 bool is(TokenKind K
) const { return Kind
== K
; }
208 bool isNot(TokenKind K
) const { return Kind
!= K
; }
210 StringRef::iterator
location() const { return Range
.begin(); }
212 StringRef
range() const { return Range
; }
214 /// Return the token's string value.
215 StringRef
stringValue() const { return StringValue
; }
217 const APSInt
&integerValue() const { return IntVal
; }
219 bool hasIntegerValue() const {
220 return Kind
== IntegerLiteral
|| Kind
== MachineBasicBlock
||
221 Kind
== MachineBasicBlockLabel
|| Kind
== StackObject
||
222 Kind
== FixedStackObject
|| Kind
== GlobalValue
||
223 Kind
== VirtualRegister
|| Kind
== ConstantPoolItem
||
224 Kind
== JumpTableIndex
|| Kind
== IRBlock
|| Kind
== IRValue
;
228 /// Consume a single machine instruction token in the given source and return
229 /// the remaining source string.
230 StringRef
lexMIToken(
231 StringRef Source
, MIToken
&Token
,
232 function_ref
<void(StringRef::iterator
, const Twine
&)> ErrorCallback
);
234 } // end namespace llvm
236 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H