2010-08-16 11:33:14 +08:00
|
|
|
//===------- ItaniumCXXABI.cpp - AST support for the Itanium C++ ABI ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-04-15 13:22:18 +08:00
|
|
|
// This provides C++ AST support targeting the Itanium C++ ABI, which is
|
2010-08-16 11:33:14 +08:00
|
|
|
// documented at:
|
|
|
|
// http://www.codesourcery.com/public/cxx-abi/abi.html
|
|
|
|
// http://www.codesourcery.com/public/cxx-abi/abi-eh.html
|
2010-08-22 06:46:04 +08:00
|
|
|
//
|
|
|
|
// It also supports the closely-related ARM C++ ABI, documented at:
|
|
|
|
// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0041c/IHI0041C_cppabi.pdf
|
|
|
|
//
|
2010-08-16 11:33:14 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CXXABI.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2010-11-25 09:51:53 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2013-09-11 04:14:30 +08:00
|
|
|
#include "clang/AST/MangleNumberingContext.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/RecordLayout.h"
|
2010-08-16 11:33:14 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2010-11-25 09:51:53 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2010-08-16 11:33:14 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
namespace {
|
2013-09-11 04:14:30 +08:00
|
|
|
|
|
|
|
/// \brief Keeps track of the mangled names of lambda expressions and block
|
|
|
|
/// literals within a particular context.
|
|
|
|
class ItaniumNumberingContext : public MangleNumberingContext {
|
|
|
|
llvm::DenseMap<IdentifierInfo*, unsigned> VarManglingNumbers;
|
2014-03-05 16:57:59 +08:00
|
|
|
llvm::DenseMap<IdentifierInfo*, unsigned> TagManglingNumbers;
|
2013-09-11 04:14:30 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// Variable decls are numbered by identifier.
|
2014-03-06 02:55:38 +08:00
|
|
|
virtual unsigned getManglingNumber(const VarDecl *VD, unsigned) {
|
2013-09-11 04:14:30 +08:00
|
|
|
return ++VarManglingNumbers[VD->getIdentifier()];
|
|
|
|
}
|
2014-03-05 16:57:59 +08:00
|
|
|
|
2014-03-06 02:55:38 +08:00
|
|
|
virtual unsigned getManglingNumber(const TagDecl *TD, unsigned) {
|
2014-03-05 16:57:59 +08:00
|
|
|
return ++TagManglingNumbers[TD->getIdentifier()];
|
|
|
|
}
|
2013-09-11 04:14:30 +08:00
|
|
|
};
|
|
|
|
|
2010-08-16 11:33:14 +08:00
|
|
|
class ItaniumCXXABI : public CXXABI {
|
2010-08-22 06:46:04 +08:00
|
|
|
protected:
|
2010-08-16 11:33:14 +08:00
|
|
|
ASTContext &Context;
|
|
|
|
public:
|
|
|
|
ItaniumCXXABI(ASTContext &Ctx) : Context(Ctx) { }
|
|
|
|
|
2013-03-29 04:02:56 +08:00
|
|
|
std::pair<uint64_t, unsigned>
|
|
|
|
getMemberPointerWidthAndAlign(const MemberPointerType *MPT) const {
|
|
|
|
const TargetInfo &Target = Context.getTargetInfo();
|
|
|
|
TargetInfo::IntType PtrDiff = Target.getPtrDiffType(0);
|
|
|
|
uint64_t Width = Target.getTypeWidth(PtrDiff);
|
|
|
|
unsigned Align = Target.getTypeAlign(PtrDiff);
|
|
|
|
if (MPT->getPointeeType()->isFunctionType())
|
|
|
|
Width = 2 * Width;
|
|
|
|
return std::make_pair(Width, Align);
|
2010-08-16 11:33:14 +08:00
|
|
|
}
|
2010-10-29 11:25:11 +08:00
|
|
|
|
2012-07-12 17:50:54 +08:00
|
|
|
CallingConv getDefaultMethodCallConv(bool isVariadic) const {
|
2013-12-13 00:07:11 +08:00
|
|
|
const llvm::Triple &T = Context.getTargetInfo().getTriple();
|
|
|
|
if (!isVariadic && T.getOS() == llvm::Triple::MinGW32 &&
|
|
|
|
T.getArch() == llvm::Triple::x86)
|
|
|
|
return CC_X86ThisCall;
|
2010-10-29 11:25:11 +08:00
|
|
|
return CC_C;
|
|
|
|
}
|
2010-11-25 09:51:53 +08:00
|
|
|
|
|
|
|
// We cheat and just check that the class has a vtable pointer, and that it's
|
|
|
|
// only big enough to have a vtable pointer and nothing more (or less).
|
|
|
|
bool isNearlyEmpty(const CXXRecordDecl *RD) const {
|
|
|
|
|
|
|
|
// Check that the class has a vtable pointer.
|
|
|
|
if (!RD->isDynamicClass())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
|
2011-02-01 09:52:10 +08:00
|
|
|
CharUnits PointerSize =
|
2011-09-02 08:18:52 +08:00
|
|
|
Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0));
|
2011-02-01 09:52:10 +08:00
|
|
|
return Layout.getNonVirtualSize() == PointerSize;
|
2010-11-25 09:51:53 +08:00
|
|
|
}
|
2013-09-11 04:14:30 +08:00
|
|
|
|
|
|
|
virtual MangleNumberingContext *createMangleNumberingContext() const {
|
|
|
|
return new ItaniumNumberingContext();
|
|
|
|
}
|
2010-08-16 11:33:14 +08:00
|
|
|
};
|
2010-08-22 06:46:04 +08:00
|
|
|
|
|
|
|
class ARMCXXABI : public ItaniumCXXABI {
|
|
|
|
public:
|
|
|
|
ARMCXXABI(ASTContext &Ctx) : ItaniumCXXABI(Ctx) { }
|
|
|
|
};
|
2010-08-16 11:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) {
|
|
|
|
return new ItaniumCXXABI(Ctx);
|
|
|
|
}
|
|
|
|
|
2010-08-22 06:46:04 +08:00
|
|
|
CXXABI *clang::CreateARMCXXABI(ASTContext &Ctx) {
|
|
|
|
return new ARMCXXABI(Ctx);
|
|
|
|
}
|