diff options
author | Chris Lattner <sabre@nondot.org> | 2003-05-08 16:52:16 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-05-08 16:52:16 +0000 |
commit | f88b9a639770327196b2a00f365155b954dd1d30 (patch) | |
tree | 29d4754a82964f1ca4218f9bb313c455f5c481a1 /lib/ExecutionEngine | |
parent | da82ed52ac02497d343b898cca0bb2cf303f062d (diff) | |
download | external_llvm-f88b9a639770327196b2a00f365155b954dd1d30.zip external_llvm-f88b9a639770327196b2a00f365155b954dd1d30.tar.gz external_llvm-f88b9a639770327196b2a00f365155b954dd1d30.tar.bz2 |
Add a pointersize/endianness safe load routine to match the store routine
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6042 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/ExecutionEngine.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index dcfbde4..a3c3f47 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -152,6 +152,82 @@ void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr, } } +GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr, + const Type *Ty) { + GenericValue Result; + if (getTargetData().isLittleEndian()) { + switch (Ty->getPrimitiveID()) { + case Type::BoolTyID: + case Type::UByteTyID: + case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break; + case Type::UShortTyID: + case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[0] | + ((unsigned)Ptr->Untyped[1] << 8); + break; + Load4BytesLittleEndian: + case Type::FloatTyID: + case Type::UIntTyID: + case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[0] | + ((unsigned)Ptr->Untyped[1] << 8) | + ((unsigned)Ptr->Untyped[2] << 16) | + ((unsigned)Ptr->Untyped[3] << 24); + break; + case Type::PointerTyID: if (getModule().has32BitPointers()) + goto Load4BytesLittleEndian; + case Type::DoubleTyID: + case Type::ULongTyID: + case Type::LongTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[0] | + ((uint64_t)Ptr->Untyped[1] << 8) | + ((uint64_t)Ptr->Untyped[2] << 16) | + ((uint64_t)Ptr->Untyped[3] << 24) | + ((uint64_t)Ptr->Untyped[4] << 32) | + ((uint64_t)Ptr->Untyped[5] << 40) | + ((uint64_t)Ptr->Untyped[6] << 48) | + ((uint64_t)Ptr->Untyped[7] << 56); + break; + default: + std::cout << "Cannot load value of type " << *Ty << "!\n"; + abort(); + } + } else { + switch (Ty->getPrimitiveID()) { + case Type::BoolTyID: + case Type::UByteTyID: + case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break; + case Type::UShortTyID: + case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[1] | + ((unsigned)Ptr->Untyped[0] << 8); + break; + Load4BytesBigEndian: + case Type::FloatTyID: + case Type::UIntTyID: + case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[3] | + ((unsigned)Ptr->Untyped[2] << 8) | + ((unsigned)Ptr->Untyped[1] << 16) | + ((unsigned)Ptr->Untyped[0] << 24); + break; + case Type::PointerTyID: if (getModule().has32BitPointers()) + goto Load4BytesBigEndian; + case Type::DoubleTyID: + case Type::ULongTyID: + case Type::LongTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[7] | + ((uint64_t)Ptr->Untyped[6] << 8) | + ((uint64_t)Ptr->Untyped[5] << 16) | + ((uint64_t)Ptr->Untyped[4] << 24) | + ((uint64_t)Ptr->Untyped[3] << 32) | + ((uint64_t)Ptr->Untyped[2] << 40) | + ((uint64_t)Ptr->Untyped[1] << 48) | + ((uint64_t)Ptr->Untyped[0] << 56); + break; + default: + std::cout << "Cannot load value of type " << *Ty << "!\n"; + abort(); + } + } + return Result; +} + + // InitializeMemory - Recursive function to apply a Constant value into the // specified memory location... // |