[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Mar 6 15:03:01 PST 2003
Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.32 -> 1.33
---
Log message:
Remove #include
Extend getNullValue to work with struct and array types
---
Diffs of the changes:
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.32 llvm/lib/VMCore/Constants.cpp:1.33
--- llvm/lib/VMCore/Constants.cpp:1.32 Sun Oct 13 22:30:23 2002
+++ llvm/lib/VMCore/Constants.cpp Thu Mar 6 15:02:18 2003
@@ -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 @@
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;
}
}
More information about the llvm-commits
mailing list