2010-09-17 15:54:40 +00: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-05-02 19:39:53 +00:00
|
|
|
// This provides C++ AST support targeting the Itanium C++ ABI, which is
|
2010-09-17 15:54:40 +00:00
|
|
|
// documented at:
|
|
|
|
// http://www.codesourcery.com/public/cxx-abi/abi.html
|
|
|
|
// http://www.codesourcery.com/public/cxx-abi/abi-eh.html
|
|
|
|
//
|
|
|
|
// It also supports the closely-related ARM C++ ABI, documented at:
|
|
|
|
// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0041c/IHI0041C_cppabi.pdf
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CXXABI.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2011-02-20 13:06:31 +00:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2013-12-22 00:07:40 +00:00
|
|
|
#include "clang/AST/MangleNumberingContext.h"
|
2013-04-08 18:45:10 +00:00
|
|
|
#include "clang/AST/RecordLayout.h"
|
2010-09-17 15:54:40 +00:00
|
|
|
#include "clang/AST/Type.h"
|
2011-02-20 13:06:31 +00:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2010-09-17 15:54:40 +00:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
namespace {
|
2013-12-22 00:07:40 +00: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-11-24 09:15:30 +00:00
|
|
|
llvm::DenseMap<IdentifierInfo*, unsigned> TagManglingNumbers;
|
2013-12-22 00:07:40 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// Variable decls are numbered by identifier.
|
2014-11-24 09:15:30 +00:00
|
|
|
unsigned getManglingNumber(const VarDecl *VD, unsigned) override {
|
2013-12-22 00:07:40 +00:00
|
|
|
return ++VarManglingNumbers[VD->getIdentifier()];
|
|
|
|
}
|
2014-11-24 09:15:30 +00:00
|
|
|
|
|
|
|
unsigned getManglingNumber(const TagDecl *TD, unsigned) override {
|
|
|
|
return ++TagManglingNumbers[TD->getIdentifier()];
|
|
|
|
}
|
2013-12-22 00:07:40 +00:00
|
|
|
};
|
|
|
|
|
2010-09-17 15:54:40 +00:00
|
|
|
class ItaniumCXXABI : public CXXABI {
|
|
|
|
protected:
|
|
|
|
ASTContext &Context;
|
|
|
|
public:
|
|
|
|
ItaniumCXXABI(ASTContext &Ctx) : Context(Ctx) { }
|
|
|
|
|
2013-04-08 18:45:10 +00:00
|
|
|
std::pair<uint64_t, unsigned>
|
2014-11-24 09:15:30 +00:00
|
|
|
getMemberPointerWidthAndAlign(const MemberPointerType *MPT) const override {
|
2013-04-08 18:45:10 +00:00
|
|
|
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-09-17 15:54:40 +00:00
|
|
|
}
|
2011-02-20 13:06:31 +00:00
|
|
|
|
2014-11-24 09:15:30 +00:00
|
|
|
CallingConv getDefaultMethodCallConv(bool isVariadic) const override {
|
|
|
|
const llvm::Triple &T = Context.getTargetInfo().getTriple();
|
|
|
|
if (!isVariadic && T.isWindowsGNUEnvironment() &&
|
|
|
|
T.getArch() == llvm::Triple::x86)
|
|
|
|
return CC_X86ThisCall;
|
2011-02-20 13:06:31 +00:00
|
|
|
return CC_C;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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).
|
2014-11-24 09:15:30 +00:00
|
|
|
bool isNearlyEmpty(const CXXRecordDecl *RD) const override {
|
2011-02-20 13:06:31 +00:00
|
|
|
|
|
|
|
// Check that the class has a vtable pointer.
|
|
|
|
if (!RD->isDynamicClass())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
|
|
|
|
CharUnits PointerSize =
|
2011-10-20 21:14:49 +00:00
|
|
|
Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0));
|
2011-02-20 13:06:31 +00:00
|
|
|
return Layout.getNonVirtualSize() == PointerSize;
|
|
|
|
}
|
2013-12-22 00:07:40 +00:00
|
|
|
|
2014-11-24 09:15:30 +00:00
|
|
|
MangleNumberingContext *createMangleNumberingContext() const override {
|
2013-12-22 00:07:40 +00:00
|
|
|
return new ItaniumNumberingContext();
|
|
|
|
}
|
2010-09-17 15:54:40 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) {
|
|
|
|
return new ItaniumCXXABI(Ctx);
|
|
|
|
}
|