libTriton  version 0.9 build 1502
bitsVector.cpp
Go to the documentation of this file.
1 /*
3 ** Copyright (C) - Triton
4 **
5 ** This program is under the terms of the Apache License 2.0.
6 */
7 
8 #include <triton/bitsVector.hpp>
9 #include <triton/cpuSize.hpp>
10 #include <triton/exceptions.hpp>
11 
12 
13 
14 namespace triton {
15  namespace arch {
16 
18  this->high = 0;
19  this->low = 0;
20  }
21 
22 
23  BitsVector::BitsVector(triton::uint32 high /* bits */, triton::uint32 low /* bits */) {
24  this->setBits(high, low);
25  }
26 
27 
29  this->high = other.high;
30  this->low = other.low;
31  }
32 
33 
35  return this->high;
36  }
37 
38 
40  return this->low;
41  }
42 
43 
45  return (this->high - this->low) + 1;
46  }
47 
48 
50  triton::uint512 max = -1;
51  max = max >> (512 - this->getVectorSize());
52  return max;
53  }
54 
55 
57  this->high = v;
58 
60  throw triton::exceptions::BitsVector("BitsVector::setHigh(): The highest bit cannot be greater than triton::bitsize::max_supported.");
61 
63  throw triton::exceptions::BitsVector("BitsVector::setHigh(): The vector size must be a multiple of 8.");
64  }
65 
66 
68  this->low = v;
69 
70  if (this->low > this->high)
71  throw triton::exceptions::BitsVector("BitsVector::setLow(): The lower bit cannot be greater than highest.");
72 
73  if (this->low % triton::bitsize::byte)
74  throw triton::exceptions::BitsVector("BitsVector::setLow(): The lower bit must be a multiple of 8.");
75  }
76 
77 
79  this->high = high;
80  this->low = low;
81 
82  if (this->high >= triton::bitsize::max_supported)
83  throw triton::exceptions::BitsVector("BitsVector::setBits(): The highest bit cannot be greater than triton::bitsize::max_supported.");
84 
85  if (this->low % triton::bitsize::byte)
86  throw triton::exceptions::BitsVector("BitsVector::setBits(): The lower bit must be a multiple of 8.");
87 
88  if (this->low > this->high)
89  throw triton::exceptions::BitsVector("BitsVector::setBits(): The lower bit cannot be greater than highest.");
90 
91  if (this->getVectorSize() % triton::bitsize::byte && this->getVectorSize() != triton::bitsize::flag)
92  throw triton::exceptions::BitsVector("BitsVector::setHigh(): The vector size must be a multiple of 8.");
93  }
94 
95 
97  this->high = other.high;
98  this->low = other.low;
99  return *this;
100  }
101 
102 
103  std::ostream& operator<<(std::ostream& stream, const BitsVector& bv) {
104  stream << "bv[" << bv.getHigh() << ".." << bv.getLow() << "]";
105  return stream;
106  }
107 
108 
109  std::ostream& operator<<(std::ostream& stream, const BitsVector* bv) {
110  stream << *bv;
111  return stream;
112  }
113 
114  }; /* arch namespace */
115 }; /* triton namespace */
This class is used to deal with registers and memory as bits vector.
Definition: bitsVector.hpp:36
TRITON_EXPORT triton::uint512 getMaxValue(void) const
Returns the max possible value of the bitvector.
Definition: bitsVector.cpp:49
triton::uint32 low
The lower bit of the bitvector.
Definition: bitsVector.hpp:42
TRITON_EXPORT triton::uint32 getHigh(void) const
Returns the highest bit.
Definition: bitsVector.cpp:34
TRITON_EXPORT triton::uint32 getVectorSize(void) const
Returns the size in bits of the vector.
Definition: bitsVector.cpp:44
TRITON_EXPORT triton::uint32 getLow(void) const
Returns the lower bit.
Definition: bitsVector.cpp:39
TRITON_EXPORT void setHigh(triton::uint32 v)
Sets the highest bit position.
Definition: bitsVector.cpp:56
TRITON_EXPORT void setBits(triton::uint32 high, triton::uint32 low)
Sets the bits (high, low) position.
Definition: bitsVector.cpp:78
TRITON_EXPORT BitsVector()
Constructor.
Definition: bitsVector.cpp:17
TRITON_EXPORT void setLow(triton::uint32 v)
Sets the lower bit position.
Definition: bitsVector.cpp:67
triton::uint32 high
The highest bit of the bitvector.
Definition: bitsVector.hpp:39
TRITON_EXPORT BitsVector & operator=(const BitsVector &other)
Copy a BitsVector.
Definition: bitsVector.cpp:96
The exception class used by bitvectors.
Definition: exceptions.hpp:209
std::ostream & operator<<(std::ostream &stream, const BitsVector &bv)
Displays a BitsVector.
Definition: bitsVector.cpp:103
constexpr triton::uint32 byte
byte size in bit
Definition: cpuSize.hpp:58
constexpr triton::uint32 flag
flag size in bit
Definition: cpuSize.hpp:56
constexpr triton::uint32 max_supported
max size supported in bit
Definition: cpuSize.hpp:72
boost::multiprecision::uint512_t uint512
unsigned 512-bits
Definition: tritonTypes.hpp:43
std::uint32_t uint32
unisgned 32-bits
Definition: tritonTypes.hpp:31
The Triton namespace.
Definition: api.cpp:227