| 8259 | } |
| 8260 | |
| 8261 | BfIRFunction BfModule::GetIntrinsic(BfMethodInstance* methodInstance, bool reportFailure) |
| 8262 | { |
| 8263 | if (!methodInstance->mIsIntrinsic) |
| 8264 | return BfIRFunction(); |
| 8265 | |
| 8266 | auto methodOwner = methodInstance->GetOwner(); |
| 8267 | auto methodDef = methodInstance->mMethodDef; |
| 8268 | auto methodDeclaration = methodDef->GetMethodDeclaration(); |
| 8269 | |
| 8270 | if (!methodDef->mIsExtern) |
| 8271 | return BfIRFunction(); |
| 8272 | |
| 8273 | if (methodInstance->GetCustomAttributes() == NULL) |
| 8274 | return BfIRFunction(); |
| 8275 | |
| 8276 | auto customAttribute = methodInstance->GetCustomAttributes()->Get(mCompiler->mIntrinsicAttributeTypeDef); |
| 8277 | auto constant = methodOwner->mConstHolder->GetConstant(customAttribute->mCtorArgs[0]); |
| 8278 | String error; |
| 8279 | |
| 8280 | if ((constant != NULL) && (constant->mTypeCode == BfTypeCode_StringId)) |
| 8281 | { |
| 8282 | int stringId = constant->mInt32; |
| 8283 | auto entry = mContext->mStringObjectIdMap[stringId]; |
| 8284 | String intrinName = entry.mString; |
| 8285 | |
| 8286 | int intrinId = BfIRCodeGen::GetIntrinsicId(intrinName); |
| 8287 | if (intrinId != -1) |
| 8288 | { |
| 8289 | if (intrinId == BfIRIntrinsic_Malloc) |
| 8290 | { |
| 8291 | return GetBuiltInFunc(BfBuiltInFuncType_Malloc); |
| 8292 | } |
| 8293 | else if (intrinId == BfIRIntrinsic_Free) |
| 8294 | { |
| 8295 | return GetBuiltInFunc(BfBuiltInFuncType_Free); |
| 8296 | } |
| 8297 | |
| 8298 | SizedArray<BfIRType, 2> paramTypes; |
| 8299 | for (auto& param : methodInstance->mParams) |
| 8300 | paramTypes.push_back(mBfIRBuilder->MapType(param.mResolvedType)); |
| 8301 | return mBfIRBuilder->GetIntrinsic(intrinName, intrinId, mBfIRBuilder->MapType(methodInstance->mReturnType), paramTypes); |
| 8302 | } |
| 8303 | else if (reportFailure) |
| 8304 | error = StrFormat("Unable to find intrinsic '%s'", entry.mString.c_str()); |
| 8305 | } |
| 8306 | else if (reportFailure) |
| 8307 | error = "Intrinsic name must be a constant string"; |
| 8308 | |
| 8309 | if (reportFailure) |
| 8310 | { |
| 8311 | Fail(error, customAttribute->mRef); |
| 8312 | } |
| 8313 | |
| 8314 | return BfIRFunction(); |
| 8315 | } |
| 8316 | |
| 8317 | BfIRFunction BfModule::GetBuiltInFunc(BfBuiltInFuncType funcTypeId) |
| 8318 | { |
nothing calls this directly
no test coverage detected