1 //===----- ABI.h - ABI related declarations ---------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Enums/classes describing ABI related information about constructors,
12 /// destructors and thunks.
14 //===----------------------------------------------------------------------===//
16 #ifndef CLANG_BASIC_ABI_H
17 #define CLANG_BASIC_ABI_H
19 #include "llvm/Support/DataTypes.h"
23 /// \brief C++ constructor types.
25 Ctor_Complete, ///< Complete object ctor
26 Ctor_Base, ///< Base object ctor
27 Ctor_CompleteAllocating ///< Complete object allocating ctor
30 /// \brief C++ destructor types.
32 Dtor_Deleting, ///< Deleting dtor
33 Dtor_Complete, ///< Complete object dtor
34 Dtor_Base ///< Base object dtor
37 /// \brief A return adjustment.
38 struct ReturnAdjustment {
39 /// \brief The non-virtual adjustment from the derived object to its
40 /// nearest virtual base.
43 /// \brief Holds the ABI-specific information about the virtual return
44 /// adjustment, if needed.
45 union VirtualAdjustment {
48 /// \brief The offset (in bytes), relative to the address point
49 /// of the virtual base class offset.
50 int64_t VBaseOffsetOffset;
55 /// \brief The offset (in bytes) of the vbptr, relative to the beginning
56 /// of the derived class.
59 /// \brief Index of the virtual base in the vbtable.
64 memset(this, 0, sizeof(*this));
67 bool Equals(const VirtualAdjustment &Other) const {
68 return memcmp(this, &Other, sizeof(Other)) == 0;
71 bool isEmpty() const {
72 VirtualAdjustment Zero;
76 bool Less(const VirtualAdjustment &RHS) const {
77 return memcmp(this, &RHS, sizeof(RHS)) < 0;
81 ReturnAdjustment() : NonVirtual(0) {}
83 bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
85 friend bool operator==(const ReturnAdjustment &LHS,
86 const ReturnAdjustment &RHS) {
87 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
90 friend bool operator!=(const ReturnAdjustment &LHS, const ReturnAdjustment &RHS) {
94 friend bool operator<(const ReturnAdjustment &LHS,
95 const ReturnAdjustment &RHS) {
96 if (LHS.NonVirtual < RHS.NonVirtual)
99 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
103 /// \brief A \c this pointer adjustment.
104 struct ThisAdjustment {
105 /// \brief The non-virtual adjustment from the derived object to its
106 /// nearest virtual base.
109 /// \brief Holds the ABI-specific information about the virtual this
110 /// adjustment, if needed.
111 union VirtualAdjustment {
114 /// \brief The offset (in bytes), relative to the address point,
115 /// of the virtual call offset.
116 int64_t VCallOffsetOffset;
120 /// \brief The offset of the vtordisp (in bytes), relative to the ECX.
121 int32_t VtordispOffset;
123 /// \brief The offset of the vbptr of the derived class (in bytes),
124 /// relative to the ECX after vtordisp adjustment.
127 /// \brief The offset (in bytes) of the vbase offset in the vbtable.
128 int32_t VBOffsetOffset;
131 VirtualAdjustment() {
132 memset(this, 0, sizeof(*this));
135 bool Equals(const VirtualAdjustment &Other) const {
136 return memcmp(this, &Other, sizeof(Other)) == 0;
139 bool isEmpty() const {
140 VirtualAdjustment Zero;
144 bool Less(const VirtualAdjustment &RHS) const {
145 return memcmp(this, &RHS, sizeof(RHS)) < 0;
149 ThisAdjustment() : NonVirtual(0) { }
151 bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
153 friend bool operator==(const ThisAdjustment &LHS,
154 const ThisAdjustment &RHS) {
155 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
158 friend bool operator!=(const ThisAdjustment &LHS, const ThisAdjustment &RHS) {
159 return !(LHS == RHS);
162 friend bool operator<(const ThisAdjustment &LHS,
163 const ThisAdjustment &RHS) {
164 if (LHS.NonVirtual < RHS.NonVirtual)
167 return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
173 /// \brief The \c this pointer adjustment as well as an optional return
174 /// adjustment for a thunk.
176 /// \brief The \c this pointer adjustment.
179 /// \brief The return adjustment.
180 ReturnAdjustment Return;
182 /// \brief Holds a pointer to the overridden method this thunk is for,
183 /// if needed by the ABI to distinguish different thunks with equal
184 /// adjustments. Otherwise, null.
185 /// CAUTION: In the unlikely event you need to sort ThunkInfos, consider using
186 /// an ABI-specific comparator.
187 const CXXMethodDecl *Method;
189 ThunkInfo() : Method(0) { }
191 ThunkInfo(const ThisAdjustment &This, const ReturnAdjustment &Return,
192 const CXXMethodDecl *Method = 0)
193 : This(This), Return(Return), Method(Method) {}
195 friend bool operator==(const ThunkInfo &LHS, const ThunkInfo &RHS) {
196 return LHS.This == RHS.This && LHS.Return == RHS.Return &&
197 LHS.Method == RHS.Method;
200 bool isEmpty() const { return This.isEmpty() && Return.isEmpty() && Method == 0; }
203 } // end namespace clang
205 #endif // CLANG_BASIC_ABI_H