libTriton version 1.0 build 1592
Loading...
Searching...
No Matches
immediate.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
8#include <triton/cpuSize.hpp>
10#include <triton/immediate.hpp>
11
12
13
14namespace triton {
15 namespace arch {
16
18 this->value = 0;
19 }
20
21
23 this->setValue(value, size);
24 }
25
26
28 : BitsVector(other),
29 ArmOperandProperties(other) {
30 this->copy(other);
31 }
32
33
35 return this->value;
36 }
37
38
39 void Immediate::setValue(triton::uint64 value, triton::uint32 size /* bytes */) {
40 /* If the size is zero, try to define the size according to the value. */
41 if (size == 0) {
42 if (/* ..... 0x0000000000000000 */ value <= 0x00000000000000ff) size = triton::size::byte;
43 else if (value >= 0x0000000000000100 && value <= 0x000000000000ffff) size = triton::size::word;
44 else if (value >= 0x0000000000010000 && value <= 0x00000000ffffffff) size = triton::size::dword;
45 else if (value >= 0x0000000100000000 && value <= 0xffffffffffffffff) size = triton::size::qword;
46 }
47
48 if (size != triton::size::byte &&
49 size != triton::size::word &&
50 size != triton::size::dword &&
51 size != triton::size::qword &&
52 size != triton::size::fword &&
53 size != triton::size::dqword &&
54 size != triton::size::qqword &&
56 throw triton::exceptions::Immediate("Immediate::setValue(): size must be aligned.");
57
58 switch (size) {
60 this->value = static_cast<triton::uint8>(value);
61 break;
62
64 this->value = static_cast<triton::uint16>(value);
65 break;
66
68 this->value = static_cast<triton::uint32>(value);
69 break;
70
71 /* In most CPU cases, integers more than 64 are loaded from memory */
72 default:
73 this->value = value;
74 }
75
76 this->setBits(((size * triton::bitsize::byte) - 1), 0);
77 }
78
79
83
84
86 return this->getVectorSize();
87 }
88
89
93
94
96 ArmOperandProperties::operator=(other);
98 this->copy(other);
99 return *this;
100 }
101
102
103 void Immediate::copy(const Immediate& other) {
104 this->value = other.value;
105 }
106
107
108 std::ostream& operator<<(std::ostream& stream, const Immediate& imm) {
109 stream << "0x"
110 << std::hex << imm.getValue()
111 << ":"
112 << std::dec << imm.getBitSize()
113 << " bv["
114 << imm.getHigh()
115 << ".."
116 << imm.getLow()
117 << "]";
118 return stream;
119 }
120
121
122 std::ostream& operator<<(std::ostream& stream, const Immediate* imm) {
123 stream << *imm;
124 return stream;
125 }
126
127
128 bool operator==(const Immediate& imm1, const Immediate& imm2) {
129 if (imm1.getValue() != imm2.getValue())
130 return false;
131 if (imm1.getSize() != imm2.getSize())
132 return false;
133 return true;
134 }
135
136
137 bool operator!=(const Immediate& imm1, const Immediate& imm2) {
138 return !(imm1 == imm2);
139 }
140
141
142 bool operator<(const Immediate& imm1, const Immediate& imm2) {
143 triton::uint64 seed1 = 0;
144 triton::uint64 seed2 = 0;
145
146 /*
147 * Golden ratio 32-bits -> 0x9e3779b9
148 * Golden ratio 64-bits -> 0x9e3779b97f4a7c13
149 */
150 seed1 ^= imm1.getValue() + 0x9e3779b97f4a7c13 + (seed1 << 6) + (seed1 >> 2);
151 seed1 ^= imm1.getSize() + 0x9e3779b97f4a7c13 + (seed1 << 6) + (seed1 >> 2);
152
153 seed2 ^= imm2.getValue() + 0x9e3779b97f4a7c13 + (seed2 << 6) + (seed2 >> 2);
154 seed2 ^= imm2.getSize() + 0x9e3779b97f4a7c13 + (seed2 << 6) + (seed2 >> 2);
155
156 return (seed1 < seed2);
157 }
158
159 }; /* arch namespace */
160}; /* triton namespace */
This class is used to deal with registers and memory as bits vector.
TRITON_EXPORT triton::uint32 getHigh(void) const
Returns the highest bit.
TRITON_EXPORT triton::uint32 getVectorSize(void) const
Returns the size in bits of the vector.
TRITON_EXPORT triton::uint32 getLow(void) const
Returns the lower bit.
TRITON_EXPORT void setBits(triton::uint32 high, triton::uint32 low)
Sets the bits (high, low) position.
TRITON_EXPORT BitsVector & operator=(const BitsVector &other)
Copy a BitsVector.
This class is used to represent an immediate.
Definition immediate.hpp:37
triton::uint64 value
The value of the operand.
Definition immediate.hpp:40
TRITON_EXPORT triton::uint32 getSize(void) const
Returns the size (in bytes) of the immediate vector.
Definition immediate.cpp:80
TRITON_EXPORT Immediate & operator=(const Immediate &other)
Copy an Immediate.
Definition immediate.cpp:95
TRITON_EXPORT triton::uint32 getBitSize(void) const
Returns the size (in bits) of the immediate vector.
Definition immediate.cpp:85
TRITON_EXPORT triton::uint64 getValue(void) const
Returns the value of the operand.
Definition immediate.cpp:34
TRITON_EXPORT triton::arch::operand_e getType(void) const
Returns the type of the operand (triton::arch::OPERAND_IMMEDIATE).
Definition immediate.cpp:90
TRITON_EXPORT void setValue(triton::uint64 v, triton::uint32 size)
Sets the value of the operand.
Definition immediate.cpp:39
TRITON_EXPORT Immediate()
Constructor.
Definition immediate.cpp:17
The exception class used by immediates.
bool operator==(const Immediate &imm1, const Immediate &imm2)
Compares two Immediate.
std::ostream & operator<<(std::ostream &stream, BasicBlock &block)
Displays an BasicBlock.
bool operator!=(const Immediate &imm1, const Immediate &imm2)
Compares two Immediate.
bool operator<(const Immediate &imm1, const Immediate &imm2)
Compares two Immediate (needed for std::map)
constexpr triton::uint32 byte
byte size in bit
Definition cpuSize.hpp:60
constexpr triton::uint32 fword
fword size in byte
Definition cpuSize.hpp:38
constexpr triton::uint32 dword
dword size in byte
Definition cpuSize.hpp:34
constexpr triton::uint32 dqqword
dqqword size in byte
Definition cpuSize.hpp:44
constexpr triton::uint32 word
word size in byte
Definition cpuSize.hpp:32
constexpr triton::uint32 dqword
dqword size in byte
Definition cpuSize.hpp:40
constexpr triton::uint32 byte
byte size in byte
Definition cpuSize.hpp:30
constexpr triton::uint32 qword
qword size in byte
Definition cpuSize.hpp:36
constexpr triton::uint32 qqword
qqword size in byte
Definition cpuSize.hpp:42
std::uint16_t uint16
unisgned 16-bits
std::uint64_t uint64
unisgned 64-bits
std::uint32_t uint32
unisgned 32-bits
std::uint8_t uint8
unisgned 8-bits
The Triton namespace.