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

Code before:
{
    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)
{
    if (!id->idIsLclVarDecl())
    {
        noway_assert("not a LclVarDecl instrDesc");
    }

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

emitter::insFormat emitter::emitInsFormat(instruction ins)
{
    static_assert(IF_COUNT < 255);

    const static uint8_t insFormats[] = {
#define INST(id, nm, info, fmt, opcode) fmt,
#include "instrs.h"
    };

    assert(ins < ArrLen(insFormats));
    assert((insFormats[ins] != IF_NONE));
    return static_cast<insFormat>(insFormats[ins]);
}

static unsigned GetInsOpcode(instruction ins)
{
    static const uint8_t insOpcodes[] = {
#define INST(id, nm, info, fmt, opcode) static_cast<uint8_t>(opcode),
#include "instrs.h"
    };

Review comment (bug):
The noway_assert macro is being used incorrectly. It should be called with a condition, not a string message. Use noway_assert(false) or unreached() instead.

Code after:
                                                    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
//   imm      - immediate value (local count)
//   valType  - value type of the local variable
//   offs     - local variable offset (= count of preceding locals) for debug info
void emitter::emitIns_I_Ty(instruction ins, unsigned int imm, WasmValueType valType, int offs)
{
    instrDesc* id  = emitNewInstrLclVarDecl(EA_8BYTE, imm, valType, offs);
    insFormat  fmt = emitInsFormat(ins);

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

    dispIns(id);
    appendToCurIG(id);
}

WasmValueType emitter::emitGetLclVarDeclType(const instrDesc* id)
{
    assert(id->idIsLclVarDecl());
    return static_cast<const instrDescLclVarDecl*>(id)->lclType;
}

unsigned int emitter::emitGetLclVarDeclCount(const instrDesc* id)
{
    assert(id->idIsLclVarDecl());
    return static_cast<const instrDescLclVarDecl*>(id)->lclCnt;
}

emitter::insFormat emitter::emitInsFormat(instruction ins)