mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 15:39:06 +00:00
Remove #include
Extend getNullValue to work with struct and array types git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5718 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
42289a3010
commit
27accf7692
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user