Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 1 | //===------- ItaniumCXXABI.cpp - AST support for the Itanium C++ ABI ------===// |
| 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 | // |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 10 | // This provides C++ AST support targeting the Itanium C++ ABI, which is |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 11 | // documented at: |
| 12 | // http://www.codesourcery.com/public/cxx-abi/abi.html |
| 13 | // http://www.codesourcery.com/public/cxx-abi/abi-eh.html |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 14 | // |
| 15 | // It also supports the closely-related ARM C++ ABI, documented at: |
| 16 | // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0041c/IHI0041C_cppabi.pdf |
| 17 | // |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 18 | //===----------------------------------------------------------------------===// |
| 19 | |
| 20 | #include "CXXABI.h" |
| 21 | #include "clang/AST/ASTContext.h" |
Anders Carlsson | dae0cb5 | 2010-11-25 01:51:53 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclCXX.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 23 | #include "clang/AST/RecordLayout.h" |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 24 | #include "clang/AST/Type.h" |
Anders Carlsson | dae0cb5 | 2010-11-25 01:51:53 +0000 | [diff] [blame] | 25 | #include "clang/Basic/TargetInfo.h" |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace clang; |
| 28 | |
| 29 | namespace { |
| 30 | class ItaniumCXXABI : public CXXABI { |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 31 | protected: |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 32 | ASTContext &Context; |
| 33 | public: |
| 34 | ItaniumCXXABI(ASTContext &Ctx) : Context(Ctx) { } |
| 35 | |
Reid Kleckner | 84e9ab4 | 2013-03-28 20:02:56 +0000 | [diff] [blame^] | 36 | std::pair<uint64_t, unsigned> |
| 37 | getMemberPointerWidthAndAlign(const MemberPointerType *MPT) const { |
| 38 | const TargetInfo &Target = Context.getTargetInfo(); |
| 39 | TargetInfo::IntType PtrDiff = Target.getPtrDiffType(0); |
| 40 | uint64_t Width = Target.getTypeWidth(PtrDiff); |
| 41 | unsigned Align = Target.getTypeAlign(PtrDiff); |
| 42 | if (MPT->getPointeeType()->isFunctionType()) |
| 43 | Width = 2 * Width; |
| 44 | return std::make_pair(Width, Align); |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 45 | } |
Charles Davis | 424ae98 | 2010-10-29 03:25:11 +0000 | [diff] [blame] | 46 | |
Timur Iskhodzhanov | 8f88a1d | 2012-07-12 09:50:54 +0000 | [diff] [blame] | 47 | CallingConv getDefaultMethodCallConv(bool isVariadic) const { |
Charles Davis | 424ae98 | 2010-10-29 03:25:11 +0000 | [diff] [blame] | 48 | return CC_C; |
| 49 | } |
Anders Carlsson | dae0cb5 | 2010-11-25 01:51:53 +0000 | [diff] [blame] | 50 | |
| 51 | // We cheat and just check that the class has a vtable pointer, and that it's |
| 52 | // only big enough to have a vtable pointer and nothing more (or less). |
| 53 | bool isNearlyEmpty(const CXXRecordDecl *RD) const { |
| 54 | |
| 55 | // Check that the class has a vtable pointer. |
| 56 | if (!RD->isDynamicClass()) |
| 57 | return false; |
| 58 | |
| 59 | const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); |
Ken Dyck | 5c3633f | 2011-02-01 01:52:10 +0000 | [diff] [blame] | 60 | CharUnits PointerSize = |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 61 | Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0)); |
Ken Dyck | 5c3633f | 2011-02-01 01:52:10 +0000 | [diff] [blame] | 62 | return Layout.getNonVirtualSize() == PointerSize; |
Anders Carlsson | dae0cb5 | 2010-11-25 01:51:53 +0000 | [diff] [blame] | 63 | } |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 64 | }; |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 65 | |
| 66 | class ARMCXXABI : public ItaniumCXXABI { |
| 67 | public: |
| 68 | ARMCXXABI(ASTContext &Ctx) : ItaniumCXXABI(Ctx) { } |
| 69 | }; |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) { |
| 73 | return new ItaniumCXXABI(Ctx); |
| 74 | } |
| 75 | |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 76 | CXXABI *clang::CreateARMCXXABI(ASTContext &Ctx) { |
| 77 | return new ARMCXXABI(Ctx); |
| 78 | } |