Clear memory, set classVData, call init. Actual ctor is called elsewhere.
| 9570 | |
| 9571 | // Clear memory, set classVData, call init. Actual ctor is called elsewhere. |
| 9572 | void BfModule::InitTypeInst(BfTypedValue typedValue, BfScopeData* scopeData, bool zeroMemory, BfIRValue sizeValue, BfAllocFlags allocFlags) |
| 9573 | { |
| 9574 | auto typeInstance = typedValue.mType->ToTypeInstance(); |
| 9575 | if (zeroMemory) |
| 9576 | { |
| 9577 | int zeroAlign = typedValue.mType->mAlign; |
| 9578 | if (typeInstance != NULL) |
| 9579 | zeroAlign = typeInstance->mInstAlign; |
| 9580 | mBfIRBuilder->CreateMemSet(typedValue.mValue, GetConstValue8(0), sizeValue, zeroAlign); |
| 9581 | } |
| 9582 | |
| 9583 | if (!typedValue.mType->IsObject()) |
| 9584 | { |
| 9585 | return; |
| 9586 | } |
| 9587 | |
| 9588 | if ((scopeData == NULL) && (mCurMethodState != NULL)) |
| 9589 | return; // Handled in heap alloc funcs |
| 9590 | |
| 9591 | auto typeDef = typeInstance->mTypeDef; |
| 9592 | |
| 9593 | mBfIRBuilder->PopulateType(typedValue.mType); |
| 9594 | auto vObjectAddr = mBfIRBuilder->CreateInBoundsGEP(typedValue.mValue, 0, 0); |
| 9595 | bool isAutocomplete = mCompiler->IsAutocomplete(); |
| 9596 | |
| 9597 | BfIRValue vDataRef; |
| 9598 | if (!isAutocomplete) |
| 9599 | { |
| 9600 | vDataRef = GetClassVDataPtr(typeInstance); |
| 9601 | } |
| 9602 | |
| 9603 | auto i8Type = GetPrimitiveType(BfTypeCode_Int8); |
| 9604 | auto ptrType = CreatePointerType(i8Type); |
| 9605 | auto ptrPtrType = CreatePointerType(ptrType); |
| 9606 | |
| 9607 | PopulateType(ptrPtrType, BfPopulateType_Declaration); |
| 9608 | PopulateType(ptrType, BfPopulateType_Declaration); |
| 9609 | auto destAddr = mBfIRBuilder->CreateBitCast(vObjectAddr, mBfIRBuilder->MapType(ptrPtrType)); |
| 9610 | if (!isAutocomplete) |
| 9611 | { |
| 9612 | if ((mCompiler->mOptions.mObjectHasDebugFlags) && (!mIsComptimeModule)) |
| 9613 | { |
| 9614 | auto objectPtr = mBfIRBuilder->CreateBitCast(destAddr, mBfIRBuilder->MapType(mContext->mBfObjectType)); |
| 9615 | |
| 9616 | SizedArray<BfIRValue, 4> llvmArgs; |
| 9617 | llvmArgs.push_back(objectPtr); |
| 9618 | llvmArgs.push_back(vDataRef); |
| 9619 | llvmArgs.push_back(sizeValue); |
| 9620 | llvmArgs.push_back(mBfIRBuilder->CreateConst(BfTypeCode_Int8, allocFlags)); |
| 9621 | |
| 9622 | auto objectStackInitMethod = GetInternalMethod("Dbg_ObjectStackInit"); |
| 9623 | if (objectStackInitMethod) |
| 9624 | mBfIRBuilder->CreateCall(objectStackInitMethod.mFunc, llvmArgs); |
| 9625 | } |
| 9626 | else |
| 9627 | { |
| 9628 | auto srcVal = mBfIRBuilder->CreateBitCast(vDataRef, mBfIRBuilder->MapType(ptrType)); |
| 9629 | auto objectPtr = mBfIRBuilder->CreateBitCast(destAddr, mBfIRBuilder->MapType(ptrType)); |
no test coverage detected