diff options
author | Chris Lattner <sabre@nondot.org> | 2007-07-13 05:13:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-07-13 05:13:43 +0000 |
commit | d14bfa94a6cbe5301edbb2b722336c5fa68a5b8e (patch) | |
tree | d64e72f4cad562f7c728d9c507193428876ae3c4 /clang/CodeGen/CodeGenModule.cpp | |
parent | fc7634f2ab5db74befd6cdaf39cdfcb632fcfc85 (diff) | |
download | bcm5719-llvm-d14bfa94a6cbe5301edbb2b722336c5fa68a5b8e.tar.gz bcm5719-llvm-d14bfa94a6cbe5301edbb2b722336c5fa68a5b8e.zip |
implement support for basic codegen of global variables with no initializers.
llvm-svn: 39795
Diffstat (limited to 'clang/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/CodeGen/CodeGenModule.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/clang/CodeGen/CodeGenModule.cpp b/clang/CodeGen/CodeGenModule.cpp index cdc3e63026d..b610d3eb27e 100644 --- a/clang/CodeGen/CodeGenModule.cpp +++ b/clang/CodeGen/CodeGenModule.cpp @@ -48,12 +48,45 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const Decl *D) { 0, D->getName(), &getModule()); } -void CodeGenModule::EmitFunction(FunctionDecl *FD) { +void CodeGenModule::EmitFunction(const FunctionDecl *FD) { // If this is not a prototype, emit the body. if (FD->getBody()) CodeGenFunction(*this).GenerateCode(FD); } +void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) { + llvm::GlobalVariable *GV = cast<llvm::GlobalVariable>(GetAddrOfGlobalDecl(D)); + + // If the storage class is external and there is no initializer, just leave it + // as a declaration. + if (D->getStorageClass() == VarDecl::Extern && D->getInit() == 0) + return; + + // Otherwise, convert the initializer, or use zero if appropriate. + llvm::Constant *Init; + if (D->getInit() == 0) + Init = llvm::Constant::getNullValue(GV->getType()->getElementType()); + else + assert(D->getInit() == 0 && "FIXME: Global variable initializers unimp!"); + + GV->setInitializer(Init); + + // Set the llvm linkage type as appropriate. + // FIXME: This isn't right. This should handle common linkage and other + // stuff. + switch (D->getStorageClass()) { + case VarDecl::Auto: + case VarDecl::Register: + assert(0 && "Can't have auto or register globals"); + case VarDecl::None: + case VarDecl::Extern: + // todo: common + break; + case VarDecl::Static: + GV->setLinkage(llvm::GlobalVariable::InternalLinkage); + break; + } +} llvm::Function *CodeGenModule::getMemCpyFn() { |