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

Code before:
    NYI_WASM("emitIns_R_R");
}

void emitter::emitIns_S_R(instruction ins, emitAttr attr, regNumber ireg, int varx, int offs)
{
    NYI_WASM("emitIns_S_R");
}

bool emitter::emitInsIsStore(instruction ins)
{
    NYI_WASM("emitInsIsStore");
    return false;
}

emitter::instrDesc* emitter::emitNewInstrLclVarDecl(emitAttr attr, cnsval_ssize_t localCount, instWasmValueType type)
{
    instrDescLclVarDecl* id = static_cast<instrDescLclVarDecl*>(emitAllocAnyInstr(sizeof(instrDescLclVarDecl), attr));
    id->idSetIsLclVarDecl(true);
    id->idLclCnt(localCount);
    id->idLclType(type);

    return id;
}

//-----------------------------------------------------------------------------------
// emitIns_I: Emit an instruction with an immediate operand and an encoded value type
//
void emitter::emitIns_I_Ty(instruction ins, cnsval_ssize_t imm, emitter::instWasmValueType valType)
{
    instrDesc* id  = this->emitNewInstrLclVarDecl(EA_8BYTE, imm, valType);
    insFormat  fmt = this->emitInsFormat(ins);

    id->idIns(ins);
    id->idInsFmt(fmt);

    this->dispIns(id);
    this->appendToCurIG(id);
}

emitter::instWasmValueType emitter::emitGetLclVarDeclType(instrDesc* id)
{
    if (!id->idIsLclVarDecl())
    {
        noway_assert("not a LclVarDecl instrDesc");
    }

    return static_cast<instrDescLclVarDecl*>(id)->lclType;
}

cnsval_ssize_t emitter::emitGetLclVarDeclCount(instrDesc* id)
{

Review comment (suggestion):
The comment says "Emit an instruction with an immediate operand and an encoded value type" but the function signature and name suggest "I_Ty" (immediate and type). The comment should clarify that this is specifically for local variable declarations that encode both a count (immediate) and a type.
```suggestion
// emitIns_I_Ty: Emit an instruction for a local variable declaration, encoding both
// a count (immediate) and a value type. This is specifically used for local variable
// declarations that require both the number of locals and their type to be encoded.
```

Code after:
    NYI_WASM("emitIns_R_R");
}

void emitter::emitIns_S_R(instruction ins, emitAttr attr, regNumber ireg, int varx, int offs)
{
    NYI_WASM("emitIns_S_R");
}

bool emitter::emitInsIsStore(instruction ins)
{
    NYI_WASM("emitInsIsStore");
    return false;
}

//-----------------------------------------------------------------------------
// emitNewInstrLclVarDecl: Construct an instrDesc corresponding to a wasm local
// declaration.
//
// Arguments:
//   attr        - emit attributes
//   localCount  - the count of locals in this declaration
//   type        - the type of local in the declaration
//   lclOffset   - used to provide the starting index of this local
//
// Notes:
//   `lclOffset` is stored as debug info attached to the instruction,
//    so the offset will only be used if m_debugInfoSize > 0
emitter::instrDesc* emitter::emitNewInstrLclVarDecl(emitAttr      attr,
                                                    unsigned int  localCount,
                                                    WasmValueType type,
                                                    int           lclOffset)
{
    instrDescLclVarDecl* id = static_cast<instrDescLclVarDecl*>(emitAllocAnyInstr(sizeof(instrDescLclVarDecl), attr));
    id->idLclCnt(localCount);
    id->idLclType(type);

    if (m_debugInfoSize > 0)
    {
        id->idDebugOnlyInfo()->lclOffset = lclOffset;
    }

    return id;
}

//-----------------------------------------------------------------------------------
// emitIns_I_Ty: Emit an instruction for a local variable declaration, encoding both
// a count (immediate) and a value type. This is specifically used for local variable
// declarations that require both the number of locals and their type to be encoded.
//
// Arguments:
//   ins      - instruction to emit