libTriton  version 0.9 build 1502
register.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 
9 #include <triton/register.hpp>
10 
11 
12 
13 namespace triton {
14  namespace arch {
15 
17  : Register(triton::arch::ID_REG_INVALID, "unknown", triton::arch::ID_REG_INVALID, 0, 0, true) {
18  }
19 
20 
21  Register::Register(triton::arch::register_e regId, std::string name, triton::arch::register_e parent, triton::uint32 high, triton::uint32 low, bool vmutable)
22  : BitsVector(high, low),
23  name(name),
24  id(regId),
25  parent(parent),
26  vmutable(vmutable) {
27  }
28 
29 
31  : Register(
32  (regId == triton::arch::ID_REG_INVALID) ?
33  triton::arch::Register(triton::arch::ID_REG_INVALID, "unknown", triton::arch::ID_REG_INVALID, 0, 0, true) : cpu.getRegister(regId)
34  ) {
35  }
36 
37 
39  : BitsVector(other),
40  ArmOperandProperties(other) {
41  this->copy(other);
42  }
43 
44 
45  void Register::copy(const Register& other) {
46  this->id = other.id;
47  this->name = other.name;
48  this->parent = other.parent;
49  this->vmutable = other.vmutable;
50  }
51 
52 
54  return this->id;
55  }
56 
57 
59  return this->parent;
60  }
61 
62 
64  return this->getVectorSize();
65  }
66 
67 
69  return this->getVectorSize() / triton::bitsize::byte;
70  }
71 
72 
73  std::string Register::getName(void) const {
74  return this->name;
75  }
76 
77 
79  return triton::arch::OP_REG;
80  }
81 
82 
83  bool Register::isOverlapWith(const Register& other) const {
84  if (this->parent == other.parent) {
85  if (this->getLow() <= other.getLow() && other.getLow() <= this->getHigh()) return true;
86  if (other.getLow() <= this->getLow() && this->getLow() <= other.getHigh()) return true;
87  }
88  return false;
89  }
90 
91 
92  bool Register::isMutable(void) const {
93  return this->vmutable;
94  }
95 
96 
97  bool Register::operator==(const Register& other) const {
98  return getId() == other.getId();
99  }
100 
101 
102  bool Register::operator!=(const Register& other) const {
103  return !(*this == other);
104  }
105 
106 
108  ArmOperandProperties::operator=(other);
109  BitsVector::operator=(other);
110  this->copy(other);
111  return *this;
112  }
113 
114 
115  std::ostream& operator<<(std::ostream& stream, const Register& reg) {
116  stream << reg.getName()
117  << ":"
118  << std::dec << reg.getBitSize()
119  << " bv["
120  << reg.getHigh()
121  << ".."
122  << reg.getLow()
123  << "]";
124  return stream;
125  }
126 
127 
128  std::ostream& operator<<(std::ostream& stream, const Register* reg) {
129  stream << *reg;
130  return stream;
131  }
132 
133 
134  bool operator<(const Register& reg1, const Register& reg2) {
135  return (reg1.getId() < reg2.getId());
136  }
137 
138  }; /* arch namespace */
139 }; /* triton namespace */
This class is used to deal with registers and memory as bits vector.
Definition: bitsVector.hpp:36
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 BitsVector & operator=(const BitsVector &other)
Copy a BitsVector.
Definition: bitsVector.cpp:96
This interface is used as abstract CPU interface. All CPU must use this interface.
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::arch::register_e getParent(void) const
Returns the parent id of the register.
Definition: register.cpp:58
TRITON_EXPORT triton::arch::register_e getId(void) const
Returns the id of the register.
Definition: register.cpp:53
triton::arch::register_e parent
The parent id of the register.
Definition: register.hpp:53
TRITON_EXPORT bool operator!=(const Register &other) const
Compare two registers specifications.
Definition: register.cpp:102
TRITON_EXPORT bool isOverlapWith(const Register &other) const
Returns true if other and self overlap.
Definition: register.cpp:83
TRITON_EXPORT Register & operator=(const Register &other)
Copies a Register.
Definition: register.cpp:107
TRITON_EXPORT triton::arch::operand_e getType(void) const
Returns the type of the operand (triton::arch::OPERAND_REGISTER).
Definition: register.cpp:78
TRITON_EXPORT bool operator==(const Register &other) const
Compare two registers specifications.
Definition: register.cpp:97
TRITON_EXPORT Register()
Constructor.
Definition: register.cpp:16
bool vmutable
True if the register is mutable. For example XZR in AArch64 is immutable.
Definition: register.hpp:56
triton::arch::register_e id
The id of the register.
Definition: register.hpp:50
TRITON_EXPORT bool isMutable(void) const
Returns true if this register is mutable. Mainly used in AArch64 to define that some registers like X...
Definition: register.cpp:92
std::string name
The name of the register.
Definition: register.hpp:47
TRITON_EXPORT std::string getName(void) const
Returns the name of the register.
Definition: register.cpp:73
TRITON_EXPORT triton::uint32 getSize(void) const
Returns the size (in bytes) of the register.
Definition: register.cpp:68
std::ostream & operator<<(std::ostream &stream, const BitsVector &bv)
Displays a BitsVector.
Definition: bitsVector.cpp:103
bool operator<(const Immediate &imm1, const Immediate &imm2)
Compares two Immediate (needed for std::map)
Definition: immediate.cpp:141
register_e
Types of register.
Definition: archEnums.hpp:55
@ OP_REG
register operand
Definition: archEnums.hpp:51
@ ID_REG_INVALID
invalid = 0
Definition: archEnums.hpp:56
constexpr triton::uint32 byte
byte size in bit
Definition: cpuSize.hpp:58
std::uint32_t uint32
unisgned 32-bits
Definition: tritonTypes.hpp:31
The Triton namespace.
Definition: api.cpp:227