(NOTE: Since John's my GSoC mentor, I've CC'd him.)

This is the first patch in my GSoC series, in which I will factor out
C++ ABI support in IRgen so that we can support other C++ ABIs. This
patch is very simple. It just adds a class hierarchy similar to the one
for Objective-C runtimes, and a basic implementation for the current GNU
C++ ABI. All it supports is name mangling. CodeGenFunction has been
redirected to use this new interface instead of holding the
MangleContext itself (which is very specific to the GNU ABI right now).

Forthcoming is a patch to add a stub mangler for the ever-popular
Microsoft Visual C++ ABI, and a driver switch to turn on MSVC ABI
support. (Daniel, I'll need your input for the driver part.)

Chip
Index: lib/CodeGen/CGCXXABIGNU.cpp
===================================================================
--- lib/CodeGen/CGCXXABIGNU.cpp (revision 0)
+++ lib/CodeGen/CGCXXABIGNU.cpp (revision 0)
@@ -0,0 +1,39 @@
+//===------- CGCXXABIGNU.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 GNU C++ ABI.  The class
+// in this file generates structures that follow the GNU C++ ABI, which is
+// based on the Itanium C++ ABI and is documented at:
+//  http://www.codesourcery.com/public/cxx-abi/abi.html
+//  http://www.codesourcery.com/public/cxx-abi/abi-eh.html
+//===----------------------------------------------------------------------===//
+
+#include "CGCXXABI.h"
+#include "CodeGenModule.h"
+#include "Mangle.h"
+
+using namespace clang;
+
+namespace {
+class CGCXXABIGNU : public CodeGen::CGCXXABI {
+  CodeGen::MangleContext MangleCtx;
+public:
+  CGCXXABIGNU(CodeGen::CodeGenModule &CGM) :
+    MangleCtx(CGM.getContext(), CGM.getDiags()) { }
+
+  CodeGen::MangleContext &getMangleContext() {
+    return MangleCtx;
+  }
+};
+}
+
+CodeGen::CGCXXABI *CodeGen::CreateGNUCXXABI(CodeGenModule &CGM) {
+  return new CGCXXABIGNU(CGM);
+}
+
Index: lib/CodeGen/CGCXX.cpp
===================================================================
--- lib/CodeGen/CGCXX.cpp       (revision 104584)
+++ lib/CodeGen/CGCXX.cpp       (working copy)
@@ -13,6 +13,7 @@
 
 // We might split this into multiple files if it gets too unwieldy
 
+#include "CGCXXABI.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "Mangle.h"
@@ -329,3 +330,5 @@
 
   return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
 }
+
+CGCXXABI::~CGCXXABI() {}
Index: lib/CodeGen/CodeGenModule.h
===================================================================
--- lib/CodeGen/CodeGenModule.h (revision 104584)
+++ lib/CodeGen/CodeGenModule.h (working copy)
@@ -22,6 +22,7 @@
 #include "CGCall.h"
 #include "CGCXX.h"
 #include "CGVTables.h"
+#include "CGCXXABI.h"
 #include "CodeGenTypes.h"
 #include "GlobalDecl.h"
 #include "Mangle.h"
@@ -90,13 +91,13 @@
   mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
   Diagnostic &Diags;
   CodeGenTypes Types;
-  MangleContext MangleCtx;
 
   /// VTables - Holds information about C++ vtables.
   CodeGenVTables VTables;
   friend class CodeGenVTables;
 
   CGObjCRuntime* Runtime;
+  CGCXXABI* CXXABI;
   CGDebugInfo* DebugInfo;
 
   // WeakRefReferences - A set of references that have only been seen via
@@ -153,6 +154,8 @@
 
   /// Lazily create the Objective-C runtime
   void createObjCRuntime();
+  /// Lazily create the C++ ABI
+  void createCXXABI();
 
   llvm::LLVMContext &VMContext;
 public:
@@ -175,6 +178,16 @@
   /// been configured.
   bool hasObjCRuntime() { return !!Runtime; }
 
+  /// getCXXABI() - Return a reference to the configured
+  /// C++ ABI.
+  CGCXXABI &getCXXABI() {
+    if (!CXXABI) createCXXABI();
+    return *CXXABI;
+  }
+
+  /// hasCXXABI() - Return true iff a C++ ABI has been configured.
+  bool hasCXXABI() { return !!CXXABI; }
+
   llvm::Value *getStaticLocalDeclAddress(const VarDecl *VD) {
     return StaticLocalDeclMap[VD];
   }
@@ -189,7 +202,10 @@
   const LangOptions &getLangOptions() const { return Features; }
   llvm::Module &getModule() const { return TheModule; }
   CodeGenTypes &getTypes() { return Types; }
-  MangleContext &getMangleContext() { return MangleCtx; }
+  MangleContext &getMangleContext() {
+    if (!CXXABI) createCXXABI();
+    return CXXABI->getMangleContext();
+  }
   CodeGenVTables &getVTables() { return VTables; }
   Diagnostic &getDiags() const { return Diags; }
   const llvm::TargetData &getTargetData() const { return TheTargetData; }
Index: lib/CodeGen/CMakeLists.txt
===================================================================
--- lib/CodeGen/CMakeLists.txt  (revision 104584)
+++ lib/CodeGen/CMakeLists.txt  (working copy)
@@ -6,6 +6,7 @@
   CGCall.cpp
   CGClass.cpp
   CGCXX.cpp
+  CGCXXABIGNU.cpp
   CGDebugInfo.cpp
   CGDecl.cpp
   CGDeclCXX.cpp
@@ -33,4 +34,4 @@
   TargetInfo.cpp
   )
 
-add_dependencies(clangCodeGen ClangStmtNodes)
\ No newline at end of file
+add_dependencies(clangCodeGen ClangStmtNodes)
Index: lib/CodeGen/CGCXXABI.h
===================================================================
--- lib/CodeGen/CGCXXABI.h      (revision 0)
+++ lib/CodeGen/CGCXXABI.h      (revision 0)
@@ -0,0 +1,37 @@
+//===----- CGCXXABI.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++ code generation. Concrete subclasses
+// of this implement code generation for specific C++ ABIs.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_CODEGEN_CXXABI_H
+#define CLANG_CODEGEN_CXXABI_H
+
+namespace clang {
+namespace CodeGen {
+  class CodeGenModule;
+  class MangleContext;
+
+/// Implements C++ ABI-specific code generation functions.
+class CGCXXABI {
+public:
+  virtual ~CGCXXABI();
+
+  /// Gets the mangle context.
+  virtual MangleContext &getMangleContext() = 0;
+};
+
+/// Creates an instance of a C++ ABI class.
+CGCXXABI *CreateGNUCXXABI(CodeGenModule &CGM);
+}
+}
+
+#endif
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp       (revision 104584)
+++ lib/CodeGen/CodeGenModule.cpp       (working copy)
@@ -48,7 +48,7 @@
     Features(C.getLangOptions()), CodeGenOpts(CGO), TheModule(M),
     TheTargetData(TD), TheTargetCodeGenInfo(0), Diags(diags),
     Types(C, M, TD, getTargetCodeGenInfo().getABIInfo()),
-    MangleCtx(C, diags), VTables(*this), Runtime(0),
+    VTables(*this), Runtime(0), CXXABI(0),
     CFConstantStringClassRef(0),
     NSConstantStringClassRef(0),
     VMContext(M.getContext()) {
@@ -68,6 +68,7 @@
 
 CodeGenModule::~CodeGenModule() {
   delete Runtime;
+  delete CXXABI;
   delete DebugInfo;
 }
 
@@ -80,6 +81,11 @@
     Runtime = CreateMacObjCRuntime(*this);
 }
 
+void CodeGenModule::createCXXABI() {
+  // For now, just create a GNU ABI.
+  CXXABI = CreateGNUCXXABI(*this);
+}
+
 void CodeGenModule::Release() {
   EmitDeferred();
   EmitCXXGlobalInitFunc();
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to