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

Code before:
        case IF_OPCODE:
            break;
        case IF_BLOCK:
            size += 1;
            break;
        case IF_RAW_ULEB128:
            assert(!idIsCnsReloc());
            size = SizeOfULEB128(emitGetInsSC(this));
            break;
        case IF_LOCAL_DECL:
        {
            assert(idIsLclVarDecl());
            uint8_t typeCode = GetWasmValueTypeCode(emitGetLclVarDeclType(this));
            size             = SizeOfULEB128(emitGetLclVarDeclCount(this)) + sizeof(typeCode);
            break;
        }
        case IF_ULEB128:
            size += idIsCnsReloc() ? PADDED_RELOC_SIZE : SizeOfULEB128(emitGetInsSC(this));
            break;
        case IF_SLEB128:
            size += idIsCnsReloc() ? PADDED_RELOC_SIZE : SizeOfSLEB128(emitGetInsSC(this));
            break;
        case IF_CALL_INDIRECT:
        {
            size += SizeOfULEB128(0);
            size += SizeOfULEB128(emitGetInsSC(this));
            break;
        }
        case IF_F32:
            size += 4;
            break;
        case IF_F64:
            size += 8;
            break;
        case IF_MEMARG:
        {
            uint64_t align = emitGetAlignHintLog2(this);
            assert(align < 64); // spec says align > 2^6 produces a memidx for multiple memories.
            size += SizeOfULEB128(align);
            size += idIsCnsReloc() ? PADDED_RELOC_SIZE : SizeOfULEB128(emitGetInsSC(this));
            break;
        }
        default:
            unreached();
    }
    return size;
}

void emitter::emitSetShortJump(instrDescJmp* id)
{
    NYI_WASM("emitSetShortJump");

Review comment (suggestion):
The order of size calculations for IF_CALL_INDIRECT is inconsistent with the actual output order. According to WebAssembly specification, call_indirect format is: opcode, type_idx, table_idx. The emitOutputInstr function (lines 539-540) correctly outputs type index first, then table index. However, this idCodeSize calculation adds the table index size first (line 404), then the type index size (line 405). The order should be reversed to match the output order for consistency.
```suggestion
            size += SizeOfULEB128(emitGetInsSC(this));
            size += SizeOfULEB128(0);
```

Code after:
            size += 4;
            break;
        case IF_F64:
            size += 8;
            break;
        case IF_MEMARG:
        {
            uint64_t align = emitGetAlignHintLog2(this);
            assert(align < 64); // spec says align > 2^6 produces a memidx for multiple memories.
            size += SizeOfULEB128(align);
            size += idIsCnsReloc() ? PADDED_RELOC_SIZE : SizeOfULEB128(emitGetInsSC(this));
            break;
        }
        default:
            unreached();
    }
    return size;
}

void emitter::emitSetShortJump(instrDescJmp* id)
{
    NYI_WASM("emitSetShortJump");
}

size_t emitter::emitOutputULEB128(uint8_t* destination, uint64_t value)
{
    uint8_t* buffer = destination + writeableOffset;
    if (value >= 0x80)
    {
        int pos = 0;
        do
        {
            buffer[pos++] = (uint8_t)((value & 0x7F) | ((value >= 0x80) ? 0x80u : 0));
            value >>= 7;
        } while (value > 0);

        return pos;
    }
    else
    {
        buffer[0] = (uint8_t)value;
        return 1;
    }
}

size_t emitter::emitOutputSLEB128(uint8_t* destination, int64_t value)
{
    uint8_t* buffer = destination + writeableOffset;
    bool     cont   = true;
    int      pos    = 0;
    while (cont)