OpenASIP
2.0
|
#include <FiniteStateAutomaton.hh>
Public Types | |
typedef int | FSAStateTransitionIndex |
Type used for indexing the transitions. More... | |
typedef int | FSAStateIndex |
Type used for indexing the states. More... | |
typedef std::set< FSAStateIndex > | FSAStateIndexSet |
Type for a set of state indices. More... | |
Public Member Functions | |
FiniteStateAutomaton (FSAStateTransitionIndex defaultState=ILLEGAL_STATE, int transitionCount=0) | |
virtual | ~FiniteStateAutomaton () |
virtual const std::string & | transitionName (FSAStateTransitionIndex transition) const |
virtual std::string | stateName (FSAStateIndex state) const |
virtual FSAStateTransitionIndex | transitionIndex (const std::string &transitionName) const |
virtual FSAStateIndex | destinationState (FSAStateIndex source, FSAStateTransitionIndex transition) |
virtual bool | isLegalTransition (FSAStateIndex source, FSAStateTransitionIndex transition) |
virtual FSAStateIndex | addState () |
virtual FSAStateTransitionIndex | addTransitionType (const std::string &name) |
virtual void | setTransitionName (FSAStateTransitionIndex transition, const std::string &name) |
virtual void | setTransition (FSAStateIndex source, FSAStateIndex destination, FSAStateTransitionIndex transition) |
virtual std::string | toDotString () const |
virtual FSAStateIndex | startState () const |
Static Public Attributes | |
static const FSAStateIndex | ILLEGAL_STATE = -1 |
A state id which denotes an illegal state. More... | |
static const FSAStateIndex | UNKNOWN_STATE = -2 |
A state id which denotes an unknown (unresolved) state. Used for lazy construction of states. More... | |
Protected Types | |
typedef std::vector< FSAStateIndex > | TransitionVector |
Vector which stores the target states of for each transition type. More... | |
typedef std::vector< TransitionVector > | TransitionMap |
Type for storing the transitions of each state. The vector stores for each state (indexed from 0) a vector with elements as many there are transitions. The value of the element is the target state to which the transition leads to, or ILLEGAL_STATE_INDEX if there is no transition for that transition type from that state. Using this structure it's possible to find the target state using two table (vector) lookups. More... | |
Protected Attributes | |
TransitionMap | transitions_ |
The state transitions. In protected to allow fast access from derived classes. More... | |
Private Types | |
typedef std::map< std::string, FSAStateTransitionIndex > | TransitionNameIndex |
Type for finding the index for a transition using its name. More... | |
Private Attributes | |
int | stateCount_ |
Count of states in the automaton. More... | |
int | transitionTypeCount_ |
Count of different transition types in the automaton. More... | |
std::vector< std::string > | transitionNames_ |
Names of the state transitions types (indexed from 0). More... | |
TransitionNameIndex | transitionIndices_ |
Indices of the state transition types. More... | |
const FSAStateTransitionIndex | defaultState_ |
The default target state for state transitions. More... | |
Friends | |
class | FSAFUResourceConflictDetector |
Friend due to highly optimized compiled simulation versions of the conflict detection functions. More... | |
Generic finite state automaton (FSA).
This is a generic structure for FSA. The building and initialization of the states is the responsibility of derived classes.
Definition at line 49 of file FiniteStateAutomaton.hh.
typedef int FiniteStateAutomaton::FSAStateIndex |
Type used for indexing the states.
Definition at line 57 of file FiniteStateAutomaton.hh.
typedef std::set<FSAStateIndex> FiniteStateAutomaton::FSAStateIndexSet |
Type for a set of state indices.
Definition at line 59 of file FiniteStateAutomaton.hh.
typedef int FiniteStateAutomaton::FSAStateTransitionIndex |
Type used for indexing the transitions.
Definition at line 55 of file FiniteStateAutomaton.hh.
|
protected |
Type for storing the transitions of each state. The vector stores for each state (indexed from 0) a vector with elements as many there are transitions. The value of the element is the target state to which the transition leads to, or ILLEGAL_STATE_INDEX if there is no transition for that transition type from that state. Using this structure it's possible to find the target state using two table (vector) lookups.
Definition at line 116 of file FiniteStateAutomaton.hh.
|
private |
Type for finding the index for a transition using its name.
Definition at line 126 of file FiniteStateAutomaton.hh.
|
protected |
Vector which stores the target states of for each transition type.
Definition at line 107 of file FiniteStateAutomaton.hh.
FiniteStateAutomaton::FiniteStateAutomaton | ( | FSAStateTransitionIndex | defaultState = ILLEGAL_STATE , |
int | transitionCount = 0 |
||
) |
Constructor.
defaultState | The default state for state transitions (either ILLEGAL_STATE or UNKNOWN_STATE, as no other states are known at this point). |
transitionCount | The initial count of transitions. |
Definition at line 55 of file FiniteStateAutomaton.cc.
|
virtual |
Destructor.
Definition at line 66 of file FiniteStateAutomaton.cc.
References Application::logStream(), and stateCount_.
|
virtual |
Adds a new state to the automaton.
Definition at line 178 of file FiniteStateAutomaton.cc.
References defaultState_, stateCount_, transitions_, and transitionTypeCount_.
Referenced by FUFiniteStateAutomaton::FUFiniteStateAutomaton(), and FUFiniteStateAutomaton::resolveState().
|
virtual |
Adds a new transition type to the automaton.
name | Name of the transition type. Must be unique within all transition types. |
Definition at line 194 of file FiniteStateAutomaton.cc.
References defaultState_, transitionIndices_, transitionNames_, transitions_, and transitionTypeCount_.
|
virtual |
Returns the index of the state resulting from the given transition from the given source state.
This method is called often, thus should be as fast as possible. Therefore, all range checking etc. is disabled. Method is not const due to possibility of lazy initialization of states in derived classes.
source | The source state. |
transition | The transition. |
Reimplemented in FUFiniteStateAutomaton.
Definition at line 146 of file FiniteStateAutomaton.cc.
References transitions_.
|
virtual |
Returns true in case the given transition is legal (accepted by the state machine) from the given state.
This method is called often, thus should be as fast as possible. Therefore, all range checking etc. is disabled. Method is not const due to possibility of lazy initialization of states in derived classes.
source | The source state. |
transition | The transition. |
Reimplemented in FUFiniteStateAutomaton.
Definition at line 165 of file FiniteStateAutomaton.cc.
References ILLEGAL_STATE, and transitions_.
|
virtual |
Set a transition between two states.
source | The source state. |
destination | The destination state. |
transition | The type of transition. |
Definition at line 219 of file FiniteStateAutomaton.cc.
References transitions_.
Referenced by FUFiniteStateAutomaton::resolveState().
|
virtual |
Sets a name for the given transition.
transition | The index of the transition of which name to return. |
name | The name of the transition. |
Definition at line 93 of file FiniteStateAutomaton.cc.
References transitionIndices_, and transitionNames_.
Referenced by FUFiniteStateAutomaton::FUFiniteStateAutomaton().
|
virtual |
Returns the starting state of the automaton.
By default the starting state is assumed to be the state 0.
Definition at line 282 of file FiniteStateAutomaton.cc.
Referenced by FSAFUResourceConflictDetector::isIdle(), and FSAFUResourceConflictDetector::reset().
|
virtual |
Returns the textual description of the state at the given index.
state | The index of the state of which name to return. |
Reimplemented in FUFiniteStateAutomaton.
Definition at line 106 of file FiniteStateAutomaton.cc.
References Conversion::toString().
Referenced by toDotString().
|
virtual |
Creates a string that represents the FSA as a graph in GraphViz dot format.
This string can be rendered to a visual graph using the 'dot' tool.
Definition at line 235 of file FiniteStateAutomaton.cc.
References ILLEGAL_STATE, stateCount_, stateName(), Conversion::toString(), transitionName(), transitions_, transitionTypeCount_, and UNKNOWN_STATE.
Referenced by FSAFUResourceConflictDetector::writeToDotFile().
|
virtual |
Returns the index of the transition with given name.
Returns the transition index for an operation in case of an FU FSA.
transitionName | The name of the transition of index to return. |
KeyNotFound | In case no transition with given is found. |
Definition at line 120 of file FiniteStateAutomaton.cc.
References __func__, transitionIndices_, and transitionName().
Referenced by FUFiniteStateAutomaton::operationCollisionMatrix(), and FSAFUResourceConflictDetector::operationID().
|
virtual |
Returns the textual description of the transition at the given index.
For example, returns the name of the operation in case of an FU FSA.
transition | The index of the transition of which name to return. |
Definition at line 81 of file FiniteStateAutomaton.cc.
References transitionNames_.
Referenced by FSAFUResourceConflictDetector::operationName(), toDotString(), and transitionIndex().
|
friend |
Friend due to highly optimized compiled simulation versions of the conflict detection functions.
Definition at line 53 of file FiniteStateAutomaton.hh.
|
private |
The default target state for state transitions.
Definition at line 136 of file FiniteStateAutomaton.hh.
Referenced by addState(), and addTransitionType().
|
static |
A state id which denotes an illegal state.
Definition at line 61 of file FiniteStateAutomaton.hh.
Referenced by FUFiniteStateAutomaton::buildStateMachine(), FUFiniteStateAutomaton::isLegalTransition(), isLegalTransition(), FSAFUResourceConflictDetector::issueOperationInline(), FSAFUResourceConflictDetector::issueOperationLazyInline(), FUFiniteStateAutomaton::resolveState(), and toDotString().
|
private |
Count of states in the automaton.
Definition at line 128 of file FiniteStateAutomaton.hh.
Referenced by addState(), toDotString(), and ~FiniteStateAutomaton().
|
private |
Indices of the state transition types.
Definition at line 134 of file FiniteStateAutomaton.hh.
Referenced by addTransitionType(), setTransitionName(), and transitionIndex().
|
private |
Names of the state transitions types (indexed from 0).
Definition at line 132 of file FiniteStateAutomaton.hh.
Referenced by addTransitionType(), setTransitionName(), and transitionName().
|
protected |
The state transitions. In protected to allow fast access from derived classes.
Definition at line 120 of file FiniteStateAutomaton.hh.
Referenced by addState(), addTransitionType(), FSAFUResourceConflictDetector::advanceCycleLazyInline(), FUFiniteStateAutomaton::destinationState(), destinationState(), isLegalTransition(), FSAFUResourceConflictDetector::issueOperationInline(), FSAFUResourceConflictDetector::issueOperationLazyInline(), setTransition(), and toDotString().
|
private |
Count of different transition types in the automaton.
Definition at line 130 of file FiniteStateAutomaton.hh.
Referenced by addState(), addTransitionType(), and toDotString().
|
static |
A state id which denotes an unknown (unresolved) state. Used for lazy construction of states.
Definition at line 64 of file FiniteStateAutomaton.hh.
Referenced by FSAFUResourceConflictDetector::advanceCycleLazyInline(), FUFiniteStateAutomaton::destinationState(), FSAFUResourceConflictDetector::issueOperationLazyInline(), and toDotString().