codegen_t Class Referenceabstract

Helper class to generate the initial microcode. More...

Public Member Functions

 codegen_t (mbl_array_t *m)
 
virtual merror_t analyze_prolog (const class qflow_chart_t &fc, const class bitset_t &reachable)=0
 Analyze prolog/epilog of the function to decompile. More...
 
virtual merror_t gen_micro ()=0
 Generate microcode for one instruction. More...
 
virtual mreg_t load_operand (int opnum)=0
 Generate microcode to load one operand.
 
virtual minsn_temit_micro_mvm (mcode_t code, op_dtype_t dtype, uval_t l, uval_t r, uval_t d, int offsize)
 Emit one microinstruction. More...
 
minsn_temit (mcode_t code, int width, uval_t l, uval_t r, uval_t d, int offsize)
 Emit one microinstruction. More...
 
minsn_temit (mcode_t code, const mop_t *l, const mop_t *r, const mop_t *d)
 Emit one microinstruction. More...
 

Public Attributes

mbl_array_tmba
 
mblock_tmb
 
insn_t insn
 
char ignore_micro
 

Detailed Description

Helper class to generate the initial microcode.

Definition at line 4658 of file hexrays.hpp.

Member Function Documentation

◆ analyze_prolog()

virtual merror_t codegen_t::analyze_prolog ( const class qflow_chart_t &  fc,
const class bitset_t reachable 
)
pure virtual

Analyze prolog/epilog of the function to decompile.

If prolog is found, allocate and fill 'mba->pi' structure.

Parameters
fcflow chart
reachablebitmap of reachable blocks
Returns
error code

◆ emit() [1/2]

minsn_t * codegen_t::emit ( mcode_t  code,
int  width,
uval_t  l,
uval_t  r,
uval_t  d,
int  offsize 
)

Emit one microinstruction.

The L, R, D arguments usually mean the register number. However, they depend on CODE. For example:

  • for m_goto and m_jcnd L is the target address
  • for m_ldc L is the constant value to load
    Parameters
    codeinstruction opcode
    widthoperand size in bytes
    lleft operand
    rright operand
    ddestination operand
    offsizefor ldx/stx, the size of the offset operand. for ldc, operand number of the constant value
    Returns
    created microinstruction. can be NULL if the instruction got immediately optimized away.

Definition at line 10509 of file hexrays.hpp.

References hexdsp.

◆ emit() [2/2]

minsn_t * codegen_t::emit ( mcode_t  code,
const mop_t l,
const mop_t r,
const mop_t d 
)

Emit one microinstruction.

This variant accepts pointers to operands. It is more difficult to use but permits to create virtually any instruction. Operands may be NULL when it makes sense.

Definition at line 10515 of file hexrays.hpp.

References hexdsp.

◆ emit_micro_mvm()

virtual minsn_t* codegen_t::emit_micro_mvm ( mcode_t  code,
op_dtype_t  dtype,
uval_t  l,
uval_t  r,
uval_t  d,
int  offsize 
)
virtual

Emit one microinstruction.

See explanations for emit().

Definition at line 4694 of file hexrays.hpp.

References get_temp_regs(), hexapi, and is_kreg().

◆ gen_micro()

virtual merror_t codegen_t::gen_micro ( )
pure virtual

Generate microcode for one instruction.

The instruction is in INSN

Returns
MERR_OK - all ok MERR_BLOCK - all ok, need to switch to new block MERR_BADBLK - delete current block and continue other error codes are fatal