LLVM 19.0.0git
MILexer.h
Go to the documentation of this file.
1//===- MILexer.h - Lexer for machine instructions ---------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the function that lexes the machine instruction source
10// string.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
15#define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
16
17#include "llvm/ADT/APSInt.h"
18#include "llvm/ADT/StringRef.h"
19#include <string>
20
21namespace llvm {
22
23class Twine;
24
25/// A token produced by the machine instruction lexer.
26struct MIToken {
27 enum TokenKind {
28 // Markers
32
33 // Tokens with no info.
49
50 // Keywords
143
144 // Metadata types.
146
147 // Named metadata keywords
154
155 // Identifier tokens
167
168 // Other tokens
180 QuotedIRValue, // `<constant value>`
183 };
184
185private:
186 TokenKind Kind = Error;
187 StringRef Range;
188 StringRef StringValue;
189 std::string StringValueStorage;
190 APSInt IntVal;
191
192public:
193 MIToken() = default;
194
195 MIToken &reset(TokenKind Kind, StringRef Range);
196
198 MIToken &setOwnedStringValue(std::string StrVal);
200
201 TokenKind kind() const { return Kind; }
202
203 bool isError() const { return Kind == Error; }
204
205 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
206
207 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
208
209 bool isRegister() const {
210 return Kind == NamedRegister || Kind == underscore ||
211 Kind == NamedVirtualRegister || Kind == VirtualRegister;
212 }
213
214 bool isRegisterFlag() const {
215 return Kind == kw_implicit || Kind == kw_implicit_define ||
216 Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
217 Kind == kw_undef || Kind == kw_internal ||
218 Kind == kw_early_clobber || Kind == kw_debug_use ||
219 Kind == kw_renamable;
220 }
221
222 bool isMemoryOperandFlag() const {
223 return Kind == kw_volatile || Kind == kw_non_temporal ||
224 Kind == kw_dereferenceable || Kind == kw_invariant ||
225 Kind == StringConstant;
226 }
227
228 bool is(TokenKind K) const { return Kind == K; }
229
230 bool isNot(TokenKind K) const { return Kind != K; }
231
232 StringRef::iterator location() const { return Range.begin(); }
233
234 StringRef range() const { return Range; }
235
236 /// Return the token's string value.
237 StringRef stringValue() const { return StringValue; }
238
239 const APSInt &integerValue() const { return IntVal; }
240
241 bool hasIntegerValue() const {
242 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
243 Kind == MachineBasicBlockLabel || Kind == StackObject ||
244 Kind == FixedStackObject || Kind == GlobalValue ||
245 Kind == VirtualRegister || Kind == ConstantPoolItem ||
246 Kind == JumpTableIndex || Kind == IRBlock || Kind == IRValue;
247 }
248};
249
250/// Consume a single machine instruction token in the given source and return
251/// the remaining source string.
253 StringRef Source, MIToken &Token,
254 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
255
256} // end namespace llvm
257
258#endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
An arbitrary precision integer that knows its signedness.
Definition: APSInt.h:23
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
StringRef lexMIToken(StringRef Source, MIToken &Token, function_ref< void(StringRef::iterator, const Twine &)> ErrorCallback)
Consume a single machine instruction token in the given source and return the remaining source string...
A token produced by the machine instruction lexer.
Definition: MILexer.h:26
bool isRegisterFlag() const
Definition: MILexer.h:214
MIToken & setStringValue(StringRef StrVal)
Definition: MILexer.cpp:68
TokenKind kind() const
Definition: MILexer.h:201
bool isNewlineOrEOF() const
Definition: MILexer.h:205
bool hasIntegerValue() const
Definition: MILexer.h:241
bool isNot(TokenKind K) const
Definition: MILexer.h:230
bool is(TokenKind K) const
Definition: MILexer.h:228
MIToken()=default
bool isMemoryOperandFlag() const
Definition: MILexer.h:222
StringRef stringValue() const
Return the token's string value.
Definition: MILexer.h:237
@ kw_target_flags
Definition: MILexer.h:108
@ kw_landing_pad
Definition: MILexer.h:122
@ kw_blockaddress
Definition: MILexer.h:99
@ kw_pre_instr_symbol
Definition: MILexer.h:130
@ md_alias_scope
Definition: MILexer.h:149
@ NamedGlobalValue
Definition: MILexer.h:163
@ kw_call_frame_size
Definition: MILexer.h:141
@ SubRegisterIndex
Definition: MILexer.h:181
@ kw_frame_setup
Definition: MILexer.h:63
@ kw_cfi_aarch64_negate_ra_sign_state
Definition: MILexer.h:98
@ ConstantPoolItem
Definition: MILexer.h:174
@ kw_cfi_llvm_def_aspace_cfa
Definition: MILexer.h:91
@ MachineBasicBlock
Definition: MILexer.h:160
@ kw_dbg_instr_ref
Definition: MILexer.h:82
@ NamedVirtualRegister
Definition: MILexer.h:158
@ kw_early_clobber
Definition: MILexer.h:59
@ kw_cfi_offset
Definition: MILexer.h:84
@ kw_unpredictable
Definition: MILexer.h:77
@ FloatingPointLiteral
Definition: MILexer.h:170
@ kw_debug_use
Definition: MILexer.h:60
@ kw_cfi_window_save
Definition: MILexer.h:97
@ kw_constant_pool
Definition: MILexer.h:118
@ kw_frame_destroy
Definition: MILexer.h:64
@ kw_cfi_undefined
Definition: MILexer.h:96
@ StringConstant
Definition: MILexer.h:182
@ MachineBasicBlockLabel
Definition: MILexer.h:159
@ kw_cfi_restore
Definition: MILexer.h:94
@ kw_non_temporal
Definition: MILexer.h:110
@ kw_cfi_register
Definition: MILexer.h:92
@ kw_inlineasm_br_indirect_target
Definition: MILexer.h:123
@ kw_cfi_rel_offset
Definition: MILexer.h:85
@ kw_ehfunclet_entry
Definition: MILexer.h:124
@ kw_cfi_def_cfa_register
Definition: MILexer.h:86
@ FixedStackObject
Definition: MILexer.h:162
@ kw_cfi_same_value
Definition: MILexer.h:83
@ kw_target_index
Definition: MILexer.h:101
@ kw_cfi_adjust_cfa_offset
Definition: MILexer.h:88
@ kw_dereferenceable
Definition: MILexer.h:55
@ kw_implicit_define
Definition: MILexer.h:52
@ kw_cfi_def_cfa
Definition: MILexer.h:90
@ kw_cfi_escape
Definition: MILexer.h:89
@ VirtualRegister
Definition: MILexer.h:173
@ kw_cfi_def_cfa_offset
Definition: MILexer.h:87
@ kw_machine_block_address_taken
Definition: MILexer.h:140
@ kw_renamable
Definition: MILexer.h:61
@ ExternalSymbol
Definition: MILexer.h:165
@ kw_unknown_size
Definition: MILexer.h:137
@ IntegerLiteral
Definition: MILexer.h:169
@ kw_cfi_remember_state
Definition: MILexer.h:93
@ kw_debug_instr_number
Definition: MILexer.h:81
@ kw_post_instr_symbol
Definition: MILexer.h:131
@ kw_cfi_restore_state
Definition: MILexer.h:95
@ kw_nofpexcept
Definition: MILexer.h:76
@ kw_ir_block_address_taken
Definition: MILexer.h:139
@ kw_unknown_address
Definition: MILexer.h:138
@ JumpTableIndex
Definition: MILexer.h:175
@ kw_shufflemask
Definition: MILexer.h:129
@ kw_debug_location
Definition: MILexer.h:80
@ kw_noconvergent
Definition: MILexer.h:142
@ kw_heap_alloc_marker
Definition: MILexer.h:132
StringRef range() const
Definition: MILexer.h:234
bool isRegister() const
Definition: MILexer.h:209
MIToken & setIntegerValue(APSInt IntVal)
Definition: MILexer.cpp:79
bool isErrorOrEOF() const
Definition: MILexer.h:207
MIToken & reset(TokenKind Kind, StringRef Range)
Definition: MILexer.cpp:62
bool isError() const
Definition: MILexer.h:203
MIToken & setOwnedStringValue(std::string StrVal)
Definition: MILexer.cpp:73
StringRef::iterator location() const
Definition: MILexer.h:232
const APSInt & integerValue() const
Definition: MILexer.h:239