Repository: dotnet/runtime
File: src/coreclr/interpreter/compiler.cpp (C++)

Code before:
            m_currentContinuationContextHandling = ContinuationContextHandling::ContinueOnThreadPool;
            break;
        case CEE_LDC_I4_1:
            m_currentContinuationContextHandling = ContinuationContextHandling::ContinueOnCapturedContext;
            break;
        default:
            return false;
    }

    CORINFO_RESOLVED_TOKEN configureAwaitResolvedToken;
    ResolveToken(getU4LittleEndian(ip + pattern[0].offsetIntoPeep + 1), CORINFO_TOKENKIND_Method, &configureAwaitResolvedToken);
    if (!m_compHnd->isIntrinsic(configureAwaitResolvedToken.hMethod) ||
        GetNamedIntrinsic(m_compHnd, m_methodHnd, configureAwaitResolvedToken.hMethod) != NI_System_Threading_Tasks_Task_ConfigureAwait)
    {
        return false;
    }

    CORINFO_RESOLVED_TOKEN awaitResolvedToken;
    ResolveToken(getU4LittleEndian(ip + pattern[1].offsetIntoPeep + 1), CORINFO_TOKENKIND_Method, &awaitResolvedToken);
    if (!m_compHnd->isIntrinsic(awaitResolvedToken.hMethod) ||
        GetNamedIntrinsic(m_compHnd, m_methodHnd, awaitResolvedToken.hMethod) != NI_System_Runtime_CompilerServices_AsyncHelpers_Await)
    {
        return false;
    }

    CorInfoTokenKind tokenKind =
        ip[0] == CEE_CALL ? CORINFO_TOKENKIND_Await : CORINFO_TOKENKIND_AwaitVirtual;
    ResolveToken(getU4LittleEndian(ip + 1), tokenKind, &m_resolvedAsyncCallToken);
    if (m_resolvedAsyncCallToken.hMethod == NULL)
    {
        return false;
    }
    return true;
}

int InterpCompiler::ApplyConvRUnR4Peep(const uint8_t* ip, OpcodePeepElement* peep, void* computedInfo)
{
    // Replace with CONV_R4_UN
    CHECK_STACK(1);
    m_pStackPointer[-1].BashStackTypeToI_ForConvert();
    switch (m_pStackPointer[-1].GetStackType())
    {
    case StackTypeR4:
        break;
    case StackTypeR8:
        EmitConv(m_pStackPointer - 1, StackTypeR4, INTOP_CONV_R4_R8);
        break;
    case StackTypeI8:
        EmitConv(m_pStackPointer - 1, StackTypeR4, INTOP_CONV_R4_UN_I8);
        break;
    case StackTypeI4:

Review comment (refactor):
A nit - can you please create a helper function for async call token resolving instead of repeating the same piece of code multiple times?

Code after:
    CORINFO_RESOLVED_TOKEN configureAwaitResolvedToken;
    ResolveToken(getU4LittleEndian(ip + pattern[0].offsetIntoPeep + 1), CORINFO_TOKENKIND_Method, &configureAwaitResolvedToken);
    if (!m_compHnd->isIntrinsic(configureAwaitResolvedToken.hMethod) ||
        GetNamedIntrinsic(m_compHnd, m_methodHnd, configureAwaitResolvedToken.hMethod) != NI_System_Threading_Tasks_Task_ConfigureAwait)
    {
        return false;
    }

    CORINFO_RESOLVED_TOKEN awaitResolvedToken;
    ResolveToken(getU4LittleEndian(ip + pattern[1].offsetIntoPeep + 1), CORINFO_TOKENKIND_Method, &awaitResolvedToken);
    if (!m_compHnd->isIntrinsic(awaitResolvedToken.hMethod) ||
        GetNamedIntrinsic(m_compHnd, m_methodHnd, awaitResolvedToken.hMethod) != NI_System_Runtime_CompilerServices_AsyncHelpers_Await)
    {
        return false;
    }

    return ResolveAsyncCallToken(ip);
}

int InterpCompiler::ApplyConvRUnR4Peep(const uint8_t* ip, OpcodePeepElement* peep, void* computedInfo)
{
    // Replace with CONV_R4_UN
    CHECK_STACK(1);
    m_pStackPointer[-1].BashStackTypeToI_ForConvert();
    switch (m_pStackPointer[-1].GetStackType())
    {
    case StackTypeR4:
        break;
    case StackTypeR8:
        EmitConv(m_pStackPointer - 1, StackTypeR4, INTOP_CONV_R4_R8);
        break;
    case StackTypeI8:
        EmitConv(m_pStackPointer - 1, StackTypeR4, INTOP_CONV_R4_UN_I8);
        break;
    case StackTypeI4:
        EmitConv(m_pStackPointer - 1, StackTypeR4, INTOP_CONV_R4_UN_I4);
        break;
    default:
        BADCODE("conv.r.un operand must be R4, R8, I4 or I8");
        break;
    }

    return -1;
}

bool InterpCompiler::FindAndApplyPeep(OpcodePeep* Peeps[])
{
    const uint8_t* ip = m_ip;

    for (int i = 0; Peeps[i] != NULL; i++)
    {