LLVM 24.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
158
159 // Metadata types.
161
162 // Named metadata keywords
171
172 // Identifier tokens
184
185 // Other tokens
197 QuotedIRValue, // `<constant value>`
200 };
201
202private:
203 TokenKind Kind = Error;
205 StringRef StringValue;
206 std::string StringValueStorage;
207 APSInt IntVal;
208
209public:
210 MIToken() = default;
211
212 MIToken &reset(TokenKind Kind, StringRef Range);
213
215 MIToken &setOwnedStringValue(std::string StrVal);
217
218 TokenKind kind() const { return Kind; }
219
220 bool isError() const { return Kind == Error; }
221
222 bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
223
224 bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
225
226 bool isRegister() const {
227 return Kind == NamedRegister || Kind == underscore ||
228 Kind == NamedVirtualRegister || Kind == VirtualRegister;
229 }
230
231 bool isRegisterFlag() const {
232 return Kind == kw_implicit || Kind == kw_implicit_define ||
233 Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
234 Kind == kw_undef || Kind == kw_internal ||
235 Kind == kw_early_clobber || Kind == kw_debug_use ||
236 Kind == kw_renamable;
237 }
238
239 bool isMemoryOperandFlag() const {
240 return Kind == kw_volatile || Kind == kw_non_temporal ||
241 Kind == kw_dereferenceable || Kind == kw_invariant ||
242 Kind == StringConstant;
243 }
244
245 bool is(TokenKind K) const { return Kind == K; }
246
247 bool isNot(TokenKind K) const { return Kind != K; }
248
249 StringRef::iterator location() const { return Range.begin(); }
250
251 StringRef range() const { return Range; }
252
253 /// Return the token's string value.
254 StringRef stringValue() const { return StringValue; }
255
256 const APSInt &integerValue() const { return IntVal; }
257
258 bool hasIntegerValue() const {
259 return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
260 Kind == MachineBasicBlockLabel || Kind == StackObject ||
261 Kind == FixedStackObject || Kind == GlobalValue ||
262 Kind == VirtualRegister || Kind == ConstantPoolItem ||
263 Kind == JumpTableIndex || Kind == IRBlock || Kind == IRValue;
264 }
265};
266
267/// Consume a single machine instruction token in the given source and return
268/// the remaining source string.
270 StringRef Source, MIToken &Token,
271 function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
272
273} // end namespace llvm
274
275#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:24
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
const char * iterator
Definition StringRef.h:60
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
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:231
MIToken & setStringValue(StringRef StrVal)
Definition MILexer.cpp:68
TokenKind kind() const
Definition MILexer.h:218
bool isNewlineOrEOF() const
Definition MILexer.h:222
bool hasIntegerValue() const
Definition MILexer.h:258
bool isNot(TokenKind K) const
Definition MILexer.h:247
bool is(TokenKind K) const
Definition MILexer.h:245
MIToken()=default
bool isMemoryOperandFlag() const
Definition MILexer.h:239
StringRef stringValue() const
Return the token's string value.
Definition MILexer.h:254
@ kw_pre_instr_symbol
Definition MILexer.h:142
@ kw_deactivation_symbol
Definition MILexer.h:147
@ kw_call_frame_size
Definition MILexer.h:154
@ kw_cfi_aarch64_negate_ra_sign_state
Definition MILexer.h:101
@ kw_cfi_llvm_def_aspace_cfa
Definition MILexer.h:94
@ MachineBasicBlock
Definition MILexer.h:177
@ kw_dbg_instr_ref
Definition MILexer.h:85
@ NamedVirtualRegister
Definition MILexer.h:175
@ kw_early_clobber
Definition MILexer.h:59
@ kw_unpredictable
Definition MILexer.h:77
@ FloatingPointLiteral
Definition MILexer.h:187
@ kw_cfi_window_save
Definition MILexer.h:100
@ kw_cfi_llvm_register_pair
Definition MILexer.h:104
@ kw_frame_destroy
Definition MILexer.h:64
@ kw_cfi_undefined
Definition MILexer.h:99
@ MachineBasicBlockLabel
Definition MILexer.h:176
@ kw_cfi_llvm_vector_offset
Definition MILexer.h:106
@ kw_cfi_register
Definition MILexer.h:95
@ kw_inlineasm_br_indirect_target
Definition MILexer.h:134
@ kw_cfi_rel_offset
Definition MILexer.h:88
@ kw_cfi_llvm_vector_registers
Definition MILexer.h:105
@ kw_ehfunclet_entry
Definition MILexer.h:136
@ kw_cfi_llvm_vector_register_mask
Definition MILexer.h:107
@ kw_cfi_aarch64_negate_ra_sign_state_with_pc
Definition MILexer.h:102
@ kw_cfi_def_cfa_register
Definition MILexer.h:89
@ kw_cfi_same_value
Definition MILexer.h:86
@ kw_cfi_set_ra_state
Definition MILexer.h:103
@ kw_cfi_adjust_cfa_offset
Definition MILexer.h:91
@ kw_dereferenceable
Definition MILexer.h:55
@ kw_implicit_define
Definition MILexer.h:52
@ kw_cfi_def_cfa_offset
Definition MILexer.h:90
@ md_mem_cache_hint
Definition MILexer.h:168
@ kw_machine_block_address_taken
Definition MILexer.h:153
@ kw_cfi_remember_state
Definition MILexer.h:96
@ kw_debug_instr_number
Definition MILexer.h:84
@ kw_post_instr_symbol
Definition MILexer.h:143
@ kw_cfi_restore_state
Definition MILexer.h:98
@ kw_ir_block_address_taken
Definition MILexer.h:152
@ kw_unknown_address
Definition MILexer.h:151
@ md_noalias_addrspace
Definition MILexer.h:166
@ kw_debug_location
Definition MILexer.h:83
@ kw_heap_alloc_marker
Definition MILexer.h:144
StringRef range() const
Definition MILexer.h:251
bool isRegister() const
Definition MILexer.h:226
MIToken & setIntegerValue(APSInt IntVal)
Definition MILexer.cpp:79
bool isErrorOrEOF() const
Definition MILexer.h:224
MIToken & reset(TokenKind Kind, StringRef Range)
Definition MILexer.cpp:62
bool isError() const
Definition MILexer.h:220
MIToken & setOwnedStringValue(std::string StrVal)
Definition MILexer.cpp:73
StringRef::iterator location() const
Definition MILexer.h:249
const APSInt & integerValue() const
Definition MILexer.h:256