MCPcopy Create free account
hub / github.com/beefytech/Beef / FlushNullConditional

Method FlushNullConditional

IDEHelper/Compiler/BfModule.cpp:9260–9345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9258static int sValueFromExprIdx = 0;
9259
9260BfTypedValue BfModule::FlushNullConditional(BfTypedValue result, bool ignoreNullable)
9261{
9262 auto pendingNullCond = mCurMethodState->mPendingNullConditional;
9263
9264 if ((result) && (!result.mType->IsVar()) && (!ignoreNullable))
9265 {
9266 auto notNullBB = mBfIRBuilder->GetInsertBlock();
9267
9268 //TODO: Make this work, needed for 'void' and such
9269 BfType* nullableType = NULL;
9270 if ((result.mType->IsValueType()) && (!result.mType->IsNullable()))
9271 {
9272 BfTypeVector typeVec;
9273 typeVec.push_back(result.mType);
9274 nullableType = ResolveTypeDef(mCompiler->mNullableTypeDef, typeVec);
9275 BF_ASSERT(nullableType != NULL);
9276 }
9277
9278 // Go back to start and do any setup we need
9279 mBfIRBuilder->SetInsertPoint(pendingNullCond->mPrevBB);
9280 BfTypedValue nullableTypedValue;
9281 if (nullableType != NULL)
9282 {
9283 nullableTypedValue = BfTypedValue(CreateAlloca(nullableType, true, "nullCond.nullable"), nullableType, true);
9284 mBfIRBuilder->CreateMemSet(nullableTypedValue.mValue, GetConstValue(0, GetPrimitiveType(BfTypeCode_Int8)),
9285 GetConstValue(nullableType->mSize), nullableType->mAlign);
9286 }
9287 mBfIRBuilder->CreateBr(pendingNullCond->mCheckBB);
9288
9289 // Now that we have the nullableTypedValue we can set that, or just jump if we didn't need it
9290 mBfIRBuilder->SetInsertPoint(notNullBB);
9291 result = LoadValue(result);
9292 if (nullableTypedValue)
9293 {
9294 auto elementType = nullableType->GetUnderlyingType();
9295 if (elementType->IsVar())
9296 {
9297 // Do nothing
9298 }
9299 else if (elementType->IsValuelessType())
9300 {
9301 BfIRValue ptrValue = mBfIRBuilder->CreateInBoundsGEP(nullableTypedValue.mValue, 0, 1); // mHasValue
9302 mBfIRBuilder->CreateStore(GetConstValue(1, GetPrimitiveType(BfTypeCode_Boolean)), ptrValue);
9303 }
9304 else
9305 {
9306 BfIRValue ptrValue = mBfIRBuilder->CreateInBoundsGEP(nullableTypedValue.mValue, 0, 1); // mValue
9307 mBfIRBuilder->CreateAlignedStore(result.mValue, ptrValue, result.mType->mAlign);
9308 ptrValue = mBfIRBuilder->CreateInBoundsGEP(nullableTypedValue.mValue, 0, 2); // mHasValue
9309 mBfIRBuilder->CreateAlignedStore(GetConstValue(1, GetPrimitiveType(BfTypeCode_Boolean)), ptrValue, 1);
9310 }
9311 result = nullableTypedValue;
9312 }
9313 mBfIRBuilder->CreateBr(pendingNullCond->mDoneBB);
9314
9315 AddBasicBlock(pendingNullCond->mDoneBB);
9316 if (nullableType == NULL)
9317 {

Callers 1

EvaluateMethod · 0.80

Calls 15

BfTypedValueClass · 0.85
CreateInBoundsGEPMethod · 0.80
CreatePhiMethod · 0.80
MapTypeMethod · 0.80
AddPhiIncomingMethod · 0.80
IsVarMethod · 0.45
GetInsertBlockMethod · 0.45
IsValueTypeMethod · 0.45
IsNullableMethod · 0.45
push_backMethod · 0.45
SetInsertPointMethod · 0.45
CreateMemSetMethod · 0.45

Tested by

no test coverage detected