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

Code before:
        case IF_MEMARG:
        {
            dst += emitOutputByte(dst, opcode);
            uint64_t align  = emitGetAlignHintLog2(id);
            uint64_t offset = emitGetInsSC(id);
            assert(align <= UINT32_MAX); // spec says memarg alignment is u32
            assert(align < 64);          // spec says align > 2^6 produces a memidx for multiple memories.
            dst += emitOutputULEB128(dst, align);
            dst += emitOutputULEB128(dst, offset);
            break;
        }
        case IF_LOCAL_CNT:
        {
            cnsval_ssize_t constant = emitGetInsSC(id);
            dst += emitOutputULEB128(dst, (uint64_t)constant);
            break;
        }
        case IF_LOCAL_DECL:
        {
            assert(id->idIsLclVarDecl());
            cnsval_ssize_t    count   = emitGetLclVarDeclCount(id);
            uint8_t valType = getWasmValueTypeCode(emitGetLclVarDeclType(id));
            dst += emitOutputULEB128(dst, (uint64_t)count);
            // TODO-WASM: currently assuming all locals are numtypes which are single byte encoded.
            // vec types are also single byte encoded. If we end up using reftypes, we'll need to handle the more
            // complex encoding.
            dst += emitOutputByte(dst, valType);
            break;
        }
        default:
            NYI_WASM("emitOutputInstr");
            break;
    }

#ifdef DEBUG
    bool dspOffs = emitComp->opts.dspGCtbls;
    if (emitComp->opts.disAsm || emitComp->verbose)
    {
        emitDispIns(id, false, dspOffs, true, emitCurCodeOffs(*dp), *dp, (dst - *dp), ig);
    }
#else
    if (emitComp->opts.disAsm)
    {
        emitDispIns(id, false, 0, true, emitCurCodeOffs(*dp), *dp, (dst - *dp), ig);
    }
#endif

    *dp = dst;
    return sz;
}


Review comment (suggestion):
```suggestion
```
I would reserve `TODO-WASM` for things that "need" to be done for the work as we currently have to be complete. We don't plan to use reference types for now. To support reference types we'd need to add a type reloc here.

Code after:
            //  then finally copy the raw truncated f32 bits to the output.
            cnsval_ssize_t bits = emitGetInsSC(id);
            double         value;
            float          truncated;
            memcpy(&value, &bits, sizeof(double));
            truncated = FloatingPointUtils::convertToSingle(value);
            dst += emitRawBytes(dst, &truncated, sizeof(float));
            break;
        }
        case IF_F64:
        {
            dst += emitOutputByte(dst, opcode);
            // The int64 bits are actually a double constant we can copy directly
            //  to the output stream.
            cnsval_ssize_t bits = emitGetInsSC(id);
            dst += emitRawBytes(dst, &bits, sizeof(cnsval_ssize_t));
            break;
        }
        case IF_RAW_ULEB128:
        {
            cnsval_ssize_t constant = emitGetInsSC(id);
            dst += emitOutputULEB128(dst, (uint64_t)constant);
            break;
        }
        case IF_MEMARG:
        {
            dst += emitOutputByte(dst, opcode);
            uint64_t align  = emitGetAlignHintLog2(id);
            uint64_t offset = emitGetInsSC(id);
            assert(align <= UINT32_MAX); // spec says memarg alignment is u32
            assert(align < 64);          // spec says align > 2^6 produces a memidx for multiple memories.
            dst += emitOutputULEB128(dst, align);
            dst += emitOutputULEB128(dst, offset);
            break;
        }
        case IF_LOCAL_DECL:
        {
            assert(id->idIsLclVarDecl());
            cnsval_ssize_t count   = emitGetLclVarDeclCount(id);
            uint8_t        valType = GetWasmValueTypeCode(emitGetLclVarDeclType(id));
            dst += emitOutputULEB128(dst, (uint64_t)count);
            dst += emitOutputByte(dst, valType);
            break;
        }
        default:
            NYI_WASM("emitOutputInstr");
            break;
    }

#ifdef DEBUG
    bool dspOffs = emitComp->opts.dspGCtbls;