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

Code before:
//------------------------------------------------------------------------
// emitIns_I: Emit an instruction with an immediate operand.
//
void emitter::emitIns_I(instruction ins, emitAttr attr, cnsval_ssize_t imm)
{
    instrDesc* id  = emitNewInstrSC(attr, imm);
    insFormat  fmt = emitInsFormat(ins);

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

    dispIns(id);
    appendToCurIG(id);
}

//------------------------------------------------------------------------
// emitIns_J: Emit a jump instruction with an immediate operand.
//
void emitter::emitIns_J(instruction ins, emitAttr attr, cnsval_ssize_t imm, BasicBlock* tgtBlock)
{
    instrDesc* id  = emitNewInstrCns(attr, imm);
    insFormat  fmt = emitInsFormat(ins);

    id->idIns(ins);
    id->idInsFmt(fmt);
    id->idAddr()->iiaBBlabel = tgtBlock;
    id->idSetIsJump();

    dispIns(id);
    appendToCurIG(id);
}

//------------------------------------------------------------------------
// emitIns_S: Emit a memory instruction with a stack-based address mode operand.
//
void emitter::emitIns_S(instruction ins, emitAttr attr, int varx, int offs)
{
    bool FPBased;
    int  lclOffset = emitComp->lvaFrameAddress(varx, &FPBased);
    int  offset    = lclOffset + offs;
    noway_assert(offset >= 0); // WASM address modes are unsigned.

    emitIns_I(ins, attr, offset);
}

void emitter::emitIns_R(instruction ins, emitAttr attr, regNumber reg)
{
    NYI_WASM("emitIns_R");
}

void emitter::emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, cnsval_ssize_t imm)

Review comment (bug):
I think it would be simpler to store this in `idDebugOnlyInfo`, that way we don't need to deal with the `idAddr` union for printing-only data (and don't need to add bits to the base instr desc).

Code after:
//------------------------------------------------------------------------
// emitIns_I: Emit an instruction with an immediate operand.
//
// Arguments:
//   ins      - instruction to emit
//   attr     - emit attributes
//   imm      - immediate value
//
void emitter::emitIns_I(instruction ins, emitAttr attr, cnsval_ssize_t imm)
{
    instrDesc* id  = emitNewInstrSC(attr, imm);
    insFormat  fmt = emitInsFormat(ins);

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

    dispIns(id);
    appendToCurIG(id);
}

//------------------------------------------------------------------------
// emitIns_J: Emit a jump instruction with an immediate operand.
//
// Arguments:
//   ins         - instruction to emit
//   attr        - emit attributes
//   imm         - immediate value (depth in control flow stack)
//   targetBlock - block at that depth
//
void emitter::emitIns_J(instruction ins, emitAttr attr, cnsval_ssize_t imm, BasicBlock* targetBlock)
{
    instrDesc* id  = emitNewInstrSC(attr, imm);
    insFormat  fmt = emitInsFormat(ins);

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

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

    dispIns(id);
    appendToCurIG(id);
}

//------------------------------------------------------------------------
// emitIns_S: Emit a memory instruction with a stack-based address mode operand.
//
void emitter::emitIns_S(instruction ins, emitAttr attr, int varx, int offs)
{