1//===----- ABI.h - ABI related declarations ---------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// These enums/classes describe ABI related information about constructors,
11// destructors and thunks.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef CLANG_BASIC_ABI_H
16#define CLANG_BASIC_ABI_H
17
18#include "llvm/Support/DataTypes.h"
19
20namespace clang {
21
22/// CXXCtorType - C++ constructor types
23enum CXXCtorType {
24    Ctor_Complete,          // Complete object ctor
25    Ctor_Base,              // Base object ctor
26    Ctor_CompleteAllocating // Complete object allocating ctor
27};
28
29/// CXXDtorType - C++ destructor types
30enum CXXDtorType {
31    Dtor_Deleting, // Deleting dtor
32    Dtor_Complete, // Complete object dtor
33    Dtor_Base      // Base object dtor
34};
35
36/// ReturnAdjustment - A return adjustment.
37struct ReturnAdjustment {
38  /// NonVirtual - The non-virtual adjustment from the derived object to its
39  /// nearest virtual base.
40  int64_t NonVirtual;
41
42  /// VBaseOffsetOffset - The offset (in bytes), relative to the address point
43  /// of the virtual base class offset.
44  int64_t VBaseOffsetOffset;
45
46  ReturnAdjustment() : NonVirtual(0), VBaseOffsetOffset(0) { }
47
48  bool isEmpty() const { return !NonVirtual && !VBaseOffsetOffset; }
49
50  friend bool operator==(const ReturnAdjustment &LHS,
51                         const ReturnAdjustment &RHS) {
52    return LHS.NonVirtual == RHS.NonVirtual &&
53      LHS.VBaseOffsetOffset == RHS.VBaseOffsetOffset;
54  }
55
56  friend bool operator<(const ReturnAdjustment &LHS,
57                        const ReturnAdjustment &RHS) {
58    if (LHS.NonVirtual < RHS.NonVirtual)
59      return true;
60
61    return LHS.NonVirtual == RHS.NonVirtual &&
62      LHS.VBaseOffsetOffset < RHS.VBaseOffsetOffset;
63  }
64};
65
66/// ThisAdjustment - A 'this' pointer adjustment.
67struct ThisAdjustment {
68  /// NonVirtual - The non-virtual adjustment from the derived object to its
69  /// nearest virtual base.
70  int64_t NonVirtual;
71
72  /// VCallOffsetOffset - The offset (in bytes), relative to the address point,
73  /// of the virtual call offset.
74  int64_t VCallOffsetOffset;
75
76  ThisAdjustment() : NonVirtual(0), VCallOffsetOffset(0) { }
77
78  bool isEmpty() const { return !NonVirtual && !VCallOffsetOffset; }
79
80  friend bool operator==(const ThisAdjustment &LHS,
81                         const ThisAdjustment &RHS) {
82    return LHS.NonVirtual == RHS.NonVirtual &&
83      LHS.VCallOffsetOffset == RHS.VCallOffsetOffset;
84  }
85
86  friend bool operator<(const ThisAdjustment &LHS,
87                        const ThisAdjustment &RHS) {
88    if (LHS.NonVirtual < RHS.NonVirtual)
89      return true;
90
91    return LHS.NonVirtual == RHS.NonVirtual &&
92      LHS.VCallOffsetOffset < RHS.VCallOffsetOffset;
93  }
94};
95
96/// ThunkInfo - The 'this' pointer adjustment as well as an optional return
97/// adjustment for a thunk.
98struct ThunkInfo {
99  /// This - The 'this' pointer adjustment.
100  ThisAdjustment This;
101
102  /// Return - The return adjustment.
103  ReturnAdjustment Return;
104
105  ThunkInfo() { }
106
107  ThunkInfo(const ThisAdjustment &This, const ReturnAdjustment &Return)
108    : This(This), Return(Return) { }
109
110  friend bool operator==(const ThunkInfo &LHS, const ThunkInfo &RHS) {
111    return LHS.This == RHS.This && LHS.Return == RHS.Return;
112  }
113
114  friend bool operator<(const ThunkInfo &LHS, const ThunkInfo &RHS) {
115    if (LHS.This < RHS.This)
116      return true;
117
118    return LHS.This == RHS.This && LHS.Return < RHS.Return;
119  }
120
121  bool isEmpty() const { return This.isEmpty() && Return.isEmpty(); }
122};
123
124} // end namespace clang
125
126#endif // CLANG_BASIC_ABI_H
127