diff options
author | Devang Patel <dpatel@apple.com> | 2007-10-26 16:31:40 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2007-10-26 16:31:40 +0000 |
commit | 19c2b9a66fa05fc6b945697919e97f52bc5a0c75 (patch) | |
tree | cf71ba39376cd3c9ee045547dc09395bb609e975 /clang/CodeGen/CodeGenModule.cpp | |
parent | 22c6a22d7699c428bda8e15495e5ea3cf0fc4926 (diff) | |
download | bcm5719-llvm-19c2b9a66fa05fc6b945697919e97f52bc5a0c75.tar.gz bcm5719-llvm-19c2b9a66fa05fc6b945697919e97f52bc5a0c75.zip |
Codegen global array initializers.
llvm-svn: 43383
Diffstat (limited to 'clang/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/CodeGen/CodeGenModule.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/clang/CodeGen/CodeGenModule.cpp b/clang/CodeGen/CodeGenModule.cpp index 8cb138ebff5..00c262167c6 100644 --- a/clang/CodeGen/CodeGenModule.cpp +++ b/clang/CodeGen/CodeGenModule.cpp @@ -72,7 +72,41 @@ void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) { if (D->getInit()->isIntegerConstantExpr(Value, Context)) Init = llvm::ConstantInt::get(Value); } - assert(Init && "FIXME: Global variable initializers unimp!"); + + if (!Init) { + if (const InitListExpr *ILE = dyn_cast<InitListExpr>(D->getInit())) { + + unsigned NumInitElements = ILE->getNumInits(); + + assert ( ILE->getType()->isArrayType() + && "FIXME: Only Array initializers are supported"); + + std::vector<llvm::Constant*> ArrayElts; + const llvm::PointerType *APType = cast<llvm::PointerType>(GV->getType()); + const llvm::ArrayType *AType = cast<llvm::ArrayType>(APType->getElementType()); + + // Copy initializer elements. + unsigned i = 0; + for (i = 0; i < NumInitElements; ++i) { + assert (ILE->getInit(i)->getType()->isIntegerType() + && "Only IntegerType global array initializers are supported"); + llvm::APSInt Value(static_cast<uint32_t>( + getContext().getTypeSize(ILE->getInit(i)->getType(), SourceLocation()))); + if (ILE->getInit(i)->isIntegerConstantExpr(Value, Context)) { + llvm::Constant *C = llvm::ConstantInt::get(Value); + ArrayElts.push_back(C); + } + } + + // Initialize remaining array elements. + unsigned NumArrayElements = AType->getNumElements(); + for (; i < NumArrayElements; ++i) + ArrayElts.push_back(llvm::Constant::getNullValue(AType->getElementType())); + + Init = llvm::ConstantArray::get(AType, ArrayElts); + } else + assert(Init && "FIXME: Global variable initializers unimp!"); + } GV->setInitializer(Init); |