clang API Documentation

ABI.h
Go to the documentation of this file.
00001 //===----- ABI.h - ABI related declarations ---------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief Enums/classes describing ABI related information about constructors,
00012 /// destructors and thunks.
00013 ///
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_CLANG_BASIC_ABI_H
00017 #define LLVM_CLANG_BASIC_ABI_H
00018 
00019 #include "llvm/Support/DataTypes.h"
00020 
00021 namespace clang {
00022 
00023 /// \brief C++ constructor types.
00024 enum CXXCtorType {
00025     Ctor_Complete,          ///< Complete object ctor
00026     Ctor_Base,              ///< Base object ctor
00027     Ctor_Comdat             ///< The COMDAT used for ctors
00028 };
00029 
00030 /// \brief C++ destructor types.
00031 enum CXXDtorType {
00032     Dtor_Deleting, ///< Deleting dtor
00033     Dtor_Complete, ///< Complete object dtor
00034     Dtor_Base,     ///< Base object dtor
00035     Dtor_Comdat    ///< The COMDAT used for dtors
00036 };
00037 
00038 /// \brief A return adjustment.
00039 struct ReturnAdjustment {
00040   /// \brief The non-virtual adjustment from the derived object to its
00041   /// nearest virtual base.
00042   int64_t NonVirtual;
00043 
00044   /// \brief Holds the ABI-specific information about the virtual return
00045   /// adjustment, if needed.
00046   union VirtualAdjustment {
00047     // Itanium ABI
00048     struct {
00049       /// \brief The offset (in bytes), relative to the address point
00050       /// of the virtual base class offset.
00051       int64_t VBaseOffsetOffset;
00052     } Itanium;
00053 
00054     // Microsoft ABI
00055     struct {
00056       /// \brief The offset (in bytes) of the vbptr, relative to the beginning
00057       /// of the derived class.
00058       uint32_t VBPtrOffset;
00059 
00060       /// \brief Index of the virtual base in the vbtable.
00061       uint32_t VBIndex;
00062     } Microsoft;
00063 
00064     VirtualAdjustment() {
00065       memset(this, 0, sizeof(*this));
00066     }
00067 
00068     bool Equals(const VirtualAdjustment &Other) const {
00069       return memcmp(this, &Other, sizeof(Other)) == 0;
00070     }
00071 
00072     bool isEmpty() const {
00073       VirtualAdjustment Zero;
00074       return Equals(Zero);
00075     }
00076 
00077     bool Less(const VirtualAdjustment &RHS) const {
00078       return memcmp(this, &RHS, sizeof(RHS)) < 0;
00079     }
00080   } Virtual;
00081   
00082   ReturnAdjustment() : NonVirtual(0) {}
00083   
00084   bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
00085 
00086   friend bool operator==(const ReturnAdjustment &LHS, 
00087                          const ReturnAdjustment &RHS) {
00088     return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
00089   }
00090 
00091   friend bool operator!=(const ReturnAdjustment &LHS, const ReturnAdjustment &RHS) {
00092     return !(LHS == RHS);
00093   }
00094 
00095   friend bool operator<(const ReturnAdjustment &LHS,
00096                         const ReturnAdjustment &RHS) {
00097     if (LHS.NonVirtual < RHS.NonVirtual)
00098       return true;
00099 
00100     return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
00101   }
00102 };
00103   
00104 /// \brief A \c this pointer adjustment.
00105 struct ThisAdjustment {
00106   /// \brief The non-virtual adjustment from the derived object to its
00107   /// nearest virtual base.
00108   int64_t NonVirtual;
00109 
00110   /// \brief Holds the ABI-specific information about the virtual this
00111   /// adjustment, if needed.
00112   union VirtualAdjustment {
00113     // Itanium ABI
00114     struct {
00115       /// \brief The offset (in bytes), relative to the address point,
00116       /// of the virtual call offset.
00117       int64_t VCallOffsetOffset;
00118     } Itanium;
00119 
00120     struct {
00121       /// \brief The offset of the vtordisp (in bytes), relative to the ECX.
00122       int32_t VtordispOffset;
00123 
00124       /// \brief The offset of the vbptr of the derived class (in bytes),
00125       /// relative to the ECX after vtordisp adjustment.
00126       int32_t VBPtrOffset;
00127 
00128       /// \brief The offset (in bytes) of the vbase offset in the vbtable.
00129       int32_t VBOffsetOffset;
00130     } Microsoft;
00131 
00132     VirtualAdjustment() {
00133       memset(this, 0, sizeof(*this));
00134     }
00135 
00136     bool Equals(const VirtualAdjustment &Other) const {
00137       return memcmp(this, &Other, sizeof(Other)) == 0;
00138     }
00139 
00140     bool isEmpty() const {
00141       VirtualAdjustment Zero;
00142       return Equals(Zero);
00143     }
00144 
00145     bool Less(const VirtualAdjustment &RHS) const {
00146       return memcmp(this, &RHS, sizeof(RHS)) < 0;
00147     }
00148   } Virtual;
00149   
00150   ThisAdjustment() : NonVirtual(0) { }
00151 
00152   bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
00153 
00154   friend bool operator==(const ThisAdjustment &LHS, 
00155                          const ThisAdjustment &RHS) {
00156     return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Equals(RHS.Virtual);
00157   }
00158 
00159   friend bool operator!=(const ThisAdjustment &LHS, const ThisAdjustment &RHS) {
00160     return !(LHS == RHS);
00161   }
00162   
00163   friend bool operator<(const ThisAdjustment &LHS,
00164                         const ThisAdjustment &RHS) {
00165     if (LHS.NonVirtual < RHS.NonVirtual)
00166       return true;
00167     
00168     return LHS.NonVirtual == RHS.NonVirtual && LHS.Virtual.Less(RHS.Virtual);
00169   }
00170 };
00171 
00172 class CXXMethodDecl;
00173 
00174 /// \brief The \c this pointer adjustment as well as an optional return
00175 /// adjustment for a thunk.
00176 struct ThunkInfo {
00177   /// \brief The \c this pointer adjustment.
00178   ThisAdjustment This;
00179     
00180   /// \brief The return adjustment.
00181   ReturnAdjustment Return;
00182 
00183   /// \brief Holds a pointer to the overridden method this thunk is for,
00184   /// if needed by the ABI to distinguish different thunks with equal
00185   /// adjustments. Otherwise, null.
00186   /// CAUTION: In the unlikely event you need to sort ThunkInfos, consider using
00187   /// an ABI-specific comparator.
00188   const CXXMethodDecl *Method;
00189 
00190   ThunkInfo() : Method(nullptr) { }
00191 
00192   ThunkInfo(const ThisAdjustment &This, const ReturnAdjustment &Return,
00193             const CXXMethodDecl *Method = nullptr)
00194       : This(This), Return(Return), Method(Method) {}
00195 
00196   friend bool operator==(const ThunkInfo &LHS, const ThunkInfo &RHS) {
00197     return LHS.This == RHS.This && LHS.Return == RHS.Return &&
00198            LHS.Method == RHS.Method;
00199   }
00200 
00201   bool isEmpty() const {
00202     return This.isEmpty() && Return.isEmpty() && Method == nullptr;
00203   }
00204 };  
00205 
00206 } // end namespace clang
00207 
00208 #endif