1 //! \file
2 /*
3 **  Copyright (C) - Triton
4 **
5 **  This program is under the terms of the Apache License 2.0.
6 */
7 
8 #include <triton/armOperandProperties.hpp>
9 #include <triton/exceptions.hpp>
10 
11 
12 
13 namespace triton {
14   namespace arch {
15     namespace arm {
16 
ArmOperandProperties()17       ArmOperandProperties::ArmOperandProperties() {
18         this->extendSize          = 0;
19         this->extendType          = triton::arch::arm::ID_EXTEND_INVALID;
20         this->shiftType           = triton::arch::arm::ID_SHIFT_INVALID;
21         this->shiftValueImmediate = 0;
22         this->shiftValueRegister  = triton::arch::ID_REG_INVALID;
23         this->subtracted          = false;
24       }
25 
26 
ArmOperandProperties(const ArmOperandProperties & other)27       ArmOperandProperties::ArmOperandProperties(const ArmOperandProperties& other) {
28         this->extendSize          = other.extendSize;
29         this->extendType          = other.extendType;
30         this->shiftType           = other.shiftType;
31         this->shiftValueImmediate = other.shiftValueImmediate;
32         this->shiftValueRegister  = other.shiftValueRegister;
33         this->subtracted          = other.subtracted;
34       }
35 
36 
operator =(const ArmOperandProperties & other)37       ArmOperandProperties& ArmOperandProperties::operator=(const ArmOperandProperties& other) {
38         this->extendSize          = other.extendSize;
39         this->extendType          = other.extendType;
40         this->shiftType           = other.shiftType;
41         this->shiftValueImmediate = other.shiftValueImmediate;
42         this->shiftValueRegister  = other.shiftValueRegister;
43         this->subtracted          = other.subtracted;
44         return *this;
45       }
46 
47 
getShiftType(void) const48       triton::arch::arm::shift_e ArmOperandProperties::getShiftType(void) const {
49         return this->shiftType;
50       }
51 
52 
getShiftImmediate(void) const53       triton::uint32 ArmOperandProperties::getShiftImmediate(void) const {
54         return this->shiftValueImmediate;
55       }
56 
57 
getShiftRegister(void) const58       triton::arch::register_e ArmOperandProperties::getShiftRegister(void) const {
59         return this->shiftValueRegister;
60       }
61 
62 
getExtendType(void) const63       triton::arch::arm::extend_e ArmOperandProperties::getExtendType(void) const {
64         return this->extendType;
65       }
66 
67 
getExtendSize(void) const68       triton::uint32 ArmOperandProperties::getExtendSize(void) const {
69         return this->extendSize;
70       }
71 
72 
isSubtracted(void) const73       bool ArmOperandProperties::isSubtracted(void) const {
74         return this->subtracted;
75       }
76 
77 
setShiftValue(triton::uint32 imm)78       void ArmOperandProperties::setShiftValue(triton::uint32 imm) {
79         this->shiftValueImmediate = imm;
80       }
81 
82 
setShiftValue(triton::arch::register_e reg)83       void ArmOperandProperties::setShiftValue(triton::arch::register_e reg) {
84         this->shiftValueRegister = reg;
85       }
86 
87 
setShiftType(triton::arch::arm::shift_e type)88       void ArmOperandProperties::setShiftType(triton::arch::arm::shift_e type) {
89         if (type >= triton::arch::arm::ID_SHIFT_LAST_ITEM)
90           throw triton::exceptions::ArmOperandProperties("ArmOperandProperties::setShiftType(): invalid type of shift.");
91         this->shiftType = type;
92       }
93 
94 
setExtendType(triton::arch::arm::extend_e type)95       void ArmOperandProperties::setExtendType(triton::arch::arm::extend_e type) {
96         if (type >= triton::arch::arm::ID_EXTEND_LAST_ITEM)
97           throw triton::exceptions::ArmOperandProperties("ArmOperandProperties::setExtendType(): invalid type of extend.");
98         this->extendType = type;
99       }
100 
101 
setExtendedSize(triton::uint32 dstSize)102       void ArmOperandProperties::setExtendedSize(triton::uint32 dstSize) {
103         switch (this->extendType) {
104           case triton::arch::arm::ID_EXTEND_SXTB:
105           case triton::arch::arm::ID_EXTEND_UXTB:
106             this->extendSize = dstSize - 8;
107             break;
108 
109           case triton::arch::arm::ID_EXTEND_SXTH:
110           case triton::arch::arm::ID_EXTEND_UXTH:
111             this->extendSize = dstSize - 16;
112             break;
113 
114           case triton::arch::arm::ID_EXTEND_SXTW:
115           case triton::arch::arm::ID_EXTEND_UXTW:
116             this->extendSize = dstSize - 32;
117             break;
118 
119           case triton::arch::arm::ID_EXTEND_SXTX:
120           case triton::arch::arm::ID_EXTEND_UXTX:
121             this->extendSize = dstSize - 64;
122             break;
123 
124           default:
125             throw triton::exceptions::ArmOperandProperties("ArmOperandProperties::setExtendedSize(): invalid type of extend");
126         }
127 
128         if (this->extendSize > 64)
129           throw triton::exceptions::ArmOperandProperties("ArmOperandProperties::setExtendedSize(): invalid size of extension (integer overflow).");
130 
131         if (dstSize != 8 && dstSize != 16 && dstSize != 32 && dstSize != 64)
132           throw triton::exceptions::ArmOperandProperties("ArmOperandProperties::setExtendedSize(): size must be 8, 16, 32 or 64.");
133       }
134 
135 
setSubtracted(bool value)136       void ArmOperandProperties::setSubtracted(bool value) {
137         this->subtracted = value;
138       }
139 
140     }; /* arm namespace */
141   }; /* arch namespace */
142 }; /* triton namespace */
143