EncoderBase Class Reference

#include <enc_base.h>

List of all members.


Detailed Description

Basic facilities for generation of processor's instructions.

The class EncoderBase represents the basic facilities for the encoding of processor's instructions on IA32 and EM64T platforms.

The class provides general interface to generate the instructions as well as to retrieve some static data about instructions (number of arguments, their roles, etc).

Currently, the EncoderBase class is used for both LIL and Jitrino code generators. Each of these code generators has its own wrapper to adapt this general interface for specific needs - see encoder.h for LIL wrappers and Ia32Encoder.h for Jitrino's adapter.

Interface is provided through static methods, no instances of EncoderBase to be created.

Todo:
RIP-based addressing on EM64T - it's not yet supported currently.


Static Public Member Functions

static char * encode (char *stream, Mnemonic mn, const Operands &opnds)
 Generates processor's instruction.
static char * nops (char *stream, unsigned howMany)
 Generates the smallest possible number of NOP-s.
static char * prefix (char *stream, InstPrefix pref)
 Inserts a prefix into the code buffer.
static const MnemonicDescgetMnemonicDesc (Mnemonic mn)
 Returns MnemonicDesc by the given Mnemonic.
static Mnemonic str2mnemonic (const char *mn_name)
 Returns a Mnemonic for the given name.
static const char * getMnemonicString (Mnemonic mn)
 Returns a string representation of the given Mnemonic.
static const char * toStr (Mnemonic mn)
static OpndRole getOpndRoles (OpndRolesDesc ord, unsigned idx)
 Extracts appropriate OpndRole for a given operand.
static int buildTable (void)
static void buildMnemonicDesc (const MnemonicInfo *minfo)
static unsigned short getHash (const OpcodeInfo *odesc)
 Computes hash value for the given operands.

Static Public Attributes

static const unsigned int HASH_MAX = 8192
 Magic number, shows a maximum value a hash code can take.
static const unsigned char NOHASH = 0xFF
 Empty value, used in hash-to-opcode map to show an empty slot.
static const unsigned char HASH_BITS_PER_OPERAND = 5
 The name says it all.
static const unsigned char size_hash [OpndSize_64+1]
 A table used for the fast computation of hash value.
static const unsigned char kind_hash [OpndKind_Mem+1]
 A table used for the fast computation of hash value.
static const unsigned int MAX_OPCODES = 32
 Maximum number of opcodes used for a single mnemonic.
static unsigned char opcodesHashMap [Mnemonic_Count][HASH_MAX]
 Mapping between operands hash code and operands.
static MnemonicDesc mnemonics [Mnemonic_Count]
 Array of mnemonics.
static OpcodeDesc opcodes [Mnemonic_Count][MAX_OPCODES]
 Array of available opcodes.
static int dummy
 Dummy variable, for automatic invocation of buildTable() at startup.

Classes

struct  MnemonicDesc
 General info about mnemonic. More...
union  OpcodeDesc
 Info about single opcode - its opcode bytes, operands, operands' roles. More...
class  Operand
 Contains info about a single instructions's operand - its location, size and a value for immediate or RegName for register operands. More...
class  Operands
 Simple container for up to 3 Operand-s. More...
struct  OpndDesc
 Description of operand. More...
struct  OpndRolesDesc
 Description of operands' roles in instruction. More...


Member Function Documentation

static char* EncoderBase.encode ( char *  stream,
Mnemonic  mn,
const Operands opnds 
) [static]

Generates processor's instruction.

Parameters:
stream - a buffer to generate into
mn - mnemonic of the instruction
opnds - operands for the instruction
Returns:
(stream + length of the just generated instruction)

static char* EncoderBase.nops ( char *  stream,
unsigned  howMany 
) [static]

Generates the smallest possible number of NOP-s.

Effectively generates the smallest possible number of instructions, which are NOP-s for CPU. Normally used to make a code alignment.

The method inserts exactly number of bytes specified. It's a caller's responsibility to make sure the buffer is big enough.

Parameters:
stream - buffer where to generate code into, can not be NULL
howMany - how many bytes to fill with NOP-s
Returns:
(stream+howMany)

static char* EncoderBase.prefix ( char *  stream,
InstPrefix  pref 
) [static]

Inserts a prefix into the code buffer.

The method writes no more than one byte into the buffer. This is a caller's responsibility to make sure the buffer is big enough.

Parameters:
stream - buffer where to insert the prefix
pref - prefix to be inserted. If it's InstPrefix_Null, then no action performed and return value is stream.
Returns:
(stream+1) if pref is not InstPrefix_Null, or stream otherwise

static const MnemonicDesc* EncoderBase.getMnemonicDesc ( Mnemonic  mn  )  [static]

Returns MnemonicDesc by the given Mnemonic.

static Mnemonic EncoderBase.str2mnemonic ( const char *  mn_name  )  [static]

Returns a Mnemonic for the given name.

The lookup is case insensitive, if no mnemonic found for the given string, then Mnemonic_Null returned.

static const char* EncoderBase.getMnemonicString ( Mnemonic  mn  )  [static]

Returns a string representation of the given Mnemonic.

If invalid mnemonic passed, then the behavior is unpredictable.

static const char* EncoderBase.toStr ( Mnemonic  mn  )  [static]

static OpndRole EncoderBase.getOpndRoles ( OpndRolesDesc  ord,
unsigned  idx 
) [static]

Extracts appropriate OpndRole for a given operand.

The order of operands is left-to-right, i.e. for MOV, it would be 'MOV op0, op1'

static int EncoderBase.buildTable ( void   )  [static]

static void EncoderBase.buildMnemonicDesc ( const MnemonicInfo minfo  )  [static]

static unsigned short EncoderBase.getHash ( const OpcodeInfo odesc  )  [static]

Computes hash value for the given operands.


Member Data Documentation

const unsigned int EncoderBase.HASH_MAX = 8192 [static]

Magic number, shows a maximum value a hash code can take.

For meaning and arithmetics see enc_tabl.cpp.

The value was increased from '5155' to '8192' to make it aligned for faster access in EncoderBase.lookup().

const unsigned char EncoderBase.NOHASH = 0xFF [static]

Empty value, used in hash-to-opcode map to show an empty slot.

const unsigned char EncoderBase.HASH_BITS_PER_OPERAND = 5 [static]

The name says it all.

const unsigned char EncoderBase.size_hash[OpndSize_64+1] [static]

A table used for the fast computation of hash value.

A change must be strictly balanced with hash-related functions and data in enc_base.h/.cpp.

const unsigned char EncoderBase.kind_hash[OpndKind_Mem+1] [static]

A table used for the fast computation of hash value.

A change must be strictly balanced with hash-related functions and data in enc_base.h/.cpp.

const unsigned int EncoderBase.MAX_OPCODES = 32 [static]

Maximum number of opcodes used for a single mnemonic.

No arithmetics behind the number, simply estimated.

unsigned char EncoderBase.opcodesHashMap[Mnemonic_Count][HASH_MAX] [static]

Mapping between operands hash code and operands.

MnemonicDesc EncoderBase.mnemonics[Mnemonic_Count] [static]

Array of mnemonics.

OpcodeDesc EncoderBase.opcodes[Mnemonic_Count][MAX_OPCODES] [static]

Array of available opcodes.

int EncoderBase.dummy [static]

Dummy variable, for automatic invocation of buildTable() at startup.


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

Genereated on Tue Mar 11 19:25:42 2008 by Doxygen.

(c) Copyright 2005, 2008 The Apache Software Foundation or its licensors, as applicable.