/// 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
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
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: {
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
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());
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;
// 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...
// 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);