LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
powerpc/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_POWERPC_OPERAND_H
16#define LIEF_ASM_POWERPC_OPERAND_H
17#include "LIEF/visibility.h"
18#include "LIEF/iterators.hpp"
20
21#include <memory>
22#include <string>
23#include <cassert>
24
25#include <ostream>
26
27namespace LIEF {
28namespace assembly {
29namespace powerpc {
30
31namespace details {
32class Operand;
33class OperandIt;
34}
35
37class LIEF_API Operand {
38 public:
40 class Iterator final
41 : public iterator_facade_base<Iterator, std::forward_iterator_tag, Operand,
42 std::ptrdiff_t, const Operand*, const Operand&> {
43 public:
44 using implementation = details::OperandIt;
45 using iterator_facade_base::operator++;
46
48
49 LIEF_API Iterator(std::unique_ptr<details::OperandIt> impl);
52
54 LIEF_API Iterator& operator=(Iterator&&) noexcept;
55
57
58 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
60
61 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
62
63 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
64 return !(LHS == RHS);
65 }
66
67 LIEF_API const Operand& operator*() const LIEF_LIFETIMEBOUND;
68
69 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
70 LIEF_API const Operand* operator->() const LIEF_LIFETIMEBOUND;
71
74 LIEF_API std::unique_ptr<Operand> yield();
75
76 private:
77 void load() const;
78
79 std::unique_ptr<details::OperandIt> impl_;
80 mutable std::unique_ptr<Operand> cached_;
81 };
82
84 std::string to_string() const;
85
94 template<class T>
95 const T* as() const LIEF_LIFETIMEBOUND {
96 static_assert(std::is_base_of<Operand, T>::value,
97 "Require Operand inheritance");
98 if (T::classof(this)) {
99 return static_cast<const T*>(this);
100 }
101 return nullptr;
102 }
103
104 virtual ~Operand();
105
107 static LIEF_LOCAL std::unique_ptr<Operand>
108 create(std::unique_ptr<details::Operand> impl);
109
111 LIEF_LOCAL const details::Operand& impl() const LIEF_LIFETIMEBOUND {
112 assert(impl_ != nullptr);
113 return *impl_;
114 }
115
117 LIEF_LOCAL details::Operand& impl() LIEF_LIFETIMEBOUND {
118 assert(impl_ != nullptr);
119 return *impl_;
120 }
121
122 friend LIEF_API std::ostream& operator<<(std::ostream& os, const Operand& op) {
123 os << op.to_string();
124 return os;
125 }
126
127 protected:
128 LIEF_LOCAL Operand(std::unique_ptr<details::Operand> impl);
129 std::unique_ptr<details::Operand> impl_;
130};
131
132}
133}
134}
135
136#endif
details::OperandIt implementation
Definition powerpc/Operand.hpp:44
std::unique_ptr< Operand > yield()
Transfer ownership of the operand at the current position to the caller. Returns nullptr if the itera...
Iterator & operator=(const Iterator &)
Iterator(std::unique_ptr< details::OperandIt > impl)
This class represents an operand for a PowerPC instruction.
Definition powerpc/Operand.hpp:37
const T * as() const
This function can be used to down cast an Operand instance:
Definition powerpc/Operand.hpp:95
friend std::ostream & operator<<(std::ostream &os, const Operand &op)
Definition powerpc/Operand.hpp:122
std::string to_string() const
Pretty representation of the operand.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:750
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition powerpc/Operand.hpp:31
PowerPC architecture-related namespace.
Definition powerpc/Instruction.hpp:28
Namespace related to assembly/disassembly support.
Definition Abstract/Binary.hpp:48
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46