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

Fixed issues with global var addresses in const arrays

This commit is contained in:
Brian Fiete 2020-07-13 08:51:02 -07:00
parent 52af512b4f
commit b30a72719c
13 changed files with 376 additions and 36 deletions

View file

@ -445,25 +445,25 @@ BeType* BeConstant::GetType()
return mType;
}
void BeConstant::GetData(Array<uint8>& data)
void BeConstant::GetData(BeConstData& data)
{
auto type = GetType();
while ((((int)data.size()) % type->mAlign) != 0)
data.push_back(0);
while ((((int)data.mData.size()) % type->mAlign) != 0)
data.mData.push_back(0);
if (type->IsComposite())
{
for (int i = 0; i < type->mSize; i++)
data.push_back(0); // Aggregate
data.mData.push_back(0); // Aggregate
}
else if (type->mTypeCode == BeTypeCode_Float)
{
float f = mDouble;
data.Insert(data.mSize, (uint8*)&f, sizeof(float));
data.mData.Insert(data.mData.mSize, (uint8*)&f, sizeof(float));
}
else
{
data.Insert(data.mSize, &mUInt8, type->mSize);
data.mData.Insert(data.mData.mSize, &mUInt8, type->mSize);
}
}
@ -491,7 +491,7 @@ void BeConstant::HashContent(BeHashContext& hashCtx)
BF_FATAL("NotImpl");
}
void BeStructConstant::GetData(Array<uint8>& data)
void BeStructConstant::GetData(BeConstData& data)
{
for (auto val : mMemberValues)
val->GetData(data);
@ -519,6 +519,27 @@ BeType* BeGEPConstant::GetType()
}
}
BeType* BeExtractValueConstant::GetType()
{
BeType* type = mTarget->GetType();
if (type->mTypeCode == BeTypeCode_SizedArray)
{
BeSizedArrayType* arrayType = (BeSizedArrayType*)type;
BF_ASSERT(arrayType->mTypeCode == BeTypeCode_SizedArray);
return arrayType->mContext->GetPointerTo(arrayType->mElementType);
}
/*else if (ptrType->mElementType->IsPointer())
{
return ptrType->mElementType;
}*/
else
{
BeStructType* structType = (BeStructType*)type;
BF_ASSERT(structType->mTypeCode == BeTypeCode_Struct);
return structType->mContext->GetPointerTo(structType->mMembers[mIdx0].mType);
}
}
BeType* BeGlobalVariable::GetType()
{
//if (mIsConstant)
@ -1240,6 +1261,14 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
return;
}
if (auto constantExtract = BeValueDynCast<BeExtractValueConstant>(value))
{
str += "ConstExtract ";
ToString(str, constantExtract->mTarget);
str += StrFormat(" %d", constantExtract->mIdx0);
return;
}
if (auto arg = BeValueDynCast<BeArgument>(value))
{
auto activeFunction = arg->mModule->mActiveFunction;
@ -1313,6 +1342,15 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
return;
}
if (auto constant = BeValueDynCast<BeExtractValueConstant>(value))
{
ToString(str, constant->GetType());
str += " extract (";
ToString(str, constant->mTarget);
str += StrFormat(", %d)", constant->mIdx0);
return;
}
if (auto constant = BeValueDynCast<BeStructConstant>(value))
{
ToString(str, constant->GetType());