mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Reflection fixes on Win32
This commit is contained in:
parent
6e6487d951
commit
4ac56a2432
6 changed files with 102 additions and 83 deletions
|
@ -607,7 +607,7 @@ namespace System.Reflection
|
|||
public struct FieldData
|
||||
{
|
||||
public String mName;
|
||||
public int64 mData;
|
||||
public int mData;
|
||||
public TypeId mFieldTypeId;
|
||||
public FieldFlags mFlags;
|
||||
public int32 mCustomAttributesIdx;
|
||||
|
|
|
@ -574,7 +574,7 @@ namespace System.Reflection
|
|||
public struct FieldData
|
||||
{
|
||||
public String mName;
|
||||
public int64 mData;
|
||||
public int mData;
|
||||
public TypeId mFieldTypeId;
|
||||
public FieldFlags mFlags;
|
||||
public int32 mCustomAttributesIdx;
|
||||
|
|
|
@ -1158,8 +1158,23 @@ void BeIRCodeGen::HandleNextCmd()
|
|||
{
|
||||
CMD_PARAM(BeValue*, val);
|
||||
CMD_PARAM(bool, valIsSigned);
|
||||
|
||||
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;
|
||||
auto toBeType = GetBeType(typeCode, toSigned);
|
||||
BeValue* retVal = mBeModule->CreateNumericCast(val, toBeType, valIsSigned, toSigned);
|
||||
|
|
|
@ -3544,75 +3544,77 @@ BfIRValue BfIRBuilder::CreateNumericCast(BfIRValue val, bool valIsSigned, BfType
|
|||
FixTypeCode(typeCode);
|
||||
if (val.IsConst())
|
||||
{
|
||||
auto constVal = GetConstantById(val.mId);
|
||||
|
||||
// ? -> Int
|
||||
if (IsInt(typeCode))
|
||||
auto constVal = GetConstantById(val.mId);
|
||||
if (constVal->mTypeCode < BfTypeCode_Length)
|
||||
{
|
||||
uint64 val = 0;
|
||||
|
||||
if ((typeCode == BfTypeCode_IntPtr) || (typeCode == BfTypeCode_UIntPtr))
|
||||
// ? -> Int
|
||||
if (IsInt(typeCode))
|
||||
{
|
||||
if (mModule->mSystem->mPtrSize == 4)
|
||||
typeCode = (typeCode == BfTypeCode_IntPtr) ? BfTypeCode_Int32 : BfTypeCode_UInt32;
|
||||
else
|
||||
typeCode = (typeCode == BfTypeCode_IntPtr) ? BfTypeCode_Int64 : BfTypeCode_UInt64;
|
||||
uint64 val = 0;
|
||||
|
||||
if ((typeCode == BfTypeCode_IntPtr) || (typeCode == BfTypeCode_UIntPtr))
|
||||
{
|
||||
if (mModule->mSystem->mPtrSize == 4)
|
||||
typeCode = (typeCode == BfTypeCode_IntPtr) ? BfTypeCode_Int32 : BfTypeCode_UInt32;
|
||||
else
|
||||
typeCode = (typeCode == BfTypeCode_IntPtr) ? BfTypeCode_Int64 : BfTypeCode_UInt64;
|
||||
}
|
||||
|
||||
// Int -> Int
|
||||
if (IsInt(constVal->mTypeCode))
|
||||
{
|
||||
switch (typeCode)
|
||||
{
|
||||
case BfTypeCode_Int8: val = (int8)constVal->mInt64; break;
|
||||
case BfTypeCode_Char8:
|
||||
case BfTypeCode_UInt8: val = (uint8)constVal->mInt64; break;
|
||||
case BfTypeCode_Int16: val = (int16)constVal->mInt64; break;
|
||||
case BfTypeCode_Char16:
|
||||
case BfTypeCode_UInt16: val = (uint16)constVal->mInt64; break;
|
||||
case BfTypeCode_Int32: val = (int32)constVal->mInt64; break;
|
||||
case BfTypeCode_Char32:
|
||||
case BfTypeCode_UInt32: val = (uint32)constVal->mInt64; break;
|
||||
case BfTypeCode_Int64: val = (uint64)(int64)constVal->mInt64; break;
|
||||
case BfTypeCode_UInt64: val = (uint64)constVal->mUInt64; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else // Float -> Int
|
||||
{
|
||||
switch (typeCode)
|
||||
{
|
||||
case BfTypeCode_Int8: val = (int8)constVal->mDouble; break;
|
||||
case BfTypeCode_Char8:
|
||||
case BfTypeCode_UInt8: val = (uint8)constVal->mDouble; break;
|
||||
case BfTypeCode_Int16: val = (int16)constVal->mDouble; break;
|
||||
case BfTypeCode_Char16:
|
||||
case BfTypeCode_UInt16: val = (uint16)constVal->mDouble; break;
|
||||
case BfTypeCode_Int32: val = (int32)constVal->mDouble; break;
|
||||
case BfTypeCode_Char32:
|
||||
case BfTypeCode_UInt32: val = (uint32)constVal->mDouble; break;
|
||||
case BfTypeCode_Int64: val = (uint64)(int64)constVal->mDouble; break;
|
||||
case BfTypeCode_UInt64: val = (uint64)constVal->mDouble; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return CreateConst(typeCode, val);
|
||||
}
|
||||
|
||||
// Int -> Int
|
||||
// Int -> Float
|
||||
if (IsInt(constVal->mTypeCode))
|
||||
{
|
||||
switch (typeCode)
|
||||
{
|
||||
case BfTypeCode_Int8: val = (int8)constVal->mInt64; break;
|
||||
case BfTypeCode_Char8:
|
||||
case BfTypeCode_UInt8: val = (uint8)constVal->mInt64; break;
|
||||
case BfTypeCode_Int16: val = (int16)constVal->mInt64; break;
|
||||
case BfTypeCode_Char16:
|
||||
case BfTypeCode_UInt16: val = (uint16)constVal->mInt64; break;
|
||||
case BfTypeCode_Int32: val = (int32)constVal->mInt64; break;
|
||||
case BfTypeCode_Char32:
|
||||
case BfTypeCode_UInt32: val = (uint32)constVal->mInt64; break;
|
||||
case BfTypeCode_Int64: val = (uint64)(int64)constVal->mInt64; break;
|
||||
case BfTypeCode_UInt64: val = (uint64)constVal->mUInt64; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else // Float -> Int
|
||||
{
|
||||
switch (typeCode)
|
||||
{
|
||||
case BfTypeCode_Int8: val = (int8)constVal->mDouble; break;
|
||||
case BfTypeCode_Char8:
|
||||
case BfTypeCode_UInt8: val = (uint8)constVal->mDouble; break;
|
||||
case BfTypeCode_Int16: val = (int16)constVal->mDouble; break;
|
||||
case BfTypeCode_Char16:
|
||||
case BfTypeCode_UInt16: val = (uint16)constVal->mDouble; break;
|
||||
case BfTypeCode_Int32: val = (int32)constVal->mDouble; break;
|
||||
case BfTypeCode_Char32:
|
||||
case BfTypeCode_UInt32: val = (uint32)constVal->mDouble; break;
|
||||
case BfTypeCode_Int64: val = (uint64)(int64)constVal->mDouble; break;
|
||||
case BfTypeCode_UInt64: val = (uint64)constVal->mDouble; break;
|
||||
default: break;
|
||||
}
|
||||
double val = 0;
|
||||
if (IsSigned(constVal->mTypeCode))
|
||||
val = (double)constVal->mInt64;
|
||||
else
|
||||
val = (double)constVal->mUInt64;
|
||||
return CreateConst(typeCode, val);
|
||||
}
|
||||
|
||||
return CreateConst(typeCode, val);
|
||||
// Float -> Float
|
||||
return CreateConst(typeCode, constVal->mDouble);
|
||||
}
|
||||
|
||||
// Int -> Float
|
||||
if (IsInt(constVal->mTypeCode))
|
||||
{
|
||||
double val = 0;
|
||||
if (IsSigned(constVal->mTypeCode))
|
||||
val = (double)constVal->mInt64;
|
||||
else
|
||||
val = (double)constVal->mUInt64;
|
||||
return CreateConst(typeCode, val);
|
||||
}
|
||||
|
||||
// Float -> Float
|
||||
return CreateConst(typeCode, constVal->mDouble);
|
||||
}
|
||||
|
||||
auto retVal = WriteCmd(BfIRCmd_NumericCast, val, valIsSigned, typeCode);
|
||||
|
|
|
@ -1296,7 +1296,11 @@ void BfIRCodeGen::HandleNextCmd()
|
|||
llvm::SmallVector<llvm::Constant*, 8> copyValues;
|
||||
FixValues((llvm::StructType*)type, 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));
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -4656,6 +4656,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
|
||||
BfType* longType = GetPrimitiveType(BfTypeCode_Int64);
|
||||
BfType* intType = GetPrimitiveType(BfTypeCode_Int32);
|
||||
BfType* intPtrType = GetPrimitiveType(BfTypeCode_IntPtr);
|
||||
BfType* shortType = GetPrimitiveType(BfTypeCode_Int16);
|
||||
BfType* byteType = GetPrimitiveType(BfTypeCode_Int8);
|
||||
|
||||
|
@ -5761,7 +5762,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
{
|
||||
emptyValueType,
|
||||
payloadNameConst, // mName
|
||||
GetConstValue(0, longType), // mData
|
||||
GetConstValue(0, intPtrType), // mData
|
||||
GetConstValue(payloadType->mTypeId, typeIdType), // mFieldTypeId
|
||||
GetConstValue(FieldFlags_SpecialName | FieldFlags_EnumPayload, shortType), // mFlags
|
||||
GetConstValue(-1, intType), // mCustomAttributesIdx
|
||||
|
@ -5776,7 +5777,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
{
|
||||
emptyValueType,
|
||||
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(FieldFlags_SpecialName | FieldFlags_EnumDiscriminator, shortType), // mFlags
|
||||
GetConstValue(-1, intType), // mCustomAttributesIdx
|
||||
|
@ -5816,13 +5817,13 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
fieldFlags = (FieldFlags)(fieldFlags | FieldFlags_Const);
|
||||
|
||||
int customAttrIdx = _HandleCustomAttrs(fieldInstance->mCustomAttributes);
|
||||
BfIRValue constValue;
|
||||
BfIRValue constValue;
|
||||
if (fieldInstance->GetFieldDef()->mIsConst)
|
||||
{
|
||||
if (fieldInstance->mConstIdx != -1)
|
||||
{
|
||||
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)
|
||||
|
@ -5830,28 +5831,25 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
auto refVal = ReferenceStaticField(fieldInstance);
|
||||
if (refVal.IsAddr())
|
||||
{
|
||||
constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_IntPtr);
|
||||
if (mSystem->mPtrSize != 8)
|
||||
constValue = mBfIRBuilder->CreateNumericCast(constValue, false, BfTypeCode_Int64);
|
||||
constValue = mBfIRBuilder->CreatePtrToInt(refVal.mValue, BfTypeCode_IntPtr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!constValue)
|
||||
{
|
||||
constValue = GetConstValue(fieldInstance->mDataOffset, longType);
|
||||
}
|
||||
constValue = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, fieldInstance->mDataOffset);
|
||||
|
||||
|
||||
SizedArray<BfIRValue, 8> fieldVals =
|
||||
{
|
||||
emptyValueType,
|
||||
fieldNameConst, // mName
|
||||
constValue, // mConstValue
|
||||
GetConstValue(typeId, typeIdType), // mFieldTypeId
|
||||
GetConstValue(fieldFlags, shortType), // mFlags
|
||||
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
|
||||
};
|
||||
{
|
||||
emptyValueType,
|
||||
fieldNameConst, // mName
|
||||
constValue, // mConstValue
|
||||
GetConstValue(typeId, typeIdType), // mFieldTypeId
|
||||
GetConstValue(fieldFlags, shortType), // mFlags
|
||||
GetConstValue(customAttrIdx, intType), // mCustomAttributesIdx
|
||||
};
|
||||
auto fieldData = mBfIRBuilder->CreateConstStruct(mBfIRBuilder->MapTypeInst(reflectFieldDataType->ToTypeInstance(), BfIRPopulateType_Full), fieldVals);
|
||||
fieldTypes.push_back(fieldData);
|
||||
fieldTypes.push_back(fieldData);
|
||||
}
|
||||
|
||||
auto reflectFieldDataIRType = mBfIRBuilder->MapType(reflectFieldDataType);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue