]> granicus.if.org Git - clang/commitdiff
Add CGDeclCXX.cpp and move EmitCXXGlobalVarDeclInit there.
authorAnders Carlsson <andersca@mac.com>
Thu, 10 Dec 2009 00:16:00 +0000 (00:16 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 10 Dec 2009 00:16:00 +0000 (00:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91006 91177308-0d34-0410-b5e6-96231b3b80d8

clang.xcodeproj/project.pbxproj
lib/CodeGen/CGCXX.cpp
lib/CodeGen/CGDeclCXX.cpp [new file with mode: 0644]
lib/CodeGen/CMakeLists.txt

index 01ff4d8e2aa95bd1186dd977b55c067a0ebe7cc2..5587aedde6c17580d3465faa691d967e77b5dd30 100644 (file)
@@ -44,6 +44,7 @@
                1A81AA19108144F40094E50B /* CGVtable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A81AA18108144F40094E50B /* CGVtable.cpp */; };
                1A869A700BA2164C008DA07A /* LiteralSupport.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1A869A6E0BA2164C008DA07A /* LiteralSupport.h */; };
                1A869AA80BA21ABA008DA07A /* LiteralSupport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */; };
+               1A986AB710D0746D00A8EA9E /* CGDeclCXX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A986AB610D0746D00A8EA9E /* CGDeclCXX.cpp */; };
                1AA1D91810125DE30078DEBC /* RecordLayoutBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AA1D91610125DE30078DEBC /* RecordLayoutBuilder.cpp */; };
                1ABC36940C7A4BDC006DB0AB /* CGBuiltin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ABC36930C7A4BDC006DB0AB /* CGBuiltin.cpp */; };
                1ADD795410A90C6100741BBA /* TypePrinter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ADD795110A90C6100741BBA /* TypePrinter.cpp */; };
                1A81AA5D108278A20094E50B /* CGVtable.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = CGVtable.h; path = lib/CodeGen/CGVtable.h; sourceTree = "<group>"; tabWidth = 2; };
                1A869A6E0BA2164C008DA07A /* LiteralSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LiteralSupport.h; sourceTree = "<group>"; };
                1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = LiteralSupport.cpp; sourceTree = "<group>"; };
+               1A986AB610D0746D00A8EA9E /* CGDeclCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CGDeclCXX.cpp; path = lib/CodeGen/CGDeclCXX.cpp; sourceTree = "<group>"; };
                1AA1D91610125DE30078DEBC /* RecordLayoutBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = RecordLayoutBuilder.cpp; path = lib/AST/RecordLayoutBuilder.cpp; sourceTree = "<group>"; tabWidth = 2; };
                1AA1D91710125DE30078DEBC /* RecordLayoutBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = RecordLayoutBuilder.h; path = lib/AST/RecordLayoutBuilder.h; sourceTree = "<group>"; tabWidth = 2; };
                1AB290021045858B00FE33D8 /* PartialDiagnostic.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; path = PartialDiagnostic.h; sourceTree = "<group>"; tabWidth = 2; };
                                1A4C41BE105B4C0B0047B5E7 /* CGClass.cpp */,
                                1A5D5E570E5E81010023C059 /* CGCXX.cpp */,
                                1A649E1E0F9599DA005B965E /* CGCXX.h */,
-                               1A6B6E991069833600BB4A8F /* CGExprCXX.cpp */,
                                35A3E7000DD3874400757F74 /* CGDebugInfo.cpp */,
                                35A3E7010DD3874400757F74 /* CGDebugInfo.h */,
                                DE4264FB0C113592005A861D /* CGDecl.cpp */,
+                               1A986AB610D0746D00A8EA9E /* CGDeclCXX.cpp */,
                                1AF1B50E109A4FB800AFAFAC /* CGException.cpp */,
                                DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */,
                                DEF2EFF20C6CDD74000C4259 /* CGExprAgg.cpp */,
+                               1A6B6E991069833600BB4A8F /* CGExprCXX.cpp */,
                                DE224FF70C7AA98800D370A5 /* CGExprComplex.cpp */,
                                1A376A2C0D4AED9B002A1C52 /* CGExprConstant.cpp */,
                                DE22526F0C7E82D000D370A5 /* CGExprScalar.cpp */,
                                1ADD795410A90C6100741BBA /* TypePrinter.cpp in Sources */,
                                1ADD795510A90C6100741BBA /* TypeLoc.cpp in Sources */,
                                1ADD795610A90C6100741BBA /* TemplateBase.cpp in Sources */,
+                               1A986AB710D0746D00A8EA9E /* CGDeclCXX.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 7bffad49a7f3875c9126e3c75abaf377b97a17bd..d3ea2c78841d1a79b86cea919727e467a2fc4ce5 100644 (file)
@@ -61,51 +61,6 @@ CodeGenFunction::EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
   Builder.CreateCall(AtExitFn, &Args[0], llvm::array_endof(Args));
 }
 
-void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
-                                               llvm::Constant *DeclPtr) {
-  assert(D.hasGlobalStorage() &&
-         "VarDecl must have global storage!");
-
-  const Expr *Init = D.getInit();
-  QualType T = D.getType();
-  bool isVolatile = getContext().getCanonicalType(T).isVolatileQualified();
-
-  if (T->isReferenceType()) {
-    ErrorUnsupported(Init, "global variable that binds to a reference");
-  } else if (!hasAggregateLLVMType(T)) {
-    llvm::Value *V = EmitScalarExpr(Init);
-    EmitStoreOfScalar(V, DeclPtr, isVolatile, T);
-  } else if (T->isAnyComplexType()) {
-    EmitComplexExprIntoAddr(Init, DeclPtr, isVolatile);
-  } else {
-    EmitAggExpr(Init, DeclPtr, isVolatile);
-    // Avoid generating destructor(s) for initialized objects. 
-    if (!isa<CXXConstructExpr>(Init))
-      return;
-    const ConstantArrayType *Array = getContext().getAsConstantArrayType(T);
-    if (Array)
-      T = getContext().getBaseElementType(Array);
-    
-    if (const RecordType *RT = T->getAs<RecordType>()) {
-      CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
-      if (!RD->hasTrivialDestructor()) {
-        llvm::Constant *DtorFn;
-        if (Array) {
-          DtorFn = CodeGenFunction(CGM).GenerateCXXAggrDestructorHelper(
-                                                RD->getDestructor(getContext()), 
-                                                Array, DeclPtr);
-          DeclPtr = 
-            llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(VMContext));
-        }
-        else
-          DtorFn = CGM.GetAddrOfCXXDestructor(RD->getDestructor(getContext()), 
-                                              Dtor_Complete);                                
-        EmitCXXGlobalDtorRegistration(DtorFn, DeclPtr);
-      }
-    }
-  }
-}
-
 void
 CodeGenModule::EmitCXXGlobalInitFunc() {
   if (CXXGlobalInits.empty())
diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp
new file mode 100644 (file)
index 0000000..b048cf8
--- /dev/null
@@ -0,0 +1,62 @@
+//===--- CGDeclCXX.cpp - Emit LLVM Code for C++ declarations --------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains code dealing with code generation of C++ declarations
+//
+//===----------------------------------------------------------------------===//
+
+#include "CodeGenFunction.h"
+using namespace clang;
+using namespace CodeGen;
+
+void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
+                                               llvm::Constant *DeclPtr) {
+  assert(D.hasGlobalStorage() &&
+         "VarDecl must have global storage!");
+
+  const Expr *Init = D.getInit();
+  QualType T = D.getType();
+  bool isVolatile = getContext().getCanonicalType(T).isVolatileQualified();
+
+  if (T->isReferenceType()) {
+    ErrorUnsupported(Init, "global variable that binds to a reference");
+  } else if (!hasAggregateLLVMType(T)) {
+    llvm::Value *V = EmitScalarExpr(Init);
+    EmitStoreOfScalar(V, DeclPtr, isVolatile, T);
+  } else if (T->isAnyComplexType()) {
+    EmitComplexExprIntoAddr(Init, DeclPtr, isVolatile);
+  } else {
+    EmitAggExpr(Init, DeclPtr, isVolatile);
+    // Avoid generating destructor(s) for initialized objects. 
+    if (!isa<CXXConstructExpr>(Init))
+      return;
+    const ConstantArrayType *Array = getContext().getAsConstantArrayType(T);
+    if (Array)
+      T = getContext().getBaseElementType(Array);
+    
+    if (const RecordType *RT = T->getAs<RecordType>()) {
+      CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
+      if (!RD->hasTrivialDestructor()) {
+        llvm::Constant *DtorFn;
+        if (Array) {
+          DtorFn = CodeGenFunction(CGM).GenerateCXXAggrDestructorHelper(
+                                                RD->getDestructor(getContext()), 
+                                                Array, DeclPtr);
+          DeclPtr = 
+            llvm::Constant::getNullValue(llvm::Type::getInt8PtrTy(VMContext));
+        }
+        else
+          DtorFn = CGM.GetAddrOfCXXDestructor(RD->getDestructor(getContext()), 
+                                              Dtor_Complete);                                
+        EmitCXXGlobalDtorRegistration(DtorFn, DeclPtr);
+      }
+    }
+  }
+}
+
index a1fb5ad7459cc4582ae1b6e42898ae9a1250a5e5..3c264847402edb1be8e1f56e3d5a9952dd5c5583 100644 (file)
@@ -8,6 +8,7 @@ add_clang_library(clangCodeGen
   CGCXX.cpp
   CGDebugInfo.cpp
   CGDecl.cpp
+  CGDeclCXX.cpp
   CGException.cpp
   CGExpr.cpp
   CGExprAgg.cpp