summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorCharles Davis <cdavis@mines.edu>2010-08-16 03:33:14 +0000
committerCharles Davis <cdavis@mines.edu>2010-08-16 03:33:14 +0000
commit53c59df2f7d2395c6b44a1b7ff5ec6be6792e150 (patch)
tree8bff2acce252777eb676dba37f3181040ab41eab /clang/lib
parentdf28e8ec4145fbe407f09dc2458d42cd9f12bd99 (diff)
downloadbcm5719-llvm-53c59df2f7d2395c6b44a1b7ff5ec6be6792e150.tar.gz
bcm5719-llvm-53c59df2f7d2395c6b44a1b7ff5ec6be6792e150.zip
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
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/ASTContext.cpp19
-rw-r--r--clang/lib/AST/CMakeLists.txt2
-rw-r--r--clang/lib/AST/CXXABI.h38
-rw-r--r--clang/lib/AST/ItaniumCXXABI.cpp39
-rw-r--r--clang/lib/AST/MicrosoftCXXABI.cpp48
-rw-r--r--clang/lib/CodeGen/CGCXX.cpp2
-rw-r--r--clang/lib/CodeGen/CGCXXABI.h8
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h4
-rw-r--r--clang/lib/CodeGen/ItaniumCXXABI.cpp4
-rw-r--r--clang/lib/CodeGen/MicrosoftCXXABI.cpp4
10 files changed, 152 insertions, 16 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index adb75f0f61e..1e437fdabeb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -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() {}
diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index 407ed95f3ee..b340c0464cc 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -23,6 +23,8 @@ add_clang_library(clangAST
ExprCXX.cpp
FullExpr.cpp
InheritViz.cpp
+ ItaniumCXXABI.cpp
+ MicrosoftCXXABI.cpp
NestedNameSpecifier.cpp
ParentMap.cpp
RecordLayout.cpp
diff --git a/clang/lib/AST/CXXABI.h b/clang/lib/AST/CXXABI.h
new file mode 100644
index 00000000000..8781bd7c75f
--- /dev/null
+++ b/clang/lib/AST/CXXABI.h
@@ -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
diff --git a/clang/lib/AST/ItaniumCXXABI.cpp b/clang/lib/AST/ItaniumCXXABI.cpp
new file mode 100644
index 00000000000..0ac80ecd638
--- /dev/null
+++ b/clang/lib/AST/ItaniumCXXABI.cpp
@@ -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);
+}
+
diff --git a/clang/lib/AST/MicrosoftCXXABI.cpp b/clang/lib/AST/MicrosoftCXXABI.cpp
new file mode 100644
index 00000000000..87b77673925
--- /dev/null
+++ b/clang/lib/AST/MicrosoftCXXABI.cpp
@@ -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);
+}
+
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp
index 7b7be9a260e..edfbe0e72ee 100644
--- a/clang/lib/CodeGen/CGCXX.cpp
+++ b/clang/lib/CodeGen/CGCXX.cpp
@@ -356,4 +356,4 @@ CodeGenFunction::BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
}
-CXXABI::~CXXABI() {}
+CGCXXABI::~CGCXXABI() {}
diff --git a/clang/lib/CodeGen/CGCXXABI.h b/clang/lib/CodeGen/CGCXXABI.h
index e1bbb0a79cc..0cebcb1c31b 100644
--- a/clang/lib/CodeGen/CGCXXABI.h
+++ b/clang/lib/CodeGen/CGCXXABI.h
@@ -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);
}
}
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index c7578788a57..eca449c702e 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -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;
}
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 98db75ea2b4..a6137692fbd 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -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);
}
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index da0fdb616d6..cfc635a7a4c 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -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);
}
OpenPOWER on IntegriCloud