blob: ce1244c542726488a831c3d70588733104c40e87 [file] [log] [blame]
Charles Davis53c59df2010-08-16 03:33:14 +00001//===------- 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//
Chris Lattner57540c52011-04-15 05:22:18 +000010// This provides C++ AST support targeting the Itanium C++ ABI, which is
Charles Davis53c59df2010-08-16 03:33:14 +000011// documented at:
12// http://www.codesourcery.com/public/cxx-abi/abi.html
13// http://www.codesourcery.com/public/cxx-abi/abi-eh.html
John McCall86353412010-08-21 22:46:04 +000014//
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 Davis53c59df2010-08-16 03:33:14 +000018//===----------------------------------------------------------------------===//
19
20#include "CXXABI.h"
21#include "clang/AST/ASTContext.h"
Anders Carlsson60a62632010-11-25 01:51:53 +000022#include "clang/AST/RecordLayout.h"
23#include "clang/AST/DeclCXX.h"
Charles Davis53c59df2010-08-16 03:33:14 +000024#include "clang/AST/Type.h"
Anders Carlsson60a62632010-11-25 01:51:53 +000025#include "clang/Basic/TargetInfo.h"
Charles Davis53c59df2010-08-16 03:33:14 +000026
27using namespace clang;
28
29namespace {
30class ItaniumCXXABI : public CXXABI {
John McCall86353412010-08-21 22:46:04 +000031protected:
Charles Davis53c59df2010-08-16 03:33:14 +000032 ASTContext &Context;
33public:
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 Davis31575f72010-10-29 03:25:11 +000041
Timur Iskhodzhanovc5098ad2012-07-12 09:50:54 +000042 CallingConv getDefaultMethodCallConv(bool isVariadic) const {
Charles Davis31575f72010-10-29 03:25:11 +000043 return CC_C;
44 }
Anders Carlsson60a62632010-11-25 01:51:53 +000045
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);
Ken Dyck316d6f62011-02-01 01:52:10 +000055 CharUnits PointerSize =
Douglas Gregore8bbc122011-09-02 00:18:52 +000056 Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0));
Ken Dyck316d6f62011-02-01 01:52:10 +000057 return Layout.getNonVirtualSize() == PointerSize;
Anders Carlsson60a62632010-11-25 01:51:53 +000058 }
Charles Davis53c59df2010-08-16 03:33:14 +000059};
John McCall86353412010-08-21 22:46:04 +000060
61class ARMCXXABI : public ItaniumCXXABI {
62public:
63 ARMCXXABI(ASTContext &Ctx) : ItaniumCXXABI(Ctx) { }
64};
Charles Davis53c59df2010-08-16 03:33:14 +000065}
66
67CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) {
68 return new ItaniumCXXABI(Ctx);
69}
70
John McCall86353412010-08-21 22:46:04 +000071CXXABI *clang::CreateARMCXXABI(ASTContext &Ctx) {
72 return new ARMCXXABI(Ctx);
73}