1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 03:28:20 +02:00

More const eval progress

This commit is contained in:
Brian Fiete 2020-12-19 14:19:33 -08:00
parent a3ea79cd62
commit 9b80c26d0a
26 changed files with 1673 additions and 460 deletions

View file

@ -70,6 +70,11 @@ BeType* BeContext::GetPrimitiveType(BeTypeCode typeCode)
return primType;
}
BeType* BeContext::GetVoidPtrType()
{
return GetPointerTo(GetPrimitiveType(BeTypeCode_None));
}
BeStructType* BeContext::CreateStruct(const StringImpl& name)
{
BeStructType* structType = mTypes.Alloc<BeStructType>();

View file

@ -275,6 +275,7 @@ public:
public:
BeContext();
BeType* GetPrimitiveType(BeTypeCode typeCode);
BeType* GetVoidPtrType();
BeStructType* CreateStruct(const StringImpl& name);
BeStructType* CreateStruct(const SizedArrayImpl<BeType*>& types);
BePointerType* GetPointerTo(BeType* beType);

View file

@ -765,6 +765,22 @@ void BeIRCodeGen::Read(BeValue*& beValue)
BE_MEM_END("ParamType_Const_PtrToInt");
return;
}
else if (constType == BfConstType_IntToPtr)
{
CMD_PARAM(BeConstant*, target);
CMD_PARAM(BeType*, toType);
auto castedVal = mBeModule->mAlloc.Alloc<BeCastConstant>();
castedVal->mInt64 = target->mInt64;
castedVal->mType = toType;
castedVal->mTarget = target;
BF_ASSERT(target->GetType() != NULL);
BF_ASSERT(!target->GetType()->IsComposite());
BF_ASSERT(toType->IsPointer());
beValue = castedVal;
BE_MEM_END("ParamType_Const_IntToPtr");
return;
}
else if (constType == BfConstType_AggZero)
{
CMD_PARAM(BeType*, type);
@ -2545,6 +2561,17 @@ void BeIRCodeGen::HandleNextCmd()
SetResult(curId, inst);
}
break;
case BfIRCmd_ConstEval_GetReflectType:
{
CMD_PARAM(int32, typeId);
CMD_PARAM(BeType*, resultType);
auto inst = mBeModule->AllocInst<BeConstEvalGetReflectType>();
inst->mTypeId = typeId;
inst->mResultType = resultType;
SetResult(curId, inst);
}
break;
case BfIRCmd_ConstEval_DynamicCastCheck:
{
CMD_PARAM(BeValue*, value);
@ -2575,13 +2602,13 @@ void BeIRCodeGen::HandleNextCmd()
{
CMD_PARAM(BeValue*, value);
CMD_PARAM(int32, ifaceTypeId);
CMD_PARAM(int32, virtualTableIdx);
CMD_PARAM(int32, methodIdx);
CMD_PARAM(BeType*, resultType);
auto inst = mBeModule->AllocInst<BeConstEvalGetInterfaceFunc>();
inst->mValue = value;
inst->mIFaceTypeId = ifaceTypeId;
inst->mVirtualTableIdx = virtualTableIdx;
inst->mMethodIdx = methodIdx;
inst->mResultType = resultType;
SetResult(curId, inst);
}

View file

@ -1282,7 +1282,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo
str += StrFormat(" %d %d", constantGEP->mIdx0, constantGEP->mIdx1);
return;
}
if (auto constantExtract = BeValueDynCast<BeExtractValueConstant>(value))
{
str += "ConstExtract ";
@ -2450,9 +2450,10 @@ String BeModule::ToString(BeFunction* wantFunc)
}
break;
DISPLAY_INST1(BeConstEvalGetType, "ConstEvalGetType", mTypeId);
DISPLAY_INST1(BeConstEvalGetReflectType, "ConstEvalGetReflectType", mTypeId);
DISPLAY_INST2(BeConstEvalDynamicCastCheck, "ConstEvalDynamicCastCheck", mValue, mTypeId);
DISPLAY_INST2(BeConstEvalGetVirtualFunc, "ConstEvalGetVirtualFunc", mValue, mVirtualTableIdx);
DISPLAY_INST3(BeConstEvalGetInterfaceFunc, "ConstEvalGetInterfaceFunc", mValue, mIFaceTypeId, mVirtualTableIdx);
DISPLAY_INST3(BeConstEvalGetInterfaceFunc, "ConstEvalGetInterfaceFunc", mValue, mIFaceTypeId, mMethodIdx);
default:
BF_FATAL("Notimpl");
str += "<UNKNOWN INST>";

View file

@ -1361,6 +1361,28 @@ public:
}
};
class BeConstEvalGetReflectType : public BeInst
{
public:
BE_VALUE_TYPE(BeConstEvalGetReflectType, BeInst);
public:
int mTypeId;
BeType* mResultType;
public:
virtual BeType* GetType() override
{
return mResultType;
}
virtual void HashInst(BeHashContext& hashCtx) override
{
hashCtx.Mixin(TypeId);
hashCtx.Mixin(mTypeId);
}
};
class BeConstEvalDynamicCastCheck : public BeInst
{
public:
@ -1417,7 +1439,7 @@ public:
public:
BeValue* mValue;
int mIFaceTypeId;
int mVirtualTableIdx;
int mMethodIdx;
BeType* mResultType;
public:
@ -1431,7 +1453,7 @@ public:
hashCtx.Mixin(TypeId);
mValue->HashReference(hashCtx);
hashCtx.Mixin(mIFaceTypeId);
hashCtx.Mixin(mVirtualTableIdx);
hashCtx.Mixin(mMethodIdx);
}
};