blob: b1f032b897aec5c9ef3dc831152917c23f728bc3 [file] [log] [blame]
Charles Davis53c59df2010-08-16 03:33:14 +00001//===------- 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 Davis31575f72010-10-29 03:25:11 +000016#include "clang/Basic/TargetInfo.h"
Charles Davis53c59df2010-08-16 03:33:14 +000017#include "clang/AST/ASTContext.h"
18#include "clang/AST/Type.h"
19#include "clang/AST/DeclCXX.h"
20
21using namespace clang;
22
23namespace {
24class MicrosoftCXXABI : public CXXABI {
25 ASTContext &Context;
26public:
27 MicrosoftCXXABI(ASTContext &Ctx) : Context(Ctx) { }
28
29 unsigned getMemberPointerSize(const MemberPointerType *MPT) const;
Charles Davis31575f72010-10-29 03:25:11 +000030
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 Davis53c59df2010-08-16 03:33:14 +000037};
38}
39
40unsigned 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
53CXXABI *clang::CreateMicrosoftCXXABI(ASTContext &Ctx) {
54 return new MicrosoftCXXABI(Ctx);
55}
56