LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
aarch64/Operand.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2024 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_AARCH64_OPERAND_H
16#define LIEF_ASM_AARCH64_OPERAND_H
17#include "LIEF/visibility.h"
18#include "LIEF/iterators.hpp"
19
20#include <memory>
21#include <string>
22#include <cassert>
23
24#include <ostream>
25
26namespace LIEF {
27namespace assembly {
28namespace aarch64 {
29
30namespace details {
31class Operand;
32class OperandIt;
33}
34class LIEF_API Operand {
37 public:
38 class Iterator final :
41 public iterator_facade_base<Iterator, std::forward_iterator_tag, std::unique_ptr<Operand>,
42 std::ptrdiff_t, Operand*, std::unique_ptr<Operand>>
43 {
44 public:
45 using implementation = details::OperandIt;
46
48
49 LIEF_API Iterator(std::unique_ptr<details::OperandIt> impl);
50 LIEF_API Iterator(const Iterator&);
51 LIEF_API Iterator& operator=(const Iterator&);
52
53 LIEF_API Iterator(Iterator&&) noexcept;
54 LIEF_API Iterator& operator=(Iterator&&) noexcept;
55
56 LIEF_API ~Iterator();
57
58 LIEF_API Iterator& operator++();
59
60 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
61
62 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
63 return !(LHS == RHS);
64 }
65
66 LIEF_API std::unique_ptr<Operand> operator*() const;
67
68 private:
69 std::unique_ptr<details::OperandIt> impl_;
70 };
71 std::string to_string() const;
74 template<class T>
84 const T* as() const {
85 static_assert(std::is_base_of<Operand, T>::value,
86 "Require Operand inheritance");
87 if (T::classof(this)) {
88 return static_cast<const T*>(this);
89 }
90 return nullptr;
91 }
92
93 virtual ~Operand();
94 static LIEF_LOCAL std::unique_ptr<Operand>
97 create(std::unique_ptr<details::Operand> impl);
98 LIEF_LOCAL const details::Operand& impl() const {
101 assert(impl_ != nullptr);
102 return *impl_;
103 }
104 LIEF_LOCAL details::Operand& impl() {
107 assert(impl_ != nullptr);
108 return *impl_;
109 }
110
111 friend LIEF_API std::ostream& operator<<(std::ostream& os, const Operand& op) {
112 os << op.to_string();
113 return os;
114 }
115
116 protected:
117 LIEF_LOCAL Operand(std::unique_ptr<details::Operand> impl);
118 std::unique_ptr<details::Operand> impl_;
119};
120
121}
122}
123}
124
125#endif
Iterator()
Iterator(Iterator &&) noexcept
Iterator(std::unique_ptr< details::OperandIt > impl)
Iterator & operator=(const Iterator &)
Iterator(const Iterator &)
std::unique_ptr< Operand > operator*() const
This class represents an operand for an AArch64 instruction.
Definition aarch64/Operand.hpp:36
friend std::ostream & operator<<(std::ostream &os, const Operand &op)
Definition aarch64/Operand.hpp:111
std::string to_string() const
Pretty representation of the operand.
virtual ~Operand()
const T * as() const
This function can be used to down cast an Operand instance:
Definition aarch64/Operand.hpp:84
Definition aarch64/Operand.hpp:30
AArch64 architecture-related namespace.
Definition aarch64/Instruction.hpp:27
Namespace related to assembly/disassembly support.
Definition Abstract/Binary.hpp:43
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42