libTriton version 1.0 build 1590
Loading...
Searching...
No Matches
operandWrapper.cpp
Go to the documentation of this file.
1
2/*
3** Copyright (C) - Triton
4**
5** This program is under the terms of the Apache License 2.0.
6*/
7
10
11
12
13namespace triton {
14 namespace arch {
15
17 this->imm = imm;
18 this->type = triton::arch::OP_IMM;
19 }
20
21
23 this->mem = mem;
24 this->type = triton::arch::OP_MEM;
25 }
26
27
29 this->reg = reg;
30 this->type = triton::arch::OP_REG;
31 }
32
33
35 : imm(other.imm),
36 mem(other.mem),
37 reg(other.reg) {
38 this->type = other.type;
39 }
40
41
43 return this->type;
44 }
45
46
48 return this->imm;
49 }
50
51
53 return this->mem;
54 }
55
56
58 return this->reg;
59 }
60
61
63 return this->imm;
64 }
65
66
68 return this->mem;
69 }
70
71
73 return this->reg;
74 }
75
76
78 this->imm = imm;
79 }
80
81
83 this->mem = mem;
84 }
85
86
88 this->reg = reg;
89 }
90
91
93 switch (this->getType()) {
94 case triton::arch::OP_IMM: return this->getConstImmediate().getSize();
95 case triton::arch::OP_MEM: return this->getConstMemory().getSize();
96 case triton::arch::OP_REG: return this->getConstRegister().getSize();
97 default:
98 throw triton::exceptions::OperandWrapper("OperandWrapper::getSize(): Invalid type operand.");
99 }
100 return 0;
101 }
102
103
105 switch (this->getType()) {
107 case triton::arch::OP_MEM: return this->getConstMemory().getBitSize();
108 case triton::arch::OP_REG: return this->getConstRegister().getBitSize();
109 default:
110 throw triton::exceptions::OperandWrapper("OperandWrapper::getBitSize(): Invalid type operand.");
111 }
112 return 0;
113 }
114
115
117 switch (this->getType()) {
118 case triton::arch::OP_IMM: return this->getConstImmediate().getHigh();
119 case triton::arch::OP_MEM: return this->getConstMemory().getHigh();
120 case triton::arch::OP_REG: return this->getConstRegister().getHigh();
121 default:
122 throw triton::exceptions::OperandWrapper("OperandWrapper::getHigh(): Invalid type operand.");
123 }
124 return 0;
125 }
126
127
129 switch (this->getType()) {
130 case triton::arch::OP_IMM: return this->getConstImmediate().getLow();
131 case triton::arch::OP_MEM: return this->getConstMemory().getLow();
132 case triton::arch::OP_REG: return this->getConstRegister().getLow();
133 default:
134 throw triton::exceptions::OperandWrapper("OperandWrapper::getLow(): Invalid type operand.");
135 }
136 return 0;
137 }
138
139
141 this->imm = other.imm;
142 this->mem = other.mem;
143 this->reg = other.reg;
144 this->type = other.type;
145 return *this;
146 }
147
148
150 if (this->type != other.type)
151 return false;
152
153 switch (this->getType()) {
154 case triton::arch::OP_IMM: return this->imm == other.imm;
155 case triton::arch::OP_MEM: return this->mem == other.mem;
156 case triton::arch::OP_REG: return this->reg == other.reg;
157 default:
158 throw triton::exceptions::OperandWrapper("OperandWrapper::operator==(): Invalid type operand.");
159 }
160 }
161
162
164 return !(*this == other);
165 }
166
167
168 bool OperandWrapper::operator<(const OperandWrapper& other) const {
169 if (this->type < other.type)
170 return true;
171
172 if (this->type > other.type)
173 return false;
174
175 switch (this->getType()) {
176 case triton::arch::OP_IMM: return this->imm < other.imm;
177 case triton::arch::OP_MEM: return this->mem < other.mem;
178 case triton::arch::OP_REG: return this->reg < other.reg;
179 default:
180 throw triton::exceptions::OperandWrapper("OperandWrapper::operator<(): Invalid type operand.");
181 }
182 }
183
184
185 std::ostream& operator<<(std::ostream& stream, const triton::arch::OperandWrapper& op) {
186 switch (op.getType()) {
187 case triton::arch::OP_IMM: stream << op.getConstImmediate(); break;
188 case triton::arch::OP_MEM: stream << op.getConstMemory(); break;
189 case triton::arch::OP_REG: stream << op.getConstRegister(); break;
190 default:
191 throw triton::exceptions::OperandWrapper("triton::arch::operator<<(OperandWrapper): Invalid type operand.");
192 }
193 return stream;
194 }
195
196
197 std::ostream& operator<<(std::ostream &stream, const triton::arch::OperandWrapper* op) {
198 stream << *op;
199 return stream;
200 }
201
202 };
203};
TRITON_EXPORT triton::uint32 getHigh(void) const
Returns the highest bit.
TRITON_EXPORT triton::uint32 getLow(void) const
Returns the lower bit.
This class is used to represent an immediate.
Definition immediate.hpp:37
TRITON_EXPORT triton::uint32 getSize(void) const
Returns the size (in bytes) of the immediate vector.
Definition immediate.cpp:80
TRITON_EXPORT triton::uint32 getBitSize(void) const
Returns the size (in bits) of the immediate vector.
Definition immediate.cpp:85
This class is used to represent a memory access.
TRITON_EXPORT triton::uint32 getBitSize(void) const
Returns the size (in bits) of the memory vector.
TRITON_EXPORT triton::uint32 getSize(void) const
Returns the size (in bytes) of the memory vector.
This class is used as operand wrapper.
TRITON_EXPORT bool operator==(const OperandWrapper &other) const
Tests two OperandWrappers for equality.
TRITON_EXPORT OperandWrapper(const triton::arch::Immediate &imm)
Immediate constructor.
TRITON_EXPORT bool operator<(const OperandWrapper &other) const
Compares two OperandWrappers for ordering.
TRITON_EXPORT bool operator!=(const OperandWrapper &other) const
Tests two OperandWrappers for not equality.
TRITON_EXPORT triton::arch::Register & getRegister(void)
Returns the register operand.
TRITON_EXPORT void setRegister(const triton::arch::Register &reg)
Sets the register operand.
TRITON_EXPORT triton::uint32 getLow(void) const
Returns the lower bit position of the abstract operand.
TRITON_EXPORT triton::arch::operand_e getType(void) const
Returns the abstract type of the operand.
TRITON_EXPORT void setImmediate(const triton::arch::Immediate &imm)
Sets the immediate operand.
TRITON_EXPORT triton::uint32 getSize(void) const
Returns the abstract size (in bytes) of the operand.
TRITON_EXPORT const triton::arch::MemoryAccess & getConstMemory(void) const
Returns the memory operand as const.
TRITON_EXPORT triton::arch::MemoryAccess & getMemory(void)
Returns the memory operand.
TRITON_EXPORT void setMemory(const triton::arch::MemoryAccess &mem)
Sets the memory operand.
TRITON_EXPORT const triton::arch::Register & getConstRegister(void) const
Returns the register operand.
TRITON_EXPORT triton::uint32 getHigh(void) const
Returns the highest bit position of the abstract operand.
TRITON_EXPORT const triton::arch::Immediate & getConstImmediate(void) const
Returns the immediate operand.
TRITON_EXPORT triton::uint32 getBitSize(void) const
Returns the abstract size (in bits) of the operand.
TRITON_EXPORT OperandWrapper & operator=(const OperandWrapper &other)
Copies a OperandWrapper.
TRITON_EXPORT triton::arch::Immediate & getImmediate(void)
Returns the immediate operand.
This class is used when an instruction has a register operand.
Definition register.hpp:44
TRITON_EXPORT triton::uint32 getBitSize(void) const
Returns the size (in bits) of the register.
Definition register.cpp:63
TRITON_EXPORT triton::uint32 getSize(void) const
Returns the size (in bytes) of the register.
Definition register.cpp:68
The exception class used by operand wrappers.
std::ostream & operator<<(std::ostream &stream, BasicBlock &block)
Displays an BasicBlock.
std::uint32_t uint32
unisgned 32-bits
The Triton namespace.