Repository: dotnet/runtime
File: src/coreclr/jit/emitwasm.cpp (C++)

Code before:

    printf("      ");

    instruction ins = id->idIns();
    insFormat   fmt = id->idInsFmt();

    emitDispInst(ins);

    auto dispJumpTargetIfAny = [this, id]() {
        if (m_debugInfoSize > 0)
        {
            BasicBlock* const targetBlock = id->idDebugOnlyInfo()->idTargetBlock;
            if (targetBlock != nullptr)
            {
                printf(" ;; ");
                insGroup* const targetGroup = (insGroup*)emitCodeGetCookie(targetBlock);
                assert(targetGroup != nullptr);
                emitPrintLabel(targetGroup);
            }
        }
    };

    auto dispTargetOfCallIfAny = [this, id]() {
        if (m_debugInfoSize > 0)
        {
            const void* const methodToken = (const void*)id->idDebugOnlyInfo()->idMemCookie;
            if (methodToken != nullptr)
            {
                printf(" ;; ");
                const char* const methodName =
                    m_compiler->eeGetMethodFullName((CORINFO_METHOD_HANDLE)id->idDebugOnlyInfo()->idMemCookie);
                printf("%s", methodName);
            }
        }
    };

    // The reference for the following style of display is wasm-objdump output.
    //
    switch (fmt)
    {
        case IF_OPCODE:
        case IF_BLOCK:
            break;

        case IF_RAW_ULEB128:
        case IF_ULEB128:
        {
            cnsval_ssize_t imm = emitGetInsSC(id);
            printf(" %llu", (uint64_t)imm);
            dispJumpTargetIfAny();
            dispTargetOfCallIfAny();

Review comment (bug):
`idMemCookier` is also used in a more generic fashion (for all kinds of handles). We could hook into that by setting the appropriate `idFlags` on the debug info (for calls only, for now) and calling `emitDispCommentForHandle` (for all instructions).

(`emitDispCommentForHandle` will also need a slight tweak to use the right comment prefix)

Code after:
    emitDispInsHex(id, pCodeRW, sz);

    printf("      ");

    instruction ins = id->idIns();
    insFormat   fmt = id->idInsFmt();

    emitDispInst(ins);

    auto dispJumpTargetIfAny = [this, id]() {
        if (m_debugInfoSize > 0)
        {
            BasicBlock* const targetBlock = id->idDebugOnlyInfo()->idTargetBlock;
            if (targetBlock != nullptr)
            {
                printf("      ;;");
                insGroup* const targetGroup = (insGroup*)emitCodeGetCookie(targetBlock);
                assert(targetGroup != nullptr);
                emitPrintLabel(targetGroup);
            }
        }
    };

    auto dispHandleIfAny = [this, id]() {
        if (m_debugInfoSize > 0)
        {
            emitDispCommentForHandle(id->idDebugOnlyInfo()->idMemCookie, 0, id->idDebugOnlyInfo()->idFlags);
        }
    };

    // The reference for the following style of display is wasm-objdump output.
    //
    switch (fmt)
    {
        case IF_OPCODE:
        case IF_BLOCK:
            break;

        case IF_RAW_ULEB128:
        case IF_ULEB128:
        {
            cnsval_ssize_t imm = emitGetInsSC(id);
            printf(" %llu", (uint64_t)imm);
            dispJumpTargetIfAny();
            dispHandleIfAny();
        }
        break;

        case IF_CALL_INDIRECT:
        {
            cnsval_ssize_t imm = emitGetInsSC(id);