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

Reflection fixes on Win32

This commit is contained in:
Brian Fiete 2020-07-06 17:58:46 -07:00
parent 6e6487d951
commit 4ac56a2432
6 changed files with 102 additions and 83 deletions

View file

@ -607,7 +607,7 @@ namespace System.Reflection
public struct FieldData public struct FieldData
{ {
public String mName; public String mName;
public int64 mData; public int mData;
public TypeId mFieldTypeId; public TypeId mFieldTypeId;
public FieldFlags mFlags; public FieldFlags mFlags;
public int32 mCustomAttributesIdx; public int32 mCustomAttributesIdx;

View file

@ -574,7 +574,7 @@ namespace System.Reflection
public struct FieldData public struct FieldData
{ {
public String mName; public String mName;
public int64 mData; public int mData;
public TypeId mFieldTypeId; public TypeId mFieldTypeId;
public FieldFlags mFlags; public FieldFlags mFlags;
public int32 mCustomAttributesIdx; public int32 mCustomAttributesIdx;

View file

@ -1158,8 +1158,23 @@ void BeIRCodeGen::HandleNextCmd()
{ {
CMD_PARAM(BeValue*, val); CMD_PARAM(BeValue*, val);
CMD_PARAM(bool, valIsSigned); CMD_PARAM(bool, valIsSigned);
BfTypeCode typeCode = (BfTypeCode)mStream->Read(); BfTypeCode typeCode = (BfTypeCode)mStream->Read();
BfTypeCode valTypeCode = GetTypeCode(val->GetType(), valIsSigned); BfTypeCode valTypeCode = GetTypeCode(val->GetType(), valIsSigned);
if (auto srcCastConstant = BeValueDynCast<BeCastConstant>(val))
{
BeType* toType = GetBeType(typeCode, valIsSigned);
auto castedVal = mBeModule->mAlloc.Alloc<BeCastConstant>();
castedVal->mInt64 = srcCastConstant->mInt64;
castedVal->mType = toType;
castedVal->mTarget = srcCastConstant->mTarget;
SetResult(curId, castedVal);
break;
}
bool toSigned = false; bool toSigned = false;
auto toBeType = GetBeType(typeCode, toSigned); auto toBeType = GetBeType(typeCode, toSigned);
BeValue* retVal = mBeModule->CreateNumericCast(val, toBeType, valIsSigned, toSigned); BeValue* retVal = mBeModule->CreateNumericCast(val, toBeType, valIsSigned, toSigned);

View file

@ -3545,7 +3545,8 @@ BfIRValue BfIRBuilder::CreateNumericCast(BfIRValue val, bool valIsSigned, BfType
if (val.IsConst()) if (val.IsConst())
{ {
auto constVal = GetConstantById(val.mId); auto constVal = GetConstantById(val.mId);
if (constVal->mTypeCode < BfTypeCode_Length)
{
// ? -> Int // ? -> Int
if (IsInt(typeCode)) if (IsInt(typeCode))
{ {
@ -3614,6 +3615,7 @@ BfIRValue BfIRBuilder::CreateNumericCast(BfIRValue val, bool valIsSigned, BfType
// Float -> Float // Float -> Float
return CreateConst(typeCode, constVal->mDouble); return CreateConst(typeCode, constVal->mDouble);
} }
}
auto retVal = WriteCmd(BfIRCmd_NumericCast, val, valIsSigned, typeCode); auto retVal = WriteCmd(BfIRCmd_NumericCast, val, valIsSigned, typeCode);
NEW_CMD_INSERTED_IRVALUE; NEW_CMD_INSERTED_IRVALUE;

View file

@ -1296,7 +1296,11 @@ void BfIRCodeGen::HandleNextCmd()
llvm::SmallVector<llvm::Constant*, 8> copyValues; llvm::SmallVector<llvm::Constant*, 8> copyValues;
FixValues((llvm::StructType*)type, values); FixValues((llvm::StructType*)type, values);
for (auto val : values) for (auto val : values)
copyValues.push_back(llvm::dyn_cast<llvm::Constant>(val)); {
auto constValue = llvm::dyn_cast<llvm::Constant>(val);
BF_ASSERT(constValue != NULL);
copyValues.push_back(constValue);
}
SetResult(curId, llvm::ConstantStruct::get((llvm::StructType*)type, copyValues)); SetResult(curId, llvm::ConstantStruct::get((llvm::StructType*)type, copyValues));
} }
break; break;

View file

@ -4656,6 +4656,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
BfType* longType = GetPrimitiveType(BfTypeCode_Int64); BfType* longType = GetPrimitiveType(BfTypeCode_Int64);
BfType* intType = GetPrimitiveType(BfTypeCode_Int32); BfType* intType = GetPrimitiveType(BfTypeCode_Int32);
BfType* intPtrType = GetPrimitiveType(BfTypeCode_IntPtr);
BfType* shortType = GetPrimitiveType(BfTypeCode_Int16); BfType* shortType = GetPrimitiveType(BfTypeCode_Int16);
BfType* byteType = GetPrimitiveType(BfTypeCode_Int8); BfType* byteType = GetPrimitiveType(BfTypeCode_Int8);
@ -5761,7 +5762,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
{ {
emptyValueType, emptyValueType,
payloadNameConst, // mName payloadNameConst, // mName
GetConstValue(0, longType), // mData GetConstValue(0, intPtrType), // mData
GetConstValue(payloadType->mTypeId, typeIdType), // mFieldTypeId GetConstValue(payloadType->mTypeId, typeIdType), // mFieldTypeId
GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumPayload, shortType), // mFlags GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumPayload, shortType), // mFlags
GetConstValue(-1, intType), // mCustomAttributesIdx GetConstValue(-1, intType), // mCustomAttributesIdx
@ -5776,7 +5777,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
{ {
emptyValueType, emptyValueType,
dscrNameConst, // mName dscrNameConst, // mName
GetConstValue(BF_ALIGN(payloadType->mSize, dscrType->mAlign), longType), // mData GetConstValue(BF_ALIGN(payloadType->mSize, dscrType->mAlign), intPtrType), // mData
GetConstValue(dscrType->mTypeId, typeIdType), // mFieldTypeId GetConstValue(dscrType->mTypeId, typeIdType), // mFieldTypeId
GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumDiscriminator, shortType), // mFlags GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumDiscriminator, shortType), // mFlags
GetConstValue(-1, intType), // mCustomAttributesIdx GetConstValue(-1, intType), // mCustomAttributesIdx
@ -5822,7 +5823,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
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_UInt64, constant->mUInt64); constValue = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, constant->mUInt64);
} }
} }
else if (fieldInstance->GetFieldDef()->mIsStatic) else if (fieldInstance->GetFieldDef()->mIsStatic)
@ -5831,15 +5832,12 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
if (refVal.IsAddr()) if (refVal.IsAddr())
{ {
constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_IntPtr); constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_IntPtr);
if (mSystem->mPtrSize != 8)
constValue = mBfIRBuilder->CreateNumericCast(constValue, false, BfTypeCode_Int64);
} }
} }
if (!constValue) if (!constValue)
{ constValue = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, fieldInstance->mDataOffset);
constValue = GetConstValue(fieldInstance->mDataOffset, longType);
}
SizedArray<BfIRValue, 8> fieldVals = SizedArray<BfIRValue, 8> fieldVals =
{ {