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

Code before:
                emitPrintLabel(targetGroup);
            }
        }
    };

    // 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();
        }
        break;

        case IF_CALL_INDIRECT:
        {
            cnsval_ssize_t imm = emitGetInsSC(id);
            printf(" 0 %llu", (uint64_t)imm);
        }
        break;

        case IF_LOCAL_DECL:
        {
            unsigned int  count   = emitGetLclVarDeclCount(id);
            WasmValueType valType = emitGetLclVarDeclType(id);
            assert(count > 0); // we should not be declaring a local entry with zero count

            if (m_debugInfoSize > 0)
            {
                // With debug info: print the local offsets being declared
                int offs = id->idDebugOnlyInfo()->lclOffset;
                if (count > 1)
                {
                    printf("[%u..%u] type=%s", offs, offs + count - 1, WasmValueTypeName(valType));
                }
                else // single local case
                {
                    printf("[%u] type=%s", offs, WasmValueTypeName(valType));
                }
            }
            else
            {
                // No debug info case: just print the count and type of the locals

Review comment (suggestion):
The display format for IF_CALL_INDIRECT at line 720 shows "0 %llu" (table index, then type index), but the actual encoding at lines 539-541 outputs the type index first, then the table index. According to the WebAssembly specification, call_indirect should be encoded as: opcode, type_idx, table_idx. The encoding order is correct, but the display format should be updated to match: "printf(" %llu 0", (uint64_t)imm);" to show type index followed by table index.
```suggestion
            printf(" %llu 0", (uint64_t)imm);
```

Code after:
        {
            unsigned int  count   = emitGetLclVarDeclCount(id);
            WasmValueType valType = emitGetLclVarDeclType(id);
            assert(count > 0); // we should not be declaring a local entry with zero count

            if (m_debugInfoSize > 0)
            {
                // With debug info: print the local offsets being declared
                int offs = id->idDebugOnlyInfo()->lclOffset;
                if (count > 1)
                {
                    printf("[%u..%u] type=%s", offs, offs + count - 1, WasmValueTypeName(valType));
                }
                else // single local case
                {
                    printf("[%u] type=%s", offs, WasmValueTypeName(valType));
                }
            }
            else
            {
                // No debug info case: just print the count and type of the locals
                printf(" count=%u type=%s", count, WasmValueTypeName(valType));
            }
        }
        break;

        case IF_SLEB128:
        {
            cnsval_ssize_t imm = emitGetInsSC(id);
            printf(" %lli", (int64_t)imm);
        }
        break;

        case IF_F32:
        case IF_F64:
        {
            cnsval_ssize_t bits = emitGetInsSC(id);
            double         value;
            memcpy(&value, &bits, sizeof(double));
            printf(" %f", value);
        }
        break;

        case IF_MEMARG:
        {
            unsigned       log2align = emitGetAlignHintLog2(id);
            cnsval_ssize_t offset    = emitGetInsSC(id);
            printf(" %u %llu", log2align, (uint64_t)offset);
        }
        break;