mini-llvm
0.1.0
Toggle main menu visibility
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
11
#include "
mini-llvm/mc/Operand.h
"
12
#include "
mini-llvm/mc/Statement.h
"
13
#include "
mini-llvm/utils/Compiler.h
"
14
#include "
mini-llvm/utils/IndirectIterator.h
"
15
16
namespace
mini_llvm::mc
{
17
18
class
MINI_LLVM_EXPORT
Instruction
:
public
Statement
{
19
public
:
20
using
operand_iterator
=
IndirectIterator<std::vector<std::unique_ptr<Operand>
>::iterator,
Operand
>;
21
using
const_operand_iterator
=
IndirectIterator<std::vector<std::unique_ptr<Operand>
>::const_iterator,
const
Operand
>;
22
23
int
opcode
()
const
{
24
return
opcode_;
25
}
26
27
void
setOpcode
(
int
opcode
) {
28
opcode_ =
opcode
;
29
}
30
31
operand_iterator
operand_begin
() {
32
return
operand_iterator
(operands_.begin());
33
}
34
35
operand_iterator
operand_end
() {
36
return
operand_iterator
(operands_.end());
37
}
38
39
const_operand_iterator
operand_begin
()
const
{
40
return
const_operand_iterator
(operands_.begin());
41
}
42
43
const_operand_iterator
operand_end
()
const
{
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
67
protected
:
68
explicit
Instruction
(
int
opcode
, std::vector<std::unique_ptr<Operand>>
operands
= {})
69
: opcode_(opcode), operands_(std::move(
operands
)) {}
70
71
private
:
72
int
opcode_;
73
std::vector<std::unique_ptr<Operand>> operands_;
74
};
75
76
inline
auto
operands
(
Instruction
&I) {
77
return
std::ranges::subrange(I.
operand_begin
(), I.
operand_end
());
78
}
79
80
inline
auto
operands
(
const
Instruction
&I) {
81
return
std::ranges::subrange(I.
operand_begin
(), I.
operand_end
());
82
}
83
84
}
// namespace mini_llvm::mc
Compiler.h
MINI_LLVM_EXPORT
#define MINI_LLVM_EXPORT
Definition
Compiler.h:17
IndirectIterator.h
Operand.h
Statement.h
mini_llvm::IndirectIterator
Definition
IndirectIterator.h:16
mini_llvm::mc::Instruction
Definition
Instruction.h:18
mini_llvm::mc::Instruction::operand_size
size_t operand_size() const
Definition
Instruction.h:51
mini_llvm::mc::Instruction::operand_iterator
IndirectIterator< std::vector< std::unique_ptr< Operand > >::iterator, Operand > operand_iterator
Definition
Instruction.h:20
mini_llvm::mc::Instruction::const_operand_iterator
IndirectIterator< std::vector< std::unique_ptr< Operand > >::const_iterator, const Operand > const_operand_iterator
Definition
Instruction.h:21
mini_llvm::mc::Instruction::setOperands
void setOperands(std::vector< std::unique_ptr< Operand > > operands)
Definition
Instruction.h:63
mini_llvm::mc::Instruction::Instruction
Instruction(int opcode, std::vector< std::unique_ptr< Operand > > operands={})
Definition
Instruction.h:68
mini_llvm::mc::Instruction::operand_end
const_operand_iterator operand_end() const
Definition
Instruction.h:43
mini_llvm::mc::Instruction::operand_end
operand_iterator operand_end()
Definition
Instruction.h:35
mini_llvm::mc::Instruction::operand_empty
bool operand_empty() const
Definition
Instruction.h:47
mini_llvm::mc::Instruction::operand
Operand & operand(size_t i)
Definition
Instruction.h:55
mini_llvm::mc::Instruction::operand_begin
const_operand_iterator operand_begin() const
Definition
Instruction.h:39
mini_llvm::mc::Instruction::operand_begin
operand_iterator operand_begin()
Definition
Instruction.h:31
mini_llvm::mc::Instruction::setOpcode
void setOpcode(int opcode)
Definition
Instruction.h:27
mini_llvm::mc::Instruction::operand
const Operand & operand(size_t i) const
Definition
Instruction.h:59
mini_llvm::mc::Instruction::opcode
int opcode() const
Definition
Instruction.h:23
mini_llvm::mc::Operand
Definition
Operand.h:13
mini_llvm::mc::Statement::Statement
Statement()=default
mini_llvm::mc
Definition
Directive.h:8
mini_llvm::mc::operands
auto operands(Instruction &I)
Definition
Instruction.h:76
include
mini-llvm
mc
Instruction.h
Generated by
1.17.0