libTriton version 1.0 build 1590
Loading...
Searching...
No Matches
register.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
9#include <triton/register.hpp>
10
11
12
13namespace triton {
14 namespace arch {
15
17 : Register(triton::arch::ID_REG_INVALID, "unknown", triton::arch::ID_REG_INVALID, 0, 0, true) {
18 }
19
20
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
71
72
73 std::string Register::getName(void) const {
74 if (this->getVASType()) {
75 return this->name + "." + this->getVASName();
76 }
77 return this->name;
78 }
79
80
84
85
86 bool Register::isOverlapWith(const Register& other) const {
87 if (this->parent == other.parent) {
88 if (this->getLow() <= other.getLow() && other.getLow() <= this->getHigh()) return true;
89 if (other.getLow() <= this->getLow() && this->getLow() <= other.getHigh()) return true;
90 }
91 return false;
92 }
93
94
95 bool Register::isMutable(void) const {
96 return this->vmutable;
97 }
98
99
100 bool Register::operator==(const Register& other) const {
101 return getId() == other.getId();
102 }
103
104
105 bool Register::operator!=(const Register& other) const {
106 return !(*this == other);
107 }
108
109
111 ArmOperandProperties::operator=(other);
113 this->copy(other);
114 return *this;
115 }
116
117
118 std::ostream& operator<<(std::ostream& stream, const Register& reg) {
119 stream << reg.getName()
120 << ":"
121 << std::dec << reg.getBitSize()
122 << " bv["
123 << reg.getHigh()
124 << ".."
125 << reg.getLow()
126 << "]";
127 return stream;
128 }
129
130
131 std::ostream& operator<<(std::ostream& stream, const Register* reg) {
132 stream << *reg;
133 return stream;
134 }
135
136
137 bool operator<(const Register& reg1, const Register& reg2) {
138 return (reg1.getId() < reg2.getId());
139 }
140
141 }; /* arch namespace */
142}; /* 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 BitsVector & operator=(const BitsVector &other)
Copy a BitsVector.
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:105
TRITON_EXPORT bool isOverlapWith(const Register &other) const
Returns true if other and self overlap.
Definition register.cpp:86
TRITON_EXPORT Register & operator=(const Register &other)
Copies a Register.
Definition register.cpp:110
TRITON_EXPORT triton::arch::operand_e getType(void) const
Returns the type of the operand (triton::arch::OPERAND_REGISTER).
Definition register.cpp:81
TRITON_EXPORT bool operator==(const Register &other) const
Compare two registers specifications.
Definition register.cpp:100
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:95
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
TRITON_EXPORT std::string getVASName(void) const
Returns the vector arrangement specifier string name.
TRITON_EXPORT triton::arch::arm::vas_e getVASType(void) const
Returns the vector arrangement specifier.
std::ostream & operator<<(std::ostream &stream, BasicBlock &block)
Displays an BasicBlock.
bool operator<(const Immediate &imm1, const Immediate &imm2)
Compares two Immediate (needed for std::map)
register_e
Types of register.
Definition archEnums.hpp:64
@ ID_REG_INVALID
invalid = 0
Definition archEnums.hpp:65
constexpr triton::uint32 byte
byte size in bit
Definition cpuSize.hpp:60
std::uint32_t uint32
unisgned 32-bits
The Triton namespace.