[llvm-commits] [llvm] r51293 - /llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp

Dan Gohman gohman at apple.com
Mon May 19 20:20:10 PDT 2008


Author: djg
Date: Mon May 19 22:20:09 2008
New Revision: 51293

URL: http://llvm.org/viewvc/llvm-project?rev=51293&view=rev
Log:
Fix ExecutionEngine's constant code to work properly when structs and arrays
will become first-class types.

Modified:
    llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp

Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=51293&r1=51292&r2=51293&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Mon May 19 22:20:09 2008
@@ -812,35 +812,26 @@
   } 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





More information about the llvm-commits mailing list