diff options
author | Anders Carlsson <andersca@mac.com> | 2009-08-08 23:24:23 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-08-08 23:24:23 +0000 |
commit | b8be93fc92c684a331a1ad40b30c77de3c18a67a (patch) | |
tree | f27bb74a30944cd5ce4ab45f693f6cf96e84e7e3 /clang/lib/CodeGen/CGCXX.cpp | |
parent | cfed3005e5c9d8ff26ee53ef4f9e459a2106c11d (diff) | |
download | bcm5719-llvm-b8be93fc92c684a331a1ad40b30c77de3c18a67a.tar.gz bcm5719-llvm-b8be93fc92c684a331a1ad40b30c77de3c18a67a.zip |
Add support for global initializers.
llvm-svn: 78515
Diffstat (limited to 'clang/lib/CodeGen/CGCXX.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGCXX.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index bed6785ef18..bcae8298e6f 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -91,6 +91,41 @@ void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D, } } +void +CodeGenModule::EmitCXXGlobalInitFunc() { + if (CXXGlobalInits.empty()) + return; + + const llvm::FunctionType *FTy = llvm::FunctionType::get(llvm::Type::VoidTy, + false); + + // Create our global initialization function. + // FIXME: Should this be tweakable by targets? + llvm::Function *Fn = + llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage, + "__cxx_global_initialization", &TheModule); + + CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, + CXXGlobalInits.data(), + CXXGlobalInits.size()); + AddGlobalCtor(Fn); +} + +void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn, + const VarDecl **Decls, + unsigned NumDecls) { + StartFunction(0, getContext().VoidTy, Fn, FunctionArgList(), + SourceLocation()); + + for (unsigned i = 0; i != NumDecls; ++i) { + const VarDecl *D = Decls[i]; + + llvm::Constant *DeclPtr = CGM.GetAddrOfGlobalVar(D); + EmitCXXGlobalVarDeclInit(*D, DeclPtr); + } + FinishFunction(); +} + void CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV) { |