LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
x86/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_X86_OPERAND_H
16#define LIEF_ASM_X86_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 x86 {
29
30namespace details {
31class Operand;
32class OperandIt;
33}
34
36class LIEF_API Operand {
37 public:
39 class Iterator final
40 : public iterator_facade_base<Iterator, std::forward_iterator_tag,
41 std::unique_ptr<Operand>, std::ptrdiff_t,
42 Operand*, std::unique_ptr<Operand>> {
43 public:
44 using implementation = details::OperandIt;
45
47
48 LIEF_API Iterator(std::unique_ptr<details::OperandIt> impl);
51
53 LIEF_API Iterator& operator=(Iterator&&) noexcept;
54
56
57 LIEF_API Iterator& operator++();
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 std::unique_ptr<Operand> operator*() const;
66
67 private:
68 std::unique_ptr<details::OperandIt> impl_;
69 };
70
72 std::string to_string() const;
73
82 template<class T>
83 const T* as() const {
84 static_assert(std::is_base_of<Operand, T>::value,
85 "Require Operand inheritance");
86 if (T::classof(this)) {
87 return static_cast<const T*>(this);
88 }
89 return nullptr;
90 }
91
92 virtual ~Operand();
93
95 static LIEF_LOCAL std::unique_ptr<Operand>
96 create(std::unique_ptr<details::Operand> impl);
97
99 LIEF_LOCAL const details::Operand& impl() const {
100 assert(impl_ != nullptr);
101 return *impl_;
102 }
103
105 LIEF_LOCAL details::Operand& impl() {
106 assert(impl_ != nullptr);
107 return *impl_;
108 }
109
110 friend LIEF_API std::ostream& operator<<(std::ostream& os, const Operand& op) {
111 os << op.to_string();
112 return os;
113 }
114
115 protected:
116 LIEF_LOCAL Operand(std::unique_ptr<details::Operand> impl);
117 std::unique_ptr<details::Operand> impl_;
118};
119
120}
121}
122}
123
124#endif
details::OperandIt implementation
Definition x86/Operand.hpp:44
std::unique_ptr< Operand > operator*() const
Iterator(std::unique_ptr< details::OperandIt > impl)
Iterator & operator=(const Iterator &)
This class represents an operand for an x86/x86-64 instruction.
Definition x86/Operand.hpp:36
friend std::ostream & operator<<(std::ostream &os, const Operand &op)
Definition x86/Operand.hpp:110
std::string to_string() const
Pretty representation of the operand.
const T * as() const
This function can be used to down cast an Operand instance:
Definition x86/Operand.hpp:83
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:685
Definition x86/Operand.hpp:30
x86/x86-64 architecture-related namespace
Definition x86/Instruction.hpp:27
Namespace related to assembly/disassembly support.
Definition Abstract/Binary.hpp:47
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:43
#define LIEF_LOCAL
Definition visibility.h:44