-static void executeStoreInst(StoreInst *I, ExecutionContext &SF) {
- GenericValue SRC = getOperandValue(I->getPointerOperand(), SF);
- PointerTy SrcPtr = SRC.PointerVal;
- SrcPtr += getElementOffset(I, SF); // Handle any structure indices
-
- GenericValue *Ptr = (GenericValue *)SrcPtr;
- GenericValue Val = getOperandValue(I->getOperand(0), SF);
-
- switch (I->getOperand(0)->getType()->getPrimitiveID()) {
- case Type::BoolTyID:
- case Type::UByteTyID:
- case Type::SByteTyID: Ptr->SByteVal = Val.SByteVal; break;
- case Type::UShortTyID:
- case Type::ShortTyID: Ptr->ShortVal = Val.ShortVal; break;
- case Type::UIntTyID:
- case Type::IntTyID: Ptr->IntVal = Val.IntVal; break;
- case Type::ULongTyID:
- case Type::LongTyID: Ptr->LongVal = Val.LongVal; break;
- case Type::PointerTyID: Ptr->PointerVal = Val.PointerVal; break;
- case Type::FloatTyID: Ptr->FloatVal = Val.FloatVal; break;
- case Type::DoubleTyID: Ptr->DoubleVal = Val.DoubleVal; break;
- default:
- cout << "Cannot store value of type " << I->getType() << "!\n";
+static void StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
+ const Type *Ty) {
+ if (TD.isLittleEndian()) {
+ switch (Ty->getPrimitiveID()) {
+ case Type::BoolTyID:
+ case Type::UByteTyID:
+ case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break;
+ case Type::UShortTyID:
+ case Type::ShortTyID: Ptr->Untyped[0] = Val.UShortVal & 255;
+ Ptr->Untyped[1] = (Val.UShortVal >> 8) & 255;
+ break;
+ case Type::FloatTyID:
+ case Type::UIntTyID:
+ case Type::IntTyID: Ptr->Untyped[0] = Val.UIntVal & 255;
+ Ptr->Untyped[1] = (Val.UIntVal >> 8) & 255;
+ Ptr->Untyped[2] = (Val.UIntVal >> 16) & 255;
+ Ptr->Untyped[3] = (Val.UIntVal >> 24) & 255;
+ break;
+ case Type::DoubleTyID:
+ case Type::ULongTyID:
+ case Type::LongTyID:
+ case Type::PointerTyID: Ptr->Untyped[0] = Val.ULongVal & 255;
+ Ptr->Untyped[1] = (Val.ULongVal >> 8) & 255;
+ Ptr->Untyped[2] = (Val.ULongVal >> 16) & 255;
+ Ptr->Untyped[3] = (Val.ULongVal >> 24) & 255;
+ Ptr->Untyped[4] = (Val.ULongVal >> 32) & 255;
+ Ptr->Untyped[5] = (Val.ULongVal >> 40) & 255;
+ Ptr->Untyped[6] = (Val.ULongVal >> 48) & 255;
+ Ptr->Untyped[7] = (Val.ULongVal >> 56) & 255;
+ break;
+ default:
+ cout << "Cannot load value of type " << Ty << "!\n";
+ }
+ } else {
+ switch (Ty->getPrimitiveID()) {
+ case Type::BoolTyID:
+ case Type::UByteTyID:
+ case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break;
+ case Type::UShortTyID:
+ case Type::ShortTyID: Ptr->Untyped[1] = Val.UShortVal & 255;
+ Ptr->Untyped[0] = (Val.UShortVal >> 8) & 255;
+ break;
+ case Type::FloatTyID:
+ case Type::UIntTyID:
+ case Type::IntTyID: Ptr->Untyped[3] = Val.UIntVal & 255;
+ Ptr->Untyped[2] = (Val.UIntVal >> 8) & 255;
+ Ptr->Untyped[1] = (Val.UIntVal >> 16) & 255;
+ Ptr->Untyped[0] = (Val.UIntVal >> 24) & 255;
+ break;
+ case Type::DoubleTyID:
+ case Type::ULongTyID:
+ case Type::LongTyID:
+ case Type::PointerTyID: Ptr->Untyped[7] = Val.ULongVal & 255;
+ Ptr->Untyped[6] = (Val.ULongVal >> 8) & 255;
+ Ptr->Untyped[5] = (Val.ULongVal >> 16) & 255;
+ Ptr->Untyped[4] = (Val.ULongVal >> 24) & 255;
+ Ptr->Untyped[3] = (Val.ULongVal >> 32) & 255;
+ Ptr->Untyped[2] = (Val.ULongVal >> 40) & 255;
+ Ptr->Untyped[1] = (Val.ULongVal >> 48) & 255;
+ Ptr->Untyped[0] = (Val.ULongVal >> 56) & 255;
+ break;
+ default:
+ cout << "Cannot load value of type " << Ty << "!\n";
+ }