]> granicus.if.org Git - clang/commitdiff
IRgen: Add a stub class for generating ABI-specific C++ code.
authorCharles Davis <cdavis@mines.edu>
Tue, 25 May 2010 19:52:27 +0000 (19:52 +0000)
committerCharles Davis <cdavis@mines.edu>
Tue, 25 May 2010 19:52:27 +0000 (19:52 +0000)
This class only supports name mangling (which is apparently used during C/ObjC
codegen). For now only the Itanium C++ ABI is supported. Patches to add a
second C++ ABI are forthcoming.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104630 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
lib/CodeGen/CGCXXABI.h [new file with mode: 0644]
lib/CodeGen/CMakeLists.txt
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenModule.h
lib/CodeGen/ItaniumCXXABI.cpp [new file with mode: 0644]

index be4256a691d28a7faaeef0f3a380707d22b6a749..525877903e7a1229150fe22ec030a972ccc7cb4f 100644 (file)
@@ -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"
@@ -333,3 +334,5 @@ CodeGenFunction::BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
 
   return ::BuildVirtualCall(*this, VTableIndex, This, Ty);
 }
+
+CXXABI::~CXXABI() {}
diff --git a/lib/CodeGen/CGCXXABI.h b/lib/CodeGen/CGCXXABI.h
new file mode 100644 (file)
index 0000000..a7e1871
--- /dev/null
@@ -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 CXXABI {
+public:
+  virtual ~CXXABI();
+
+  /// Gets the mangle context.
+  virtual MangleContext &getMangleContext() = 0;
+};
+
+/// Creates an instance of a C++ ABI class.
+CXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
+}
+}
+
+#endif
index 8309aa994d6d3ef2c81b296b8758cbfeac620169..a226400a3787f1ba81aa8e81a23545c9890fc0a7 100644 (file)
@@ -28,9 +28,10 @@ add_clang_library(clangCodeGen
   CodeGenFunction.cpp
   CodeGenModule.cpp
   CodeGenTypes.cpp
+  ItaniumCXXABI.cpp
   Mangle.cpp
   ModuleBuilder.cpp
   TargetInfo.cpp
   )
 
-add_dependencies(clangCodeGen ClangStmtNodes)
\ No newline at end of file
+add_dependencies(clangCodeGen ClangStmtNodes)
index 2f8404e251e99c7ba45442deb1f259adac850e84..1b89d6224208991fb1ddc8eac2a05fc385090779 100644 (file)
@@ -48,7 +48,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
     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), ABI(0),
     CFConstantStringClassRef(0),
     NSConstantStringClassRef(0),
     VMContext(M.getContext()) {
@@ -62,12 +62,17 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
   else
     Runtime = CreateMacObjCRuntime(*this);
 
+  if (!Features.CPlusPlus)
+    ABI = 0;
+  else createCXXABI();
+
   // If debug info generation is enabled, create the CGDebugInfo object.
   DebugInfo = CodeGenOpts.DebugInfo ? new CGDebugInfo(*this) : 0;
 }
 
 CodeGenModule::~CodeGenModule() {
   delete Runtime;
+  delete ABI;
   delete DebugInfo;
 }
 
@@ -80,6 +85,11 @@ void CodeGenModule::createObjCRuntime() {
     Runtime = CreateMacObjCRuntime(*this);
 }
 
+void CodeGenModule::createCXXABI() {
+  // For now, just create an Itanium ABI.
+  ABI = CreateItaniumCXXABI(*this);
+}
+
 void CodeGenModule::Release() {
   EmitDeferred();
   EmitCXXGlobalInitFunc();
index b14c35f3845410c0e4ef0135e85d1eab835457ff..319744c4be3dbed7107eed34bf80c0965381403a 100644 (file)
@@ -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 @@ class CodeGenModule : public BlockModule {
   mutable const TargetCodeGenInfo *TheTargetCodeGenInfo;
   Diagnostic &Diags;
   CodeGenTypes Types;
-  MangleContext MangleCtx;
 
   /// VTables - Holds information about C++ vtables.
   CodeGenVTables VTables;
   friend class CodeGenVTables;
 
   CGObjCRuntime* Runtime;
+  CXXABI* ABI;
   CGDebugInfo* DebugInfo;
 
   // WeakRefReferences - A set of references that have only been seen via
@@ -153,6 +154,8 @@ class CodeGenModule : public BlockModule {
 
   /// Lazily create the Objective-C runtime
   void createObjCRuntime();
+  /// Lazily create the C++ ABI
+  void createCXXABI();
 
   llvm::LLVMContext &VMContext;
 public:
@@ -175,6 +178,16 @@ public:
   /// been configured.
   bool hasObjCRuntime() { return !!Runtime; }
 
+  /// getCXXABI() - Return a reference to the configured
+  /// C++ ABI.
+  CXXABI &getCXXABI() {
+    if (!ABI) createCXXABI();
+    return *ABI;
+  }
+
+  /// hasCXXABI() - Return true iff a C++ ABI has been configured.
+  bool hasCXXABI() { return !!ABI; }
+
   llvm::Value *getStaticLocalDeclAddress(const VarDecl *VD) {
     return StaticLocalDeclMap[VD];
   }
@@ -189,7 +202,10 @@ public:
   const LangOptions &getLangOptions() const { return Features; }
   llvm::Module &getModule() const { return TheModule; }
   CodeGenTypes &getTypes() { return Types; }
-  MangleContext &getMangleContext() { return MangleCtx; }
+  MangleContext &getMangleContext() {
+    if (!ABI) createCXXABI();
+    return ABI->getMangleContext();
+  }
   CodeGenVTables &getVTables() { return VTables; }
   Diagnostic &getDiags() const { return Diags; }
   const llvm::TargetData &getTargetData() const { return TheTargetData; }
diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp
new file mode 100644 (file)
index 0000000..98db75e
--- /dev/null
@@ -0,0 +1,39 @@
+//===------- ItaniumCXXABI.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 Itanium C++ ABI.  The class
+// in this file generates structures that follow 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 "CGCXXABI.h"
+#include "CodeGenModule.h"
+#include "Mangle.h"
+
+using namespace clang;
+
+namespace {
+class ItaniumCXXABI : public CodeGen::CXXABI {
+  CodeGen::MangleContext MangleCtx;
+public:
+  ItaniumCXXABI(CodeGen::CodeGenModule &CGM) :
+    MangleCtx(CGM.getContext(), CGM.getDiags()) { }
+
+  CodeGen::MangleContext &getMangleContext() {
+    return MangleCtx;
+  }
+};
+}
+
+CodeGen::CXXABI *CodeGen::CreateItaniumCXXABI(CodeGenModule &CGM) {
+  return new ItaniumCXXABI(CGM);
+}
+