1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +02:00

Fixed 64-bit field data for 32-bit builds

This commit is contained in:
Brian Fiete 2021-12-29 13:01:13 -05:00
parent 7e315e49d2
commit 6fe6b8f2e6
3 changed files with 98 additions and 35 deletions

View file

@ -10,7 +10,7 @@ namespace System
for (var field in type.GetFields()) for (var field in type.GetFields())
{ {
if (field.[Friend]mFieldData.mFlags.HasFlag(.EnumCase) && if (field.[Friend]mFieldData.mFlags.HasFlag(.EnumCase) &&
field.[Friend]mFieldData.[Friend]mData == iVal) *(int64*)&field.[Friend]mFieldData.[Friend]mData == iVal)
{ {
strBuffer.Append(field.Name); strBuffer.Append(field.Name);
return; return;
@ -132,7 +132,7 @@ namespace System
{ {
get get
{ {
return ((.)base.Current.[Friend]mFieldData.[Friend]mName, (.)base.Current.[Friend]mFieldData.[Friend]mData); return ((.)base.Current.[Friend]mFieldData.[Friend]mName, (.)*(int64*)&base.Current.[Friend]mFieldData.[Friend]mData);
} }
} }
@ -151,7 +151,7 @@ namespace System
{ {
get get
{ {
return (.)base.Current.[Friend]mFieldData.[Friend]mData; return (.)*(int64*)&base.Current.[Friend]mFieldData.[Friend]mData;
} }
} }

View file

@ -694,7 +694,10 @@ namespace System.Reflection
{ {
public String mName; public String mName;
public TypeId mFieldTypeId; public TypeId mFieldTypeId;
public int64 mData; public int mData;
#if BF_32_BIT
public int mDataHi;
#endif
public FieldFlags mFlags; public FieldFlags mFlags;
public int32 mCustomAttributesIdx; public int32 mCustomAttributesIdx;
} }

View file

@ -6372,36 +6372,72 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
FieldFlags_EnumCase = 0x400 FieldFlags_EnumCase = 0x400
}; };
bool is32Bit = mCompiler->mSystem->mPtrSize == 4;
if ((typeInstance->IsPayloadEnum()) && (!typeInstance->IsBoxed())) if ((typeInstance->IsPayloadEnum()) && (!typeInstance->IsBoxed()))
{ {
BfType* payloadType = typeInstance->GetUnionInnerType(); BfType* payloadType = typeInstance->GetUnionInnerType();
if (!payloadType->IsValuelessType()) if (!payloadType->IsValuelessType())
{ {
BfIRValue payloadNameConst = GetStringObjectValue("$payload", !mIsComptimeModule); BfIRValue payloadNameConst = GetStringObjectValue("$payload", !mIsComptimeModule);
SizedArray<BfIRValue, 8> payloadFieldVals = SizedArray<BfIRValue, 8> payloadFieldVals;
if (is32Bit)
{ {
emptyValueType, payloadFieldVals =
payloadNameConst, // mName {
GetConstValue(payloadType->mTypeId, typeIdType), // mFieldTypeId emptyValueType,
GetConstValue(0, longType), // mData payloadNameConst, // mName
GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumPayload, shortType), // mFlags GetConstValue(payloadType->mTypeId, typeIdType), // mFieldTypeId
GetConstValue(-1, intType), // mCustomAttributesIdx GetConstValue(0, intPtrType), // mData
}; GetConstValue(0, intPtrType), // mDataHi
GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumPayload, shortType), // mFlags
GetConstValue(-1, intType), // mCustomAttributesIdx
};
}
else
{
payloadFieldVals =
{
emptyValueType,
payloadNameConst, // mName
GetConstValue(payloadType->mTypeId, typeIdType), // mFieldTypeId
GetConstValue(0, intPtrType), // mData
GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumPayload, shortType), // mFlags
GetConstValue(-1, intType), // mCustomAttributesIdx
};
}
auto payloadFieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), payloadFieldVals); auto payloadFieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), payloadFieldVals);
fieldTypes.push_back(payloadFieldData); fieldTypes.push_back(payloadFieldData);
} }
BfType* dscrType = typeInstance->GetDiscriminatorType(); BfType* dscrType = typeInstance->GetDiscriminatorType();
BfIRValue dscrNameConst = GetStringObjectValue("$discriminator", !mIsComptimeModule); BfIRValue dscrNameConst = GetStringObjectValue("$discriminator", !mIsComptimeModule);
SizedArray<BfIRValue, 8> dscrFieldVals = SizedArray<BfIRValue, 8> dscrFieldVals;
if (is32Bit)
{ {
emptyValueType, dscrFieldVals =
dscrNameConst, // mName {
GetConstValue(dscrType->mTypeId, typeIdType), // mFieldTypeId emptyValueType,
GetConstValue(BF_ALIGN(payloadType->mSize, dscrType->mAlign), longType), // mData dscrNameConst, // mName
GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumDiscriminator, shortType), // mFlags GetConstValue(dscrType->mTypeId, typeIdType), // mFieldTypeId
GetConstValue(-1, intType), // mCustomAttributesIdx GetConstValue(BF_ALIGN(payloadType->mSize, dscrType->mAlign), intPtrType), // mData
}; GetConstValue(0, intPtrType), // mDataHi
GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumDiscriminator, shortType), // mFlags
GetConstValue(-1, intType), // mCustomAttributesIdx
};
}
else
{
dscrFieldVals =
{
emptyValueType,
dscrNameConst, // mName
GetConstValue(dscrType->mTypeId, typeIdType), // mFieldTypeId
GetConstValue(BF_ALIGN(payloadType->mSize, dscrType->mAlign), intPtrType), // mData
GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumDiscriminator, shortType), // mFlags
GetConstValue(-1, intType), // mCustomAttributesIdx
};
}
auto dscrFieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), dscrFieldVals); auto dscrFieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), dscrFieldVals);
fieldTypes.push_back(dscrFieldData); fieldTypes.push_back(dscrFieldData);
} }
@ -6440,12 +6476,15 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
int customAttrIdx = _HandleCustomAttrs(fieldInstance->mCustomAttributes); int customAttrIdx = _HandleCustomAttrs(fieldInstance->mCustomAttributes);
BfIRValue constValue; BfIRValue constValue;
BfIRValue constValue2;
if (fieldInstance->GetFieldDef()->mIsConst) if (fieldInstance->GetFieldDef()->mIsConst)
{ {
if (fieldInstance->mConstIdx != -1) if (fieldInstance->mConstIdx != -1)
{ {
auto constant = typeInstance->mConstHolder->GetConstantById(fieldInstance->mConstIdx); auto constant = typeInstance->mConstHolder->GetConstantById(fieldInstance->mConstIdx);
constValue = mBfIRBuilder->CreateConst(BfTypeCode_Int64, constant->mUInt64); constValue = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, constant->mUInt64);
if (is32Bit)
constValue2 = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, constant->mUInt64 >> 32);
} }
} }
else if (fieldInstance->GetFieldDef()->mIsStatic) else if (fieldInstance->GetFieldDef()->mIsStatic)
@ -6466,24 +6505,45 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
if (refVal.IsAddr()) if (refVal.IsAddr())
{ {
constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_Int64); constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_IntPtr);
} }
} }
if (!constValue) if (!constValue)
constValue = mBfIRBuilder->CreateConst(BfTypeCode_Int64, fieldInstance->mDataOffset); constValue = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, fieldInstance->mDataOffset);
SizedArray<BfIRValue, 8> fieldVals = if (is32Bit)
{ {
emptyValueType, if (!constValue2)
fieldNameConst, // mName constValue2 = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, 0);
GetConstValue(typeId, typeIdType), // mFieldTypeId
constValue, // mConstValue SizedArray<BfIRValue, 8> fieldVals =
GetConstValue(fieldFlags, shortType), // mFlags {
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx emptyValueType,
}; fieldNameConst, // mName
auto fieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), fieldVals); GetConstValue(typeId, typeIdType), // mFieldTypeId
fieldTypes.push_back(fieldData); constValue, // mData
constValue2, // mDataHi
GetConstValue(fieldFlags, shortType), // mFlags
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
};
auto fieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), fieldVals);
fieldTypes.push_back(fieldData);
}
else
{
SizedArray<BfIRValue, 8> fieldVals =
{
emptyValueType,
fieldNameConst, // mName
GetConstValue(typeId, typeIdType), // mFieldTypeId
constValue, // mData
GetConstValue(fieldFlags, shortType), // mFlags
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
};
auto fieldData = mBfIRBuilder->CreateConstAgg_Value(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), fieldVals);
fieldTypes.push_back(fieldData);
}
} }
auto reflectFieldDataIRType = mBfIRBuilder->MapType(reflectFieldDataType); auto reflectFieldDataIRType = mBfIRBuilder->MapType(reflectFieldDataType);