[llvm-commits] CVS: llvm/tools/lli/ExecutionEngine.cpp ExecutionEngine.h
Chris Lattner
lattner at cs.uiuc.edu
Thu May 8 11:53:01 PDT 2003
Changes in directory llvm/tools/lli:
ExecutionEngine.cpp updated: 1.8 -> 1.9
ExecutionEngine.h updated: 1.1 -> 1.2
---
Log message:
Add a pointersize/endianness safe load routine to match the store routine
---
Diffs of the changes:
Index: llvm/tools/lli/ExecutionEngine.cpp
diff -u llvm/tools/lli/ExecutionEngine.cpp:1.8 llvm/tools/lli/ExecutionEngine.cpp:1.9
--- llvm/tools/lli/ExecutionEngine.cpp:1.8 Wed May 7 15:31:37 2003
+++ llvm/tools/lli/ExecutionEngine.cpp Thu May 8 11:52:16 2003
@@ -152,6 +152,82 @@
}
}
+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...
//
Index: llvm/tools/lli/ExecutionEngine.h
diff -u llvm/tools/lli/ExecutionEngine.h:1.1 llvm/tools/lli/ExecutionEngine.h:1.2
--- llvm/tools/lli/ExecutionEngine.h:1.1 Mon Dec 23 18:01:01 2002
+++ llvm/tools/lli/ExecutionEngine.h Thu May 8 11:52:16 2003
@@ -79,6 +79,7 @@
public: // FIXME: protected: // API shared among subclasses
GenericValue getConstantValue(const Constant *C);
void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
+ GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
void *CreateArgv(const std::vector<std::string> &InputArgv);
void InitializeMemory(const Constant *Init, void *Addr);
};
More information about the llvm-commits
mailing list