MetaCC::StateTable Class Reference

#include <state_table.h>

List of all members.


Detailed Description

State trasitions table.

Todo:
This is much improved version of class StateMachine used in CPU::CPU_I8086 emulation code, and may replace that one in the future.

Should I add support for deletion of states? This is possible, but may create mess in the table if deletion is performed:

All these problems led me to decision not to allow deletion of states once they are added, but if future proves deletion is indeed necessary, support for it may be added.

Definition at line 21 of file state_table.h.

Public Member Functions

int add_state ()
 Add new state to the state table.
bool learn (int src_state, const char *patt_str, int dest_state, uint8 value=0, uint8 mask=0)
 Teach state table new edges between src_state to dest state, described by patt_str.
int states_count () const
 Return count of states currently in database.
int get_state_edge (int state_id, uint8 v) const
 Return index of dest edge leading from given edge for given input value v.

Static Public Member Functions

static std::string bin_str (uint8 v)
static std::string mask_str (uint8 v)


Member Function Documentation

int MetaCC::StateTable::add_state (  ) 

Add new state to the state table.

All edges will be inigially be set to point to state 0 (which generall means "error detecting pattern"). After adding state, caller might (and probably will ;o) call "learn()" function one or more time to setup edges leading from other (previously ADDed) states to this new state.

Returns:
the new state ID (integer value).

Definition at line 7 of file state_table.cpp.

Referenced by MetaCC::Compilation::prepare_state_table().

static std::string MetaCC::StateTable::bin_str ( uint8  v  )  [inline, static]

Todo:
remove this function (debug only!)

Definition at line 49 of file state_table.h.

static std::string MetaCC::StateTable::mask_str ( uint8  v  )  [inline, static]

Todo:
remove this function (debug only!)

Definition at line 56 of file state_table.h.

bool MetaCC::StateTable::learn ( int  src_state,
const char *  patt_str,
int  dest_state,
uint8  value = 0,
uint8  mask = 0 
)

Teach state table new edges between src_state to dest state, described by patt_str.

Format of patt_str is defined as string of characters, which MUST consist of any combination of characters '0', '1' and 'x'. Any other character in the string will cause OE_ASSERT() to be called in debug build, and will cause unpredictable results in release mode!

Parameters:
patt_str contain the string which represents pattern from which one or more result values (state graph edges) will be generated leading from src_state to dst_state.
src_state is an integer specifying source state ID for the generated edge(s).
dest_state is an integer specifying destination state ID for the generated edge(s).
value is internal parameter (not to be used by caller), used by recursion and is used to accumulate 8-bit value during recursion.
mask is internal parameter (not to be used by caller), used by recursion and is used to accumulate 8-bit "mask", which is parallel to 8-bit "value", and is bitfield where "1" bits signify bits specified as "digits" in the original pattern, and "0" bits signify bits specified as "x" in the original pattern.
Returns:
true if succesful, false if collision detected.
Note:
if "false" is returned some states may partially be changed, so this is fatal error, and this StateTable is probably not safe to use from this point!

Definition at line 19 of file state_table.cpp.

Referenced by MetaCC::Compilation::prepare_state_table().

int MetaCC::StateTable::states_count (  )  const [inline]

Return count of states currently in database.

For the function get_state_edge() max value of state_id must then be return value of this function - 1.

Definition at line 91 of file state_table.h.

Referenced by MetaCC::Compilation::generate_code_for_state_table().

int MetaCC::StateTable::get_state_edge ( int  state_id,
uint8  v 
) const [inline]

Return index of dest edge leading from given edge for given input value v.

Basically, this function performs fast lookup in the table.

Definition at line 96 of file state_table.h.

Referenced by MetaCC::Compilation::generate_code_for_state_table().


The documentation for this class was generated from the following files:
Generated on Sat Sep 9 03:50:56 2006 for Openem APIs by  doxygen 1.4.7