mini-llvm 0.1.0
Loading...
Searching...
No Matches
Instruction.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <cstddef>
6#include <memory>
7#include <ranges>
8#include <utility>
9#include <vector>
10
15
16namespace mini_llvm::mc {
17
19public:
22
23 int opcode() const {
24 return opcode_;
25 }
26
27 void setOpcode(int opcode) {
28 opcode_ = opcode;
29 }
30
32 return operand_iterator(operands_.begin());
33 }
34
36 return operand_iterator(operands_.end());
37 }
38
40 return const_operand_iterator(operands_.begin());
41 }
42
44 return const_operand_iterator(operands_.end());
45 }
46
47 bool operand_empty() const {
48 return operands_.empty();
49 }
50
51 size_t operand_size() const {
52 return operands_.size();
53 }
54
55 Operand &operand(size_t i) {
56 return *operands_[i];
57 }
58
59 const Operand &operand(size_t i) const {
60 return *operands_[i];
61 }
62
63 void setOperands(std::vector<std::unique_ptr<Operand>> operands) {
64 operands_ = std::move(operands);
65 }
66
67protected:
68 explicit Instruction(int opcode, std::vector<std::unique_ptr<Operand>> operands = {})
69 : opcode_(opcode), operands_(std::move(operands)) {}
70
71private:
72 int opcode_;
73 std::vector<std::unique_ptr<Operand>> operands_;
74};
75
76inline auto operands(Instruction &I) {
77 return std::ranges::subrange(I.operand_begin(), I.operand_end());
78}
79
80inline auto operands(const Instruction &I) {
81 return std::ranges::subrange(I.operand_begin(), I.operand_end());
82}
83
84} // namespace mini_llvm::mc
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
Definition IndirectIterator.h:16
Definition Instruction.h:18
size_t operand_size() const
Definition Instruction.h:51
IndirectIterator< std::vector< std::unique_ptr< Operand > >::iterator, Operand > operand_iterator
Definition Instruction.h:20
IndirectIterator< std::vector< std::unique_ptr< Operand > >::const_iterator, const Operand > const_operand_iterator
Definition Instruction.h:21
void setOperands(std::vector< std::unique_ptr< Operand > > operands)
Definition Instruction.h:63
Instruction(int opcode, std::vector< std::unique_ptr< Operand > > operands={})
Definition Instruction.h:68
const_operand_iterator operand_end() const
Definition Instruction.h:43
operand_iterator operand_end()
Definition Instruction.h:35
bool operand_empty() const
Definition Instruction.h:47
Operand & operand(size_t i)
Definition Instruction.h:55
const_operand_iterator operand_begin() const
Definition Instruction.h:39
operand_iterator operand_begin()
Definition Instruction.h:31
void setOpcode(int opcode)
Definition Instruction.h:27
const Operand & operand(size_t i) const
Definition Instruction.h:59
int opcode() const
Definition Instruction.h:23
Definition Operand.h:13
Definition Directive.h:8
auto operands(Instruction &I)
Definition Instruction.h:76