aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-05-20 03:20:09 +0000
committerDan Gohman <gohman@apple.com>2008-05-20 03:20:09 +0000
commit638e378f2cb62c34f306f8eadd43039e20caede4 (patch)
tree488fd83fc79e10059b5992a59a461d25cd1ca228 /lib/ExecutionEngine
parentca756ae886f1d39053ffd049123fdcc7e5c2aed3 (diff)
downloadexternal_llvm-638e378f2cb62c34f306f8eadd43039e20caede4.zip
external_llvm-638e378f2cb62c34f306f8eadd43039e20caede4.tar.gz
external_llvm-638e378f2cb62c34f306f8eadd43039e20caede4.tar.bz2
Fix ExecutionEngine's constant code to work properly when structs and arrays
will become first-class types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51293 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r--lib/ExecutionEngine/ExecutionEngine.cpp25
1 files changed, 8 insertions, 17 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp
index 8bd3b11..535f4ac 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -812,35 +812,26 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
} else if (isa<ConstantAggregateZero>(Init)) {
memset(Addr, 0, (size_t)getTargetData()->getABITypeSize(Init->getType()));
return;
- } else if (Init->getType()->isFirstClassType()) {
- GenericValue Val = getConstantValue(Init);
- StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
- return;
- }
-
- switch (Init->getType()->getTypeID()) {
- case Type::ArrayTyID: {
- const ConstantArray *CPA = cast<ConstantArray>(Init);
+ } else if (const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
unsigned ElementSize =
getTargetData()->getABITypeSize(CPA->getType()->getElementType());
for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
return;
- }
-
- case Type::StructTyID: {
- const ConstantStruct *CPS = cast<ConstantStruct>(Init);
+ } else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
const StructLayout *SL =
getTargetData()->getStructLayout(cast<StructType>(CPS->getType()));
for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->getElementOffset(i));
return;
+ } else if (Init->getType()->isFirstClassType()) {
+ GenericValue Val = getConstantValue(Init);
+ StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
+ return;
}
- default:
- cerr << "Bad Type: " << *Init->getType() << "\n";
- assert(0 && "Unknown constant type to initialize memory with!");
- }
+ cerr << "Bad Type: " << *Init->getType() << "\n";
+ assert(0 && "Unknown constant type to initialize memory with!");
}
/// EmitGlobals - Emit all of the global variables to memory, storing their