[cfe-commits] r43519 - in /cfe/trunk/CodeGen: CodeGenModule.cpp CodeGenModule.h
Devang Patel
dpatel at apple.com
Tue Oct 30 14:27:20 PDT 2007
Author: dpatel
Date: Tue Oct 30 16:27:20 2007
New Revision: 43519
URL: http://llvm.org/viewvc/llvm-project?rev=43519&view=rev
Log:
Refactor code into a separate method.
Modified:
cfe/trunk/CodeGen/CodeGenModule.cpp
cfe/trunk/CodeGen/CodeGenModule.h
Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=43519&r1=43518&r2=43519&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Tue Oct 30 16:27:20 2007
@@ -54,6 +54,47 @@
CodeGenFunction(*this).GenerateCode(FD);
}
+llvm::Constant *CodeGenModule::EmitGlobalInit(const FileVarDecl *D,
+ llvm::GlobalVariable *GV) {
+
+ const InitListExpr *ILE = dyn_cast<InitListExpr>(D->getInit());
+ if (!ILE)
+ return 0;
+
+ 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();
+ const llvm::Type *AElemTy = AType->getElementType();
+ for (; i < NumArrayElements; ++i)
+ ArrayElts.push_back(llvm::Constant::getNullValue(AElemTy));
+
+ return llvm::ConstantArray::get(AType, ArrayElts);
+}
+
void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
llvm::GlobalVariable *GV = cast<llvm::GlobalVariable>(GetAddrOfGlobalDecl(D));
@@ -73,44 +114,10 @@
Init = llvm::ConstantInt::get(Value);
}
- if (!Init) {
- if (const InitListExpr *ILE = dyn_cast<InitListExpr>(D->getInit())) {
+ if (!Init)
+ Init = EmitGlobalInit(D, GV);
- 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();
- const llvm::Type *AElemTy = AType->getElementType();
- for (; i < NumArrayElements; ++i)
- ArrayElts.push_back(llvm::Constant::getNullValue(AElemTy));
-
- Init = llvm::ConstantArray::get(AType, ArrayElts);
- } else
- assert(Init && "FIXME: Global variable initializers unimp!");
- }
+ assert(Init && "FIXME: Global variable initializers unimp!");
GV->setInitializer(Init);
Modified: cfe/trunk/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.h?rev=43519&r1=43518&r2=43519&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/CodeGen/CodeGenModule.h Tue Oct 30 16:27:20 2007
@@ -22,6 +22,7 @@
class Module;
class Constant;
class Function;
+ class GlobalVariable;
}
namespace clang {
@@ -67,6 +68,8 @@
void EmitFunction(const FunctionDecl *FD);
void EmitGlobalVar(const FileVarDecl *D);
void EmitGlobalVarDeclarator(const FileVarDecl *D);
+ llvm::Constant *EmitGlobalInit(const FileVarDecl *D,
+ llvm::GlobalVariable *GV);
void PrintStats() {}
};
More information about the cfe-commits
mailing list