Latest available version: IDA and decompilers v8.4.240320sp1 see all releases
Hex-Rays logo State-of-the-art binary code analysis tools
email icon
codegen_t Class Referenceabstract

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

#include <hexrays.hpp>

Public Member Functions

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, int flags=0)=0
 Generate microcode to load one operand. More...
 
virtual void microgen_completed ()
 This method is called when the microcode generation is done. More...
 
virtual merror_t prepare_gen_micro ()
 Setup internal data to handle new instruction. More...
 
virtual mreg_t load_effective_address (int n, int flags=0)=0
 Generate microcode to calculate the address of a memory operand. More...
 
virtual bool store_operand (int n, const mop_t &mop, int flags=0, minsn_t **outins=nullptr)
 Generate microcode to store an operand. 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_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, const mop_t *l, const mop_t *r, const mop_t *d)
 Emit one microinstruction. More...
 

Public Attributes

mba_tmba
 
mblock_tmb = nullptr
 
insn_t insn
 
char ignore_micro = IM_NONE
 
cdg_insn_iterator_t ii
 
size_t reserved
 

Detailed Description

Helper class to generate the initial microcode.

Definition at line 5162 of file hexrays.hpp.

Constructor & Destructor Documentation

◆ ~codegen_t()

virtual codegen_t::~codegen_t ( )
virtual

Definition at line 5173 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,
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 nullptr when it makes sense.

Definition at line 11499 of file hexrays.hpp.

◆ emit() [2/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 -1, set the FP instruction (e.g. for m_mov)
    Returns
    created microinstruction. can be nullptr if the instruction got immediately optimized away.

Definition at line 11493 of file hexrays.hpp.

◆ emit_micro_mvm()

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 
)

Emit one microinstruction.

This variant takes a data type not a size.

Definition at line 5249 of file hexrays.hpp.

◆ 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

◆ load_effective_address()

virtual mreg_t codegen_t::load_effective_address ( int  n,
int  flags = 0 
)
pure virtual

Generate microcode to calculate the address of a memory operand.

Parameters
n- number of INSN operand
flags- reserved for future use
Returns
register containing the operand address. mr_none - failed (not a memory operand)

◆ load_operand()

virtual mreg_t codegen_t::load_operand ( int  opnum,
int  flags = 0 
)
pure virtual

Generate microcode to load one operand.

Parameters
opnumnumber of INSN operand
flagsreserved for future use
Returns
register containing the operand.

◆ microgen_completed()

virtual void codegen_t::microgen_completed ( )
virtual

This method is called when the microcode generation is done.

Definition at line 5201 of file hexrays.hpp.

◆ prepare_gen_micro()

virtual merror_t codegen_t::prepare_gen_micro ( )
virtual

Setup internal data to handle new instruction.

This method should be called before calling gen_micro(). Usually gen_micro() is called by the decompiler. You have to call this function explicitly only if you yourself call gen_micro(). The instruction is in INSN

Returns
MERR_OK - all ok other error codes are fatal

Definition at line 5210 of file hexrays.hpp.

References MERR_OK.

◆ store_operand()

virtual bool codegen_t::store_operand ( int  n,
const mop_t mop,
int  flags = 0,
minsn_t **  outins = nullptr 
)
virtual

Generate microcode to store an operand.

In case of success an arbitrary number of instructions can be generated (and even no instruction if the source and target are the same)

Parameters
n- number of target INSN operand
mop- operand to be stored
flags- reserved for future use
outins- (OUT) the last generated instruction
Returns
success

Member Data Documentation

◆ ignore_micro

char codegen_t::ignore_micro = IM_NONE

Definition at line 5168 of file hexrays.hpp.

◆ ii

cdg_insn_iterator_t codegen_t::ii

Definition at line 5169 of file hexrays.hpp.

◆ insn

insn_t codegen_t::insn

Definition at line 5167 of file hexrays.hpp.

◆ mb

mblock_t* codegen_t::mb = nullptr

Definition at line 5166 of file hexrays.hpp.

◆ mba

mba_t* codegen_t::mba

Definition at line 5165 of file hexrays.hpp.

◆ reserved

size_t codegen_t::reserved

Definition at line 5170 of file hexrays.hpp.