IDA C++ SDK 9.2
Loading...
Searching...
No Matches
codegen_t Class Referenceabstract

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

#include <hexrays.hpp>

Public Member Functions

 codegen_t ()=delete
virtual ~codegen_t ()
void hexapi clear ()
virtual merror_t idaapi analyze_prolog (const class qflow_chart_t &fc, const class bitset_t &reachable)=0
 Analyze prolog/epilog of the function to decompile.
virtual merror_t idaapi gen_micro ()=0
 Generate microcode for one instruction.
virtual mreg_t idaapi load_operand (int opnum, int flags=0)=0
 Generate microcode to load one operand.
virtual void idaapi microgen_completed ()
 This method is called when the microcode generation is done.
virtual merror_t idaapi prepare_gen_micro ()
 Setup internal data to handle new instruction.
virtual mreg_t idaapi load_effective_address (int n, int flags=0)=0
 Generate microcode to calculate the address of a memory operand.
virtual bool idaapi store_operand (int n, const mop_t &mop, int flags=0, minsn_t **outins=nullptr)
 Generate microcode to store an operand.
minsn_t *hexapi emit (mcode_t code, int width, uval_t l, uval_t r, uval_t d, int offsize)
 Emit one microinstruction.
minsn_t *idaapi emit_micro_mvm (mcode_t code, op_dtype_t dtype, uval_t l, uval_t r, uval_t d, int offsize)
 Emit one microinstruction.
minsn_t *hexapi emit (mcode_t code, const mop_t *l, const mop_t *r, const mop_t *d)
 Emit one microinstruction.

Public Attributes

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

Detailed Description

Helper class to generate the initial microcode.

Constructor & Destructor Documentation

◆ codegen_t()

codegen_t::codegen_t ( )
delete

◆ ~codegen_t()

virtual codegen_t::~codegen_t ( )
inlinevirtual

Member Function Documentation

◆ clear()

void codegen_t::clear ( )
inline

◆ analyze_prolog()

virtual merror_t idaapi 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

◆ gen_micro()

virtual merror_t idaapi 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_operand()

virtual mreg_t idaapi 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 idaapi codegen_t::microgen_completed ( )
inlinevirtual

This method is called when the microcode generation is done.

◆ prepare_gen_micro()

virtual merror_t idaapi codegen_t::prepare_gen_micro ( )
inlinevirtual

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

◆ load_effective_address()

virtual mreg_t idaapi 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)

◆ store_operand()

virtual bool idaapi 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

◆ emit() [1/2]

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

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.

◆ emit_micro_mvm()

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

Emit one microinstruction.

This variant takes a data type not a size.

◆ emit() [2/2]

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

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.

Member Data Documentation

◆ mba

mba_t* codegen_t::mba

◆ mb

mblock_t* codegen_t::mb = nullptr

◆ insn

insn_t codegen_t::insn

◆ ignore_micro

char codegen_t::ignore_micro = IM_NONE

◆ ii

cdg_insn_iterator_t codegen_t::ii

◆ reserved

size_t codegen_t::reserved[4]

The documentation for this class was generated from the following file: