Charles Davis | 53c59df | 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" |
Charles Davis | 31575f7 | 2010-10-29 03:25:11 +0000 | [diff] [blame] | 16 | #include "clang/Basic/TargetInfo.h" |
Charles Davis | 53c59df | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/AST/Type.h" |
| 19 | #include "clang/AST/DeclCXX.h" |
| 20 | |
| 21 | using namespace clang; |
| 22 | |
| 23 | namespace { |
| 24 | class MicrosoftCXXABI : public CXXABI { |
| 25 | ASTContext &Context; |
| 26 | public: |
| 27 | MicrosoftCXXABI(ASTContext &Ctx) : Context(Ctx) { } |
| 28 | |
| 29 | unsigned getMemberPointerSize(const MemberPointerType *MPT) const; |
Charles Davis | 31575f7 | 2010-10-29 03:25:11 +0000 | [diff] [blame] | 30 | |
| 31 | CallingConv getDefaultMethodCallConv() const { |
| 32 | if (Context.Target.getTriple().getArch() == llvm::Triple::x86) |
| 33 | return CC_X86ThisCall; |
| 34 | else |
| 35 | return CC_C; |
| 36 | } |
Charles Davis | 53c59df | 2010-08-16 03:33:14 +0000 | [diff] [blame] | 37 | }; |
| 38 | } |
| 39 | |
| 40 | unsigned MicrosoftCXXABI::getMemberPointerSize(const MemberPointerType *MPT) const { |
| 41 | QualType Pointee = MPT->getPointeeType(); |
| 42 | CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl(); |
| 43 | if (RD->getNumVBases() > 0) { |
| 44 | if (Pointee->isFunctionType()) |
| 45 | return 3; |
| 46 | else |
| 47 | return 2; |
| 48 | } else if (RD->getNumBases() > 1 && Pointee->isFunctionType()) |
| 49 | return 2; |
| 50 | return 1; |
| 51 | } |
| 52 | |
| 53 | CXXABI *clang::CreateMicrosoftCXXABI(ASTContext &Ctx) { |
| 54 | return new MicrosoftCXXABI(Ctx); |
| 55 | } |
| 56 | |