From c3926645d70842eae22641df1bf69da457a0ff11 Mon Sep 17 00:00:00 2001 From: Charles Davis Date: Wed, 9 Jun 2010 23:25:41 +0000 Subject: [PATCH] Add a stub Microsoft Visual C++ ABI class (with stub mangler). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105767 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCXXABI.h | 1 + lib/CodeGen/CMakeLists.txt | 1 + lib/CodeGen/Mangle.h | 44 +++++------ lib/CodeGen/MicrosoftCXXABI.cpp | 130 ++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+), 21 deletions(-) create mode 100644 lib/CodeGen/MicrosoftCXXABI.cpp diff --git a/lib/CodeGen/CGCXXABI.h b/lib/CodeGen/CGCXXABI.h index a7e18714e8..e1bbb0a79c 100644 --- a/lib/CodeGen/CGCXXABI.h +++ b/lib/CodeGen/CGCXXABI.h @@ -31,6 +31,7 @@ public: /// Creates an instance of a C++ ABI class. CXXABI *CreateItaniumCXXABI(CodeGenModule &CGM); +CXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM); } } diff --git a/lib/CodeGen/CMakeLists.txt b/lib/CodeGen/CMakeLists.txt index ef98312586..bb2160e2c4 100644 --- a/lib/CodeGen/CMakeLists.txt +++ b/lib/CodeGen/CMakeLists.txt @@ -30,6 +30,7 @@ add_clang_library(clangCodeGen CodeGenTypes.cpp ItaniumCXXABI.cpp Mangle.cpp + MicrosoftCXXABI.cpp ModuleBuilder.cpp TargetInfo.cpp ) diff --git a/lib/CodeGen/Mangle.h b/lib/CodeGen/Mangle.h index 956217ebd4..a12a140f72 100644 --- a/lib/CodeGen/Mangle.h +++ b/lib/CodeGen/Mangle.h @@ -84,6 +84,8 @@ public: Diagnostic &Diags) : Context(Context), Diags(Diags) { } + virtual ~MangleContext() { } + ASTContext &getASTContext() const { return Context; } Diagnostic &getDiags() const { return Diags; } @@ -109,28 +111,28 @@ public: /// @{ bool shouldMangleDeclName(const NamedDecl *D); - void mangleName(const NamedDecl *D, llvm::SmallVectorImpl &); - void mangleThunk(const CXXMethodDecl *MD, - const ThunkInfo &Thunk, - llvm::SmallVectorImpl &); - void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, - const ThisAdjustment &ThisAdjustment, + virtual void mangleName(const NamedDecl *D, llvm::SmallVectorImpl &); + virtual void mangleThunk(const CXXMethodDecl *MD, + const ThunkInfo &Thunk, llvm::SmallVectorImpl &); - void mangleGuardVariable(const VarDecl *D, - llvm::SmallVectorImpl &); - void mangleCXXVTable(const CXXRecordDecl *RD, - llvm::SmallVectorImpl &); - void mangleCXXVTT(const CXXRecordDecl *RD, - llvm::SmallVectorImpl &); - void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset, - const CXXRecordDecl *Type, - llvm::SmallVectorImpl &); - void mangleCXXRTTI(QualType T, llvm::SmallVectorImpl &); - void mangleCXXRTTIName(QualType T, llvm::SmallVectorImpl &); - void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, - llvm::SmallVectorImpl &); - void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, - llvm::SmallVectorImpl &); + virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, + const ThisAdjustment &ThisAdjustment, + llvm::SmallVectorImpl &); + virtual void mangleGuardVariable(const VarDecl *D, + llvm::SmallVectorImpl &); + virtual void mangleCXXVTable(const CXXRecordDecl *RD, + llvm::SmallVectorImpl &); + virtual void mangleCXXVTT(const CXXRecordDecl *RD, + llvm::SmallVectorImpl &); + virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset, + const CXXRecordDecl *Type, + llvm::SmallVectorImpl &); + virtual void mangleCXXRTTI(QualType T, llvm::SmallVectorImpl &); + virtual void mangleCXXRTTIName(QualType T, llvm::SmallVectorImpl &); + virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, + llvm::SmallVectorImpl &); + virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, + llvm::SmallVectorImpl &); void mangleBlock(const BlockDecl *BD, llvm::SmallVectorImpl &); void mangleInitDiscriminator() { diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp new file mode 100644 index 0000000000..cf809991de --- /dev/null +++ b/lib/CodeGen/MicrosoftCXXABI.cpp @@ -0,0 +1,130 @@ +//===--- MicrosoftCXXABI.cpp - Emit LLVM Code from ASTs for a Module ------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This provides C++ code generation targetting the Microsoft Visual C++ ABI. +// The class in this file generates structures that follow the Microsoft +// Visual C++ ABI, which is actually not very well documented at all outside +// of Microsoft. +// +//===----------------------------------------------------------------------===// + +#include "CGCXXABI.h" +#include "CodeGenModule.h" +#include "Mangle.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclTemplate.h" +#include "clang/AST/ExprCXX.h" +#include "CGVTables.h" + +using namespace clang; +using namespace CodeGen; + +namespace { + +/// MicrosoftMangleContext - Overrides the default MangleContext for the +/// Microsoft Visual C++ ABI. +class MicrosoftMangleContext : public MangleContext { +public: + MicrosoftMangleContext(ASTContext &Context, + Diagnostic &Diags) : MangleContext(Context, Diags) { } + virtual void mangleName(const NamedDecl *D, llvm::SmallVectorImpl &); + virtual void mangleThunk(const CXXMethodDecl *MD, + const ThunkInfo &Thunk, + llvm::SmallVectorImpl &); + virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, + const ThisAdjustment &ThisAdjustment, + llvm::SmallVectorImpl &); + virtual void mangleGuardVariable(const VarDecl *D, + llvm::SmallVectorImpl &); + virtual void mangleCXXVTable(const CXXRecordDecl *RD, + llvm::SmallVectorImpl &); + virtual void mangleCXXVTT(const CXXRecordDecl *RD, + llvm::SmallVectorImpl &); + virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset, + const CXXRecordDecl *Type, + llvm::SmallVectorImpl &); + virtual void mangleCXXRTTI(QualType T, llvm::SmallVectorImpl &); + virtual void mangleCXXRTTIName(QualType T, llvm::SmallVectorImpl &); + virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, + llvm::SmallVectorImpl &); + virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, + llvm::SmallVectorImpl &); +}; + +class MicrosoftCXXABI : public CXXABI { + MicrosoftMangleContext MangleCtx; +public: + MicrosoftCXXABI(CodeGenModule &CGM) + : MangleCtx(CGM.getContext(), CGM.getDiags()) {} + + MicrosoftMangleContext &getMangleContext() { + return MangleCtx; + } +}; + +} + +void MicrosoftMangleContext::mangleName(const NamedDecl *D, + llvm::SmallVectorImpl &Name) { + assert(false && "Can't yet mangle names!"); +} +void MicrosoftMangleContext::mangleThunk(const CXXMethodDecl *MD, + const ThunkInfo &Thunk, + llvm::SmallVectorImpl &) { + assert(false && "Can't yet mangle thunks!"); +} +void MicrosoftMangleContext::mangleCXXDtorThunk(const CXXDestructorDecl *DD, + CXXDtorType Type, + const ThisAdjustment &, + llvm::SmallVectorImpl &) { + assert(false && "Can't yet mangle destructor thunks!"); +} +void MicrosoftMangleContext::mangleGuardVariable(const VarDecl *D, + llvm::SmallVectorImpl &) { + assert(false && "Can't yet mangle guard variables!"); +} +void MicrosoftMangleContext::mangleCXXVTable(const CXXRecordDecl *RD, + llvm::SmallVectorImpl &) { + assert(false && "Can't yet mangle virtual tables!"); +} +void MicrosoftMangleContext::mangleCXXVTT(const CXXRecordDecl *RD, + llvm::SmallVectorImpl &) { + llvm_unreachable("The MS C++ ABI does not have virtual table tables!"); +} +void MicrosoftMangleContext::mangleCXXCtorVTable(const CXXRecordDecl *RD, + int64_t Offset, + const CXXRecordDecl *Type, + llvm::SmallVectorImpl &) { + llvm_unreachable("The MS C++ ABI does not have constructor vtables!"); +} +void MicrosoftMangleContext::mangleCXXRTTI(QualType T, + llvm::SmallVectorImpl &) { + assert(false && "Can't yet mangle RTTI!"); +} +void MicrosoftMangleContext::mangleCXXRTTIName(QualType T, + llvm::SmallVectorImpl &) { + assert(false && "Can't yet mangle RTTI names!"); +} +void MicrosoftMangleContext::mangleCXXCtor(const CXXConstructorDecl *D, + CXXCtorType Type, + llvm::SmallVectorImpl &) { + assert(false && "Can't yet mangle constructors!"); +} +void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D, + CXXDtorType Type, + llvm::SmallVectorImpl &) { + assert(false && "Can't yet mangle destructors!"); +} + +CXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM) { + return new MicrosoftCXXABI(CGM); +} + -- 2.40.0