- if (getTargetData()->isLittleEndian()) {
- switch (Ty->getTypeID()) {
- case Type::IntegerTyID: {
- unsigned BitWidth = cast<IntegerType>(Ty)->getBitWidth();
- uint64_t BitMask = cast<IntegerType>(Ty)->getBitMask();
- GenericValue TmpVal = Val;
- if (BitWidth <= 8)
- Ptr->Untyped[0] = Val.Int8Val & BitMask;
- else if (BitWidth <= 16) {
- TmpVal.Int16Val &= BitMask;
- Ptr->Untyped[0] = TmpVal.Int16Val & 255;
- Ptr->Untyped[1] = (TmpVal.Int16Val >> 8) & 255;
- } else if (BitWidth <= 32) {
- TmpVal.Int32Val &= BitMask;
- Ptr->Untyped[0] = TmpVal.Int32Val & 255;
- Ptr->Untyped[1] = (TmpVal.Int32Val >> 8) & 255;
- Ptr->Untyped[2] = (TmpVal.Int32Val >> 16) & 255;
- Ptr->Untyped[3] = (TmpVal.Int32Val >> 24) & 255;
- } else if (BitWidth <= 64) {
- TmpVal.Int64Val &= BitMask;
- Ptr->Untyped[0] = (unsigned char)(TmpVal.Int64Val );
- Ptr->Untyped[1] = (unsigned char)(TmpVal.Int64Val >> 8);
- Ptr->Untyped[2] = (unsigned char)(TmpVal.Int64Val >> 16);
- Ptr->Untyped[3] = (unsigned char)(TmpVal.Int64Val >> 24);
- Ptr->Untyped[4] = (unsigned char)(TmpVal.Int64Val >> 32);
- Ptr->Untyped[5] = (unsigned char)(TmpVal.Int64Val >> 40);
- Ptr->Untyped[6] = (unsigned char)(TmpVal.Int64Val >> 48);
- Ptr->Untyped[7] = (unsigned char)(TmpVal.Int64Val >> 56);
- } else {
- uint64_t *Dest = (uint64_t*)Ptr;
- const uint64_t *Src = Val.APIntVal->getRawData();
- for (uint32_t i = 0; i < Val.APIntVal->getNumWords(); ++i)
- Dest[i] = Src[i];
- }
- break;
- }
-Store4BytesLittleEndian:
- case Type::FloatTyID:
- Ptr->Untyped[0] = Val.Int32Val & 255;
- Ptr->Untyped[1] = (Val.Int32Val >> 8) & 255;
- Ptr->Untyped[2] = (Val.Int32Val >> 16) & 255;
- Ptr->Untyped[3] = (Val.Int32Val >> 24) & 255;
- break;
- case Type::PointerTyID:
- if (getTargetData()->getPointerSize() == 4)
- goto Store4BytesLittleEndian;
- /* FALL THROUGH */
- case Type::DoubleTyID:
- Ptr->Untyped[0] = (unsigned char)(Val.Int64Val );
- Ptr->Untyped[1] = (unsigned char)(Val.Int64Val >> 8);
- Ptr->Untyped[2] = (unsigned char)(Val.Int64Val >> 16);
- Ptr->Untyped[3] = (unsigned char)(Val.Int64Val >> 24);
- Ptr->Untyped[4] = (unsigned char)(Val.Int64Val >> 32);
- Ptr->Untyped[5] = (unsigned char)(Val.Int64Val >> 40);
- Ptr->Untyped[6] = (unsigned char)(Val.Int64Val >> 48);
- Ptr->Untyped[7] = (unsigned char)(Val.Int64Val >> 56);
- break;
- default:
- cerr << "Cannot store value of type " << *Ty << "!\n";
- }
- } else {
- switch (Ty->getTypeID()) {
- case Type::IntegerTyID: {
- unsigned BitWidth = cast<IntegerType>(Ty)->getBitWidth();
- uint64_t BitMask = cast<IntegerType>(Ty)->getBitMask();
- GenericValue TmpVal = Val;
- if (BitWidth <= 8)
- Ptr->Untyped[0] = Val.Int8Val & BitMask;
- else if (BitWidth <= 16) {
- TmpVal.Int16Val &= BitMask;
- Ptr->Untyped[1] = TmpVal.Int16Val & 255;
- Ptr->Untyped[0] = (TmpVal.Int16Val >> 8) & 255;
- } else if (BitWidth <= 32) {
- TmpVal.Int32Val &= BitMask;
- Ptr->Untyped[3] = TmpVal.Int32Val & 255;
- Ptr->Untyped[2] = (TmpVal.Int32Val >> 8) & 255;
- Ptr->Untyped[1] = (TmpVal.Int32Val >> 16) & 255;
- Ptr->Untyped[0] = (TmpVal.Int32Val >> 24) & 255;
- } else if (BitWidth <= 64) {
- TmpVal.Int64Val &= BitMask;
- Ptr->Untyped[7] = (unsigned char)(TmpVal.Int64Val );
- Ptr->Untyped[6] = (unsigned char)(TmpVal.Int64Val >> 8);
- Ptr->Untyped[5] = (unsigned char)(TmpVal.Int64Val >> 16);
- Ptr->Untyped[4] = (unsigned char)(TmpVal.Int64Val >> 24);
- Ptr->Untyped[3] = (unsigned char)(TmpVal.Int64Val >> 32);
- Ptr->Untyped[2] = (unsigned char)(TmpVal.Int64Val >> 40);
- Ptr->Untyped[1] = (unsigned char)(TmpVal.Int64Val >> 48);
- Ptr->Untyped[0] = (unsigned char)(TmpVal.Int64Val >> 56);
- } else {
- uint64_t *Dest = (uint64_t*)Ptr;
- const uint64_t *Src = Val.APIntVal->getRawData();
- for (uint32_t i = 0; i < Val.APIntVal->getNumWords(); ++i)
- Dest[i] = Src[i];
- }
- break;
- }
- Store4BytesBigEndian:
- case Type::FloatTyID:
- Ptr->Untyped[3] = Val.Int32Val & 255;
- Ptr->Untyped[2] = (Val.Int32Val >> 8) & 255;
- Ptr->Untyped[1] = (Val.Int32Val >> 16) & 255;
- Ptr->Untyped[0] = (Val.Int32Val >> 24) & 255;
- break;
- case Type::PointerTyID:
- if (getTargetData()->getPointerSize() == 4)
- goto Store4BytesBigEndian;
- /* FALL THROUGH */
- case Type::DoubleTyID:
- Ptr->Untyped[7] = (unsigned char)(Val.Int64Val );
- Ptr->Untyped[6] = (unsigned char)(Val.Int64Val >> 8);
- Ptr->Untyped[5] = (unsigned char)(Val.Int64Val >> 16);
- Ptr->Untyped[4] = (unsigned char)(Val.Int64Val >> 24);
- Ptr->Untyped[3] = (unsigned char)(Val.Int64Val >> 32);
- Ptr->Untyped[2] = (unsigned char)(Val.Int64Val >> 40);
- Ptr->Untyped[1] = (unsigned char)(Val.Int64Val >> 48);
- Ptr->Untyped[0] = (unsigned char)(Val.Int64Val >> 56);
- break;
- default:
- cerr << "Cannot store value of type " << *Ty << "!\n";