Make iostream #inclusion explicit
[oota-llvm.git] / lib / ExecutionEngine / ExecutionEngine.cpp
index 22a28b51c85f67d61faa72cd174f52b6681f7472..53587bff5a077c413e1925812c394957e55c7577 100644 (file)
@@ -50,16 +50,18 @@ ExecutionEngine::~ExecutionEngine() {
 /// at the specified address.
 ///
 const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
+  MutexGuard locked(lock);
+
   // If we haven't computed the reverse mapping yet, do so first.
-  if (GlobalAddressReverseMap.empty()) {
+  if (state.getGlobalAddressReverseMap(locked).empty()) {
     for (std::map<const GlobalValue*, void *>::iterator I =
-           GlobalAddressMap.begin(), E = GlobalAddressMap.end(); I != E; ++I)
-      GlobalAddressReverseMap.insert(std::make_pair(I->second, I->first));
+           state.getGlobalAddressMap(locked).begin(), E = state.getGlobalAddressMap(locked).end(); I != E; ++I)
+      state.getGlobalAddressReverseMap(locked).insert(std::make_pair(I->second, I->first));
   }
 
   std::map<void *, const GlobalValue*>::iterator I =
-    GlobalAddressReverseMap.find(Addr);
-  return I != GlobalAddressReverseMap.end() ? I->second : 0;
+    state.getGlobalAddressReverseMap(locked).find(Addr);
+  return I != state.getGlobalAddressReverseMap(locked).end() ? I->second : 0;
 }
 
 // CreateArgv - Turn a vector of strings into a nice argv style array of
@@ -168,8 +170,9 @@ void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) {
   if (Function *F = const_cast<Function*>(dyn_cast<Function>(GV)))
     return getPointerToFunction(F);
 
-  assert(GlobalAddressMap[GV] && "Global hasn't had an address allocated yet?");
-  return GlobalAddressMap[GV];
+  MutexGuard locked(lock);
+  assert(state.getGlobalAddressMap(locked)[GV] && "Global hasn't had an address allocated yet?");
+  return state.getGlobalAddressMap(locked)[GV];
 }
 
 /// FIXME: document
@@ -186,7 +189,10 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
       uint64_t Offset =
         TD->getIndexedOffset(CE->getOperand(0)->getType(), Indexes);
 
-      Result.LongVal += Offset;
+      if (getTargetData().getPointerSize() == 4)
+        Result.IntVal += Offset;
+      else
+        Result.LongVal += Offset;
       return Result;
     }
     case Instruction::Cast: {
@@ -271,8 +277,8 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
     GET_CONST_VAL(Short  , signed short  , ConstantSInt);
     GET_CONST_VAL(UInt   , unsigned int  , ConstantUInt);
     GET_CONST_VAL(Int    , signed int    , ConstantSInt);
-    GET_CONST_VAL(ULong  , unsigned long , ConstantUInt);
-    GET_CONST_VAL(Long   , signed long   , ConstantSInt);
+    GET_CONST_VAL(ULong  , uint64_t      , ConstantUInt);
+    GET_CONST_VAL(Long   , int64_t       , ConstantSInt);
     GET_CONST_VAL(Float  , float         , ConstantFP);
     GET_CONST_VAL(Double , double        , ConstantFP);
 #undef GET_CONST_VAL
@@ -451,6 +457,12 @@ GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr,
 void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
   if (isa<UndefValue>(Init)) {
     return;
+  } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(Init)) {
+    unsigned ElementSize =
+      getTargetData().getTypeSize(CP->getType()->getElementType());
+    for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
+      InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
+    return;
   } else if (Init->getType()->isFirstClassType()) {
     GenericValue Val = getConstantValue(Init);
     StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
@@ -464,7 +476,7 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
   case Type::ArrayTyID: {
     const ConstantArray *CPA = cast<ConstantArray>(Init);
     unsigned ElementSize =
-      getTargetData().getTypeSize(cast<ArrayType>(CPA->getType())->getElementType());
+      getTargetData().getTypeSize(CPA->getType()->getElementType());
     for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
       InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
     return;
@@ -494,7 +506,8 @@ void ExecutionEngine::emitGlobals() {
 
   // Loop over all of the global variables in the program, allocating the memory
   // to hold them.
-  for (Module::const_global_iterator I = getModule().global_begin(), E = getModule().global_end();
+  Module &M = getModule();
+  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
        I != E; ++I)
     if (!I->isExternal()) {
       // Get the type of the global...
@@ -518,7 +531,7 @@ void ExecutionEngine::emitGlobals() {
 
   // Now that all of the globals are set up in memory, loop through them all and
   // initialize their contents.
-  for (Module::const_global_iterator I = getModule().global_begin(), E = getModule().global_end();
+  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
        I != E; ++I)
     if (!I->isExternal())
       EmitGlobalVariable(I);