| Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 1 | //===------- MicrosoftCXXABI.cpp - AST support for the Microsoft 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 Microsoft Visual C++ | 
 | 11 | // ABI. | 
 | 12 | // | 
 | 13 | //===----------------------------------------------------------------------===// | 
 | 14 |  | 
 | 15 | #include "CXXABI.h" | 
 | 16 | #include "clang/AST/ASTContext.h" | 
| Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclCXX.h" | 
| Anders Carlsson | dae0cb5 | 2010-11-25 01:51:53 +0000 | [diff] [blame] | 18 | #include "clang/AST/RecordLayout.h" | 
 | 19 | #include "clang/AST/Type.h" | 
 | 20 | #include "clang/Basic/TargetInfo.h" | 
| Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 21 |  | 
 | 22 | using namespace clang; | 
 | 23 |  | 
 | 24 | namespace { | 
 | 25 | class MicrosoftCXXABI : public CXXABI { | 
 | 26 |   ASTContext &Context; | 
 | 27 | public: | 
 | 28 |   MicrosoftCXXABI(ASTContext &Ctx) : Context(Ctx) { } | 
 | 29 |  | 
 | 30 |   unsigned getMemberPointerSize(const MemberPointerType *MPT) const; | 
| Charles Davis | 424ae98 | 2010-10-29 03:25:11 +0000 | [diff] [blame] | 31 |  | 
 | 32 |   CallingConv getDefaultMethodCallConv() const { | 
 | 33 |     if (Context.Target.getTriple().getArch() == llvm::Triple::x86) | 
 | 34 |       return CC_X86ThisCall; | 
 | 35 |     else | 
 | 36 |       return CC_C; | 
 | 37 |   } | 
| Anders Carlsson | dae0cb5 | 2010-11-25 01:51:53 +0000 | [diff] [blame] | 38 |  | 
 | 39 |   bool isNearlyEmpty(const CXXRecordDecl *RD) const { | 
 | 40 |     // FIXME: Audit the corners | 
 | 41 |     if (!RD->isDynamicClass()) | 
 | 42 |       return false; | 
 | 43 |  | 
 | 44 |     const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); | 
 | 45 |      | 
 | 46 |     // In the Microsoft ABI, classes can have one or two vtable pointers. | 
 | 47 |     return Layout.getNonVirtualSize() == Context.Target.getPointerWidth(0) || | 
 | 48 |       Layout.getNonVirtualSize() == Context.Target.getPointerWidth(0) * 2; | 
 | 49 |   }     | 
| Charles Davis | 071cc7d | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 50 | }; | 
 | 51 | } | 
 | 52 |  | 
 | 53 | unsigned MicrosoftCXXABI::getMemberPointerSize(const MemberPointerType *MPT) const { | 
 | 54 |   QualType Pointee = MPT->getPointeeType(); | 
 | 55 |   CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl(); | 
 | 56 |   if (RD->getNumVBases() > 0) { | 
 | 57 |     if (Pointee->isFunctionType()) | 
 | 58 |       return 3; | 
 | 59 |     else | 
 | 60 |       return 2; | 
 | 61 |   } else if (RD->getNumBases() > 1 && Pointee->isFunctionType()) | 
 | 62 |     return 2; | 
 | 63 |   return 1; | 
 | 64 | } | 
 | 65 |  | 
 | 66 | CXXABI *clang::CreateMicrosoftCXXABI(ASTContext &Ctx) { | 
 | 67 |   return new MicrosoftCXXABI(Ctx); | 
 | 68 | } | 
 | 69 |  |