1 //===------- ItaniumCXXABI.cpp - AST support for the Itanium C++ ABI ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This provides C++ AST support targeting the Itanium C++ ABI, which is
12 // http://www.codesourcery.com/public/cxx-abi/abi.html
13 // http://www.codesourcery.com/public/cxx-abi/abi-eh.html
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
18 //===----------------------------------------------------------------------===//
21 #include "clang/AST/ASTContext.h"
22 #include "clang/AST/RecordLayout.h"
23 #include "clang/AST/DeclCXX.h"
24 #include "clang/AST/Type.h"
25 #include "clang/Basic/TargetInfo.h"
27 using namespace clang;
30 class ItaniumCXXABI : public CXXABI {
34 ItaniumCXXABI(ASTContext &Ctx) : Context(Ctx) { }
36 unsigned getMemberPointerSize(const MemberPointerType *MPT) const {
37 QualType Pointee = MPT->getPointeeType();
38 if (Pointee->isFunctionType()) return 2;
42 CallingConv getDefaultMethodCallConv() const {
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 {
50 // Check that the class has a vtable pointer.
51 if (!RD->isDynamicClass())
54 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
55 CharUnits PointerSize =
56 Context.toCharUnitsFromBits(Context.Target.getPointerWidth(0));
57 return Layout.getNonVirtualSize() == PointerSize;
61 class ARMCXXABI : public ItaniumCXXABI {
63 ARMCXXABI(ASTContext &Ctx) : ItaniumCXXABI(Ctx) { }
67 CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) {
68 return new ItaniumCXXABI(Ctx);
71 CXXABI *clang::CreateARMCXXABI(ASTContext &Ctx) {
72 return new ARMCXXABI(Ctx);