summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-03-06 21:02:18 +0000
committerChris Lattner <sabre@nondot.org>2003-03-06 21:02:18 +0000
commitc33ae6723733877871e1dfc6ad65d7db5402217f (patch)
tree2435122d52dfa4cd5dd30c2df44f49866375267a /llvm
parent81e92fe0bdfa086f2b40f646dcc5c3b2637c075b (diff)
downloadbcm5719-llvm-c33ae6723733877871e1dfc6ad65d7db5402217f.tar.gz
bcm5719-llvm-c33ae6723733877871e1dfc6ad65d7db5402217f.zip
Remove #include
Extend getNullValue to work with struct and array types llvm-svn: 5718
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/VMCore/Constants.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 3887e33274a..6a91757641a 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -9,7 +9,6 @@
#include "llvm/iMemory.h"
#include "llvm/SymbolTable.h"
#include "llvm/Module.h"
-#include "llvm/SlotCalculator.h"
#include "Support/StringExtras.h"
#include <algorithm>
@@ -80,7 +79,25 @@ Constant *Constant::getNullValue(const Type *Ty) {
case Type::PointerTyID:
return ConstantPointerNull::get(cast<PointerType>(Ty));
+ case Type::StructTyID: {
+ const StructType *ST = cast<StructType>(Ty);
+
+ const StructType::ElementTypes &ETs = ST->getElementTypes();
+ std::vector<Constant*> Elements;
+ Elements.resize(ETs.size());
+ for (unsigned i = 0, e = ETs.size(); i != e; ++i)
+ Elements[i] = Constant::getNullValue(ETs[i]);
+ return ConstantStruct::get(ST, Elements);
+ }
+ case Type::ArrayTyID: {
+ const ArrayType *AT = cast<ArrayType>(Ty);
+ Constant *El = Constant::getNullValue(AT->getElementType());
+ unsigned NumElements = AT->getNumElements();
+ return ConstantArray::get(AT, std::vector<Constant*>(NumElements, El));
+ }
default:
+ // Function, Type, Label, or Opaque type?
+ assert(0 && "Cannot create a null constant of that type!");
return 0;
}
}
OpenPOWER on IntegriCloud