LIEF: Library to Instrument Executable Formats
Version 2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
LIEF
asm
mips
mips/Operand.hpp
Go to the documentation of this file.
1
/* Copyright 2022 - 2026 R. Thomas
2
*
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
6
*
7
* http://www.apache.org/licenses/LICENSE-2.0
8
*
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
14
*/
15
#ifndef LIEF_ASM_MIPS_OPERAND_H
16
#define LIEF_ASM_MIPS_OPERAND_H
17
#include "
LIEF/iterators.hpp
"
18
#include "
LIEF/visibility.h
"
19
20
#include <cassert>
21
#include <memory>
22
#include <string>
23
24
#include <ostream>
25
26
27
namespace
LIEF::assembly::mips
{
28
29
namespace
details
{
30
class
Operand
;
31
class
OperandIt;
32
}
33
35
class
LIEF_API
Operand {
36
public
:
38
class
Iterator
final
39
:
public
iterator_facade_base
<Iterator, std::forward_iterator_tag, Operand,
40
std::ptrdiff_t, const Operand*, const Operand&> {
41
public
:
42
using
implementation
= details::OperandIt;
43
using
iterator_facade_base::operator++;
44
45
LIEF_API
Iterator
();
46
47
LIEF_API
Iterator
(std::unique_ptr<details::OperandIt> impl);
48
LIEF_API
Iterator
(
const
Iterator
&);
49
LIEF_API
Iterator
&
operator=
(
const
Iterator
&);
50
51
LIEF_API
Iterator
(
Iterator
&&) noexcept;
52
LIEF_API
Iterator
& operator=(
Iterator
&&) noexcept;
53
54
LIEF_API
~
Iterator
();
55
56
// NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
57
LIEF_API
Iterator
& operator++()
LIEF_LIFETIMEBOUND
;
58
59
friend
LIEF_API
bool
operator==(const
Iterator
& LHS, const
Iterator
& RHS);
60
61
friend
bool
operator!=(const
Iterator
& LHS, const
Iterator
& RHS) {
62
return
!(LHS == RHS);
63
}
64
65
LIEF_API
const
Operand&
operator*
() const
LIEF_LIFETIMEBOUND
;
66
67
// NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
68
LIEF_API
const Operand* operator->() const
LIEF_LIFETIMEBOUND
;
69
72
LIEF_API
std::unique_ptr<Operand>
yield
();
73
74
private:
75
void
load() const;
76
77
std::unique_ptr<
details
::OperandIt> impl_;
78
mutable std::unique_ptr<Operand> cached_;
79
};
80
82
std::
string
to_string
() const;
83
92
template<class T>
93
const T*
as
() const
LIEF_LIFETIMEBOUND
{
94
static_assert
(std::is_base_of_v<Operand, T>,
"Require Operand inheritance"
);
95
if
(T::classof(
this
)) {
96
return
static_cast<
const
T*
>
(
this
);
97
}
98
return
nullptr
;
99
}
100
101
virtual
~Operand
();
102
104
static
LIEF_LOCAL
std::unique_ptr<Operand>
105
create(std::unique_ptr<details::Operand> impl);
106
108
LIEF_LOCAL
const
details::Operand& impl() const
LIEF_LIFETIMEBOUND
{
109
assert(impl_ !=
nullptr
);
110
return
*impl_;
111
}
112
114
LIEF_LOCAL
details::Operand& impl()
LIEF_LIFETIMEBOUND
{
115
assert(impl_ !=
nullptr
);
116
return
*impl_;
117
}
118
119
friend
LIEF_API
std::ostream&
operator<<
(std::ostream& os,
const
Operand& op) {
120
os << op.
to_string
();
121
return
os;
122
}
123
124
protected
:
125
LIEF_LOCAL
Operand
(std::unique_ptr<details::Operand> impl);
126
std::unique_ptr<details::Operand> impl_;
127
};
128
129
}
130
131
132
#endif
LIEF::assembly::mips::Operand::Iterator::Iterator
Iterator()
LIEF::assembly::mips::Operand::Iterator::Iterator
Iterator(const Iterator &)
LIEF::assembly::mips::Operand::Iterator::operator*
const Operand & operator*() const
LIEF::assembly::mips::Operand::Iterator::yield
std::unique_ptr< Operand > yield()
Transfer ownership of the operand at the current position to the caller. Returns nullptr if the itera...
LIEF::assembly::mips::Operand::Iterator::implementation
details::OperandIt implementation
Definition
mips/Operand.hpp:42
LIEF::assembly::mips::Operand::Iterator::Iterator
Iterator(Iterator &&) noexcept
LIEF::assembly::mips::Operand::Iterator::Iterator
Iterator(std::unique_ptr< details::OperandIt > impl)
LIEF::assembly::mips::Operand::Iterator::operator=
Iterator & operator=(const Iterator &)
LIEF::assembly::mips::Operand
This class represents an operand for a Mips instruction.
Definition
mips/Operand.hpp:35
LIEF::assembly::mips::Operand::~Operand
virtual ~Operand()
LIEF::assembly::mips::Operand::as
const T * as() const
This function can be used to down cast an Operand instance:
Definition
mips/Operand.hpp:93
LIEF::assembly::mips::Operand::operator<<
friend std::ostream & operator<<(std::ostream &os, const Operand &op)
Definition
mips/Operand.hpp:119
LIEF::assembly::mips::Operand::to_string
std::string to_string() const
Pretty representation of the operand.
LIEF::iterator_facade_base
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition
iterators.hpp:738
LIEF_LIFETIMEBOUND
#define LIEF_LIFETIMEBOUND
Definition
compiler_attributes.hpp:72
iterators.hpp
LIEF::assembly::mips::details
Definition
mips/Operand.hpp:29
LIEF::assembly::mips
Mips architecture-related namespace.
Definition
mips/Instruction.hpp:26
visibility.h
LIEF_API
#define LIEF_API
Definition
visibility.h:45
LIEF_LOCAL
#define LIEF_LOCAL
Definition
visibility.h:46
Generated by
1.18.0