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 | // |
| 10 | // This provides C++ AST support targetting the Itanium C++ ABI, which is |
| 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/RecordLayout.h" |
| 23 | #include "clang/AST/DeclCXX.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 | |
| 36 | unsigned getMemberPointerSize(const MemberPointerType *MPT) const { |
| 37 | QualType Pointee = MPT->getPointeeType(); |
| 38 | if (Pointee->isFunctionType()) return 2; |
| 39 | return 1; |
| 40 | } |
Charles Davis | 424ae98 | 2010-10-29 03:25:11 +0000 | [diff] [blame] | 41 | |
| 42 | CallingConv getDefaultMethodCallConv() const { |
| 43 | return CC_C; |
| 44 | } |
Anders Carlsson | dae0cb5 | 2010-11-25 01:51:53 +0000 | [diff] [blame] | 45 | |
| 46 | // We cheat and just check that the class has a vtable pointer, and that it's |
| 47 | // only big enough to have a vtable pointer and nothing more (or less). |
| 48 | bool isNearlyEmpty(const CXXRecordDecl *RD) const { |
| 49 | |
| 50 | // Check that the class has a vtable pointer. |
| 51 | if (!RD->isDynamicClass()) |
| 52 | return false; |
| 53 | |
| 54 | const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); |
| 55 | return Layout.getNonVirtualSize() == Context.Target.getPointerWidth(0); |
| 56 | } |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 57 | }; |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 58 | |
| 59 | class ARMCXXABI : public ItaniumCXXABI { |
| 60 | public: |
| 61 | ARMCXXABI(ASTContext &Ctx) : ItaniumCXXABI(Ctx) { } |
| 62 | }; |
Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) { |
| 66 | return new ItaniumCXXABI(Ctx); |
| 67 | } |
| 68 | |
John McCall | ee79a4c | 2010-08-21 22:46:04 +0000 | [diff] [blame] | 69 | CXXABI *clang::CreateARMCXXABI(ASTContext &Ctx) { |
| 70 | return new ARMCXXABI(Ctx); |
| 71 | } |