Changeset View
Changeset View
Standalone View
Standalone View
llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
Show First 20 Lines • Show All 1,013 Lines • ▼ Show 20 Lines | default: | ||||
raw_svector_ostream OS(Msg); | raw_svector_ostream OS(Msg); | ||||
OS << "ERROR: Constant unimplemented for type: " << *C->getType(); | OS << "ERROR: Constant unimplemented for type: " << *C->getType(); | ||||
report_fatal_error(OS.str()); | report_fatal_error(OS.str()); | ||||
} | } | ||||
return Result; | return Result; | ||||
} | } | ||||
/// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst | |||||
/// with the integer held in IntVal. | |||||
static void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst, | |||||
unsigned StoreBytes) { | |||||
assert((IntVal.getBitWidth()+7)/8 >= StoreBytes && "Integer too small!"); | |||||
const uint8_t *Src = (const uint8_t *)IntVal.getRawData(); | |||||
if (sys::IsLittleEndianHost) { | |||||
// Little-endian host - the source is ordered from LSB to MSB. Order the | |||||
// destination from LSB to MSB: Do a straight copy. | |||||
memcpy(Dst, Src, StoreBytes); | |||||
} else { | |||||
// Big-endian host - the source is an array of 64 bit words ordered from | |||||
// LSW to MSW. Each word is ordered from MSB to LSB. Order the destination | |||||
// from MSB to LSB: Reverse the word order, but not the bytes in a word. | |||||
while (StoreBytes > sizeof(uint64_t)) { | |||||
StoreBytes -= sizeof(uint64_t); | |||||
// May not be aligned so use memcpy. | |||||
memcpy(Dst + StoreBytes, Src, sizeof(uint64_t)); | |||||
Src += sizeof(uint64_t); | |||||
} | |||||
memcpy(Dst, Src + sizeof(uint64_t) - StoreBytes, StoreBytes); | |||||
} | |||||
} | |||||
void ExecutionEngine::StoreValueToMemory(const GenericValue &Val, | void ExecutionEngine::StoreValueToMemory(const GenericValue &Val, | ||||
GenericValue *Ptr, Type *Ty) { | GenericValue *Ptr, Type *Ty) { | ||||
const unsigned StoreBytes = getDataLayout().getTypeStoreSize(Ty); | const unsigned StoreBytes = getDataLayout().getTypeStoreSize(Ty); | ||||
switch (Ty->getTypeID()) { | switch (Ty->getTypeID()) { | ||||
default: | default: | ||||
dbgs() << "Cannot store value of type " << *Ty << "!\n"; | dbgs() << "Cannot store value of type " << *Ty << "!\n"; | ||||
break; | break; | ||||
Show All 31 Lines | case Type::VectorTyID: | ||||
break; | break; | ||||
} | } | ||||
if (sys::IsLittleEndianHost != getDataLayout().isLittleEndian()) | if (sys::IsLittleEndianHost != getDataLayout().isLittleEndian()) | ||||
// Host and target are different endian - reverse the stored bytes. | // Host and target are different endian - reverse the stored bytes. | ||||
std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr); | std::reverse((uint8_t*)Ptr, StoreBytes + (uint8_t*)Ptr); | ||||
} | } | ||||
/// LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting | |||||
/// from Src into IntVal, which is assumed to be wide enough and to hold zero. | |||||
static void LoadIntFromMemory(APInt &IntVal, uint8_t *Src, unsigned LoadBytes) { | |||||
assert((IntVal.getBitWidth()+7)/8 >= LoadBytes && "Integer too small!"); | |||||
uint8_t *Dst = reinterpret_cast<uint8_t *>( | |||||
const_cast<uint64_t *>(IntVal.getRawData())); | |||||
if (sys::IsLittleEndianHost) | |||||
// Little-endian host - the destination must be ordered from LSB to MSB. | |||||
// The source is ordered from LSB to MSB: Do a straight copy. | |||||
memcpy(Dst, Src, LoadBytes); | |||||
else { | |||||
// Big-endian - the destination is an array of 64 bit words ordered from | |||||
// LSW to MSW. Each word must be ordered from MSB to LSB. The source is | |||||
// ordered from MSB to LSB: Reverse the word order, but not the bytes in | |||||
// a word. | |||||
while (LoadBytes > sizeof(uint64_t)) { | |||||
LoadBytes -= sizeof(uint64_t); | |||||
// May not be aligned so use memcpy. | |||||
memcpy(Dst, Src + LoadBytes, sizeof(uint64_t)); | |||||
Dst += sizeof(uint64_t); | |||||
} | |||||
memcpy(Dst + sizeof(uint64_t) - LoadBytes, Src, LoadBytes); | |||||
} | |||||
} | |||||
/// FIXME: document | /// FIXME: document | ||||
/// | /// | ||||
void ExecutionEngine::LoadValueFromMemory(GenericValue &Result, | void ExecutionEngine::LoadValueFromMemory(GenericValue &Result, | ||||
GenericValue *Ptr, | GenericValue *Ptr, | ||||
Type *Ty) { | Type *Ty) { | ||||
const unsigned LoadBytes = getDataLayout().getTypeStoreSize(Ty); | const unsigned LoadBytes = getDataLayout().getTypeStoreSize(Ty); | ||||
switch (Ty->getTypeID()) { | switch (Ty->getTypeID()) { | ||||
▲ Show 20 Lines • Show All 233 Lines • Show Last 20 Lines |