forked from OSchip/llvm-project
Implement support for member pointers under the Microsoft C++ ABI in the
AST library. This also adds infrastructure for supporting multiple C++ ABIs in the AST. llvm-svn: 111117
This commit is contained in:
parent
df28e8ec41
commit
53c59df2f7
|
@ -50,6 +50,7 @@ namespace clang {
|
|||
class SelectorTable;
|
||||
class SourceManager;
|
||||
class TargetInfo;
|
||||
class CXXABI;
|
||||
// Decls
|
||||
class DeclContext;
|
||||
class CXXMethodDecl;
|
||||
|
@ -283,6 +284,10 @@ class ASTContext {
|
|||
|
||||
/// \brief Allocator for partial diagnostics.
|
||||
PartialDiagnostic::StorageAllocator DiagAllocator;
|
||||
|
||||
/// \brief The current C++ ABI.
|
||||
CXXABI *ABI;
|
||||
CXXABI *createCXXABI(const TargetInfo &T);
|
||||
|
||||
public:
|
||||
const TargetInfo &Target;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "CXXABI.h"
|
||||
|
||||
using namespace clang;
|
||||
|
||||
|
@ -134,6 +135,14 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
|
|||
return CanonTTP;
|
||||
}
|
||||
|
||||
CXXABI *ASTContext::createCXXABI(const TargetInfo &T) {
|
||||
if (!LangOpts.CPlusPlus) return NULL;
|
||||
if (T.getCXXABI() == "microsoft")
|
||||
return CreateMicrosoftCXXABI(*this);
|
||||
else
|
||||
return CreateItaniumCXXABI(*this);
|
||||
}
|
||||
|
||||
ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
|
||||
const TargetInfo &t,
|
||||
IdentifierTable &idents, SelectorTable &sels,
|
||||
|
@ -146,7 +155,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
|
|||
ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0), jmp_bufDecl(0),
|
||||
sigjmp_bufDecl(0), BlockDescriptorType(0), BlockDescriptorExtendedType(0),
|
||||
NullTypeSourceInfo(QualType()),
|
||||
SourceMgr(SM), LangOpts(LOpts), Target(t),
|
||||
SourceMgr(SM), LangOpts(LOpts), ABI(createCXXABI(t)), Target(t),
|
||||
Idents(idents), Selectors(sels),
|
||||
BuiltinInfo(builtins),
|
||||
DeclarationNames(*this),
|
||||
|
@ -700,12 +709,10 @@ ASTContext::getTypeInfo(const Type *T) {
|
|||
break;
|
||||
}
|
||||
case Type::MemberPointer: {
|
||||
QualType Pointee = cast<MemberPointerType>(T)->getPointeeType();
|
||||
const MemberPointerType *MPT = cast<MemberPointerType>(T);
|
||||
std::pair<uint64_t, unsigned> PtrDiffInfo =
|
||||
getTypeInfo(getPointerDiffType());
|
||||
Width = PtrDiffInfo.first;
|
||||
if (Pointee->isFunctionType())
|
||||
Width *= 2;
|
||||
Width = PtrDiffInfo.first * ABI->getMemberPointerSize(MPT);
|
||||
Align = PtrDiffInfo.second;
|
||||
break;
|
||||
}
|
||||
|
@ -5640,3 +5647,5 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
CXXABI::~CXXABI() {}
|
||||
|
|
|
@ -23,6 +23,8 @@ add_clang_library(clangAST
|
|||
ExprCXX.cpp
|
||||
FullExpr.cpp
|
||||
InheritViz.cpp
|
||||
ItaniumCXXABI.cpp
|
||||
MicrosoftCXXABI.cpp
|
||||
NestedNameSpecifier.cpp
|
||||
ParentMap.cpp
|
||||
RecordLayout.cpp
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
//===----- CXXABI.h - Interface to C++ ABIs ---------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This provides an abstract class for C++ AST support. Concrete
|
||||
// subclasses of this implement AST support for specific C++ ABIs.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_AST_CXXABI_H
|
||||
#define LLVM_CLANG_AST_CXXABI_H
|
||||
|
||||
namespace clang {
|
||||
|
||||
class ASTContext;
|
||||
class MemberPointerType;
|
||||
|
||||
/// Implements C++ ABI-specific semantic analysis functions.
|
||||
class CXXABI {
|
||||
public:
|
||||
virtual ~CXXABI();
|
||||
|
||||
/// Returns the size of a member pointer in multiples of the target
|
||||
/// pointer size.
|
||||
virtual unsigned getMemberPointerSize(const MemberPointerType *MPT) const = 0;
|
||||
};
|
||||
|
||||
/// Creates an instance of a C++ ABI class.
|
||||
CXXABI *CreateItaniumCXXABI(ASTContext &Ctx);
|
||||
CXXABI *CreateMicrosoftCXXABI(ASTContext &Ctx);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,39 @@
|
|||
//===------- 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This provides C++ AST support targetting the Itanium C++ ABI, which is
|
||||
// documented at:
|
||||
// http://www.codesourcery.com/public/cxx-abi/abi.html
|
||||
// http://www.codesourcery.com/public/cxx-abi/abi-eh.html
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CXXABI.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/Type.h"
|
||||
|
||||
using namespace clang;
|
||||
|
||||
namespace {
|
||||
class ItaniumCXXABI : public CXXABI {
|
||||
ASTContext &Context;
|
||||
public:
|
||||
ItaniumCXXABI(ASTContext &Ctx) : Context(Ctx) { }
|
||||
|
||||
unsigned getMemberPointerSize(const MemberPointerType *MPT) const {
|
||||
QualType Pointee = MPT->getPointeeType();
|
||||
if (Pointee->isFunctionType()) return 2;
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
CXXABI *clang::CreateItaniumCXXABI(ASTContext &Ctx) {
|
||||
return new ItaniumCXXABI(Ctx);
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
//===------- MicrosoftCXXABI.cpp - AST support for the Microsoft C++ ABI --===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This provides C++ AST support targetting the Microsoft Visual C++
|
||||
// ABI.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CXXABI.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/Type.h"
|
||||
#include "clang/AST/DeclCXX.h"
|
||||
|
||||
using namespace clang;
|
||||
|
||||
namespace {
|
||||
class MicrosoftCXXABI : public CXXABI {
|
||||
ASTContext &Context;
|
||||
public:
|
||||
MicrosoftCXXABI(ASTContext &Ctx) : Context(Ctx) { }
|
||||
|
||||
unsigned getMemberPointerSize(const MemberPointerType *MPT) const;
|
||||
};
|
||||
}
|
||||
|
||||
unsigned MicrosoftCXXABI::getMemberPointerSize(const MemberPointerType *MPT) const {
|
||||
QualType Pointee = MPT->getPointeeType();
|
||||
CXXRecordDecl *RD = MPT->getClass()->getAsCXXRecordDecl();
|
||||
if (RD->getNumVBases() > 0) {
|
||||
if (Pointee->isFunctionType())
|
||||
return 3;
|
||||
else
|
||||
return 2;
|
||||
} else if (RD->getNumBases() > 1 && Pointee->isFunctionType())
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
CXXABI *clang::CreateMicrosoftCXXABI(ASTContext &Ctx) {
|
||||
return new MicrosoftCXXABI(Ctx);
|
||||
}
|
||||
|
|
@ -356,4 +356,4 @@ CodeGenFunction::BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
|
|||
return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
|
||||
}
|
||||
|
||||
CXXABI::~CXXABI() {}
|
||||
CGCXXABI::~CGCXXABI() {}
|
||||
|
|
|
@ -21,17 +21,17 @@ namespace CodeGen {
|
|||
class MangleContext;
|
||||
|
||||
/// Implements C++ ABI-specific code generation functions.
|
||||
class CXXABI {
|
||||
class CGCXXABI {
|
||||
public:
|
||||
virtual ~CXXABI();
|
||||
virtual ~CGCXXABI();
|
||||
|
||||
/// Gets the mangle context.
|
||||
virtual MangleContext &getMangleContext() = 0;
|
||||
};
|
||||
|
||||
/// Creates an instance of a C++ ABI class.
|
||||
CXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
|
||||
CXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
|
||||
CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
|
||||
CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ class CodeGenModule : public BlockModule {
|
|||
friend class CodeGenVTables;
|
||||
|
||||
CGObjCRuntime* Runtime;
|
||||
CXXABI* ABI;
|
||||
CGCXXABI* ABI;
|
||||
CGDebugInfo* DebugInfo;
|
||||
|
||||
// WeakRefReferences - A set of references that have only been seen via
|
||||
|
@ -230,7 +230,7 @@ public:
|
|||
|
||||
/// getCXXABI() - Return a reference to the configured
|
||||
/// C++ ABI.
|
||||
CXXABI &getCXXABI() {
|
||||
CGCXXABI &getCXXABI() {
|
||||
if (!ABI) createCXXABI();
|
||||
return *ABI;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
using namespace clang;
|
||||
|
||||
namespace {
|
||||
class ItaniumCXXABI : public CodeGen::CXXABI {
|
||||
class ItaniumCXXABI : public CodeGen::CGCXXABI {
|
||||
CodeGen::MangleContext MangleCtx;
|
||||
public:
|
||||
ItaniumCXXABI(CodeGen::CodeGenModule &CGM) :
|
||||
|
@ -33,7 +33,7 @@ public:
|
|||
};
|
||||
}
|
||||
|
||||
CodeGen::CXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) {
|
||||
CodeGen::CGCXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) {
|
||||
return new ItaniumCXXABI(CGM);
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ public:
|
|||
llvm::SmallVectorImpl<char> &);
|
||||
};
|
||||
|
||||
class MicrosoftCXXABI : public CXXABI {
|
||||
class MicrosoftCXXABI : public CGCXXABI {
|
||||
MicrosoftMangleContext MangleCtx;
|
||||
public:
|
||||
MicrosoftCXXABI(CodeGenModule &CGM)
|
||||
|
@ -1185,7 +1185,7 @@ void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
|
|||
assert(false && "Can't yet mangle destructors!");
|
||||
}
|
||||
|
||||
CXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
|
||||
CGCXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
|
||||
return new MicrosoftCXXABI(CGM);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue