void FFlatCodeGen::writeOutData()
{
- if ( anyConditions() ) {
+ if ( redFsm->anyConditions() ) {
OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
COND_KEYS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCondSpan), CSP() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() );
COND_KEY_SPANS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCond), C() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() );
CONDS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCondIndexOffset), CO() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() );
COND_INDEX_OFFSET();
CLOSE_ARRAY() <<
"\n";
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxSpan), SP() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() );
KEY_SPANS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxFlatIndexOffset), IO() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() );
FLAT_INDEX_OFFSET();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxIndex), I() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
INDICIES();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS();
CLOSE_ARRAY() <<
"\n";
- if ( anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActListId), TA() );
+ if ( redFsm->anyActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() );
TRANS_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
TO_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
FROM_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActListId), EA() );
+ if ( redFsm->anyEofActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), EA() );
EOF_ACTIONS();
CLOSE_ARRAY() <<
"\n";
" {\n"
" int _slen";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << ", _ps";
out << ";\n";
out << " int _trans";
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
out << ", _cond";
out << ";\n";
out <<
" " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
- " " << PTR_CONST() << ARRAY_TYPE(maxIndex) << POINTER() << "_inds;\n";
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << "_inds;\n";
- if ( anyConditions() ) {
+ if ( redFsm->anyConditions() ) {
out <<
- " " << PTR_CONST() << ARRAY_TYPE(maxCond) << POINTER() << "_conds;\n"
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxCond) << POINTER() << "_conds;\n"
" " << WIDE_ALPH_TYPE() << " _widec;\n";
}
" goto _out;\n";
}
- if ( anyFromStateActions() ) {
+ if ( redFsm->anyFromStateActions() ) {
out <<
" switch ( " << FSA() << "[" << CS() << "] ) {\n";
FROM_STATE_ACTION_SWITCH();
"\n";
}
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
COND_TRANSLATE();
LOCATE_TRANS();
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << " _ps = " << CS() << ";\n";
out <<
" " << CS() << " = " << TT() << "[_trans];\n\n";
- if ( anyRegActions() ) {
+ if ( redFsm->anyRegActions() ) {
out <<
" if ( " << TA() << "[_trans] == 0 )\n"
" goto _again;\n"
"\n";
}
- if ( anyRegActions() || anyActionGotos() || anyActionCalls() || anyActionRets() )
+ if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
+ redFsm->anyActionCalls() || redFsm->anyActionRets() )
out << "_again:\n";
- if ( anyToStateActions() ) {
+ if ( redFsm->anyToStateActions() ) {
out <<
" switch ( " << TSA() << "[" << CS() << "] ) {\n";
TO_STATE_ACTION_SWITCH();
void FFlatCodeGen::writeOutEOF()
{
- if ( anyEofActions() ) {
+ if ( redFsm->anyEofActions() ) {
out <<
" {\n"
" switch ( " << EA() << "[" << CS() << "] ) {\n";
"\n";
}
- if ( anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
TO_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
FROM_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), EA() );
+ if ( redFsm->anyEofActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
EOF_ACTIONS();
CLOSE_ARRAY() <<
"\n";
out << " {\n";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << " int _ps = 0;\n";
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
if ( cgd->hasEnd ) {
out << "_resume:\n";
- if ( anyFromStateActions() ) {
+ if ( redFsm->anyFromStateActions() ) {
out <<
" switch ( " << FSA() << "[" << CS() << "] ) {\n";
FROM_STATE_ACTION_SWITCH();
TRANSITIONS() <<
"\n";
- if ( anyRegActions() )
+ if ( redFsm->anyRegActions() )
EXEC_ACTIONS() << "\n";
out << "_again:\n";
- if ( anyToStateActions() ) {
+ if ( redFsm->anyToStateActions() ) {
out <<
" switch ( " << TSA() << "[" << CS() << "] ) {\n";
TO_STATE_ACTION_SWITCH();
void FGotoCodeGen::writeOutEOF()
{
- if ( anyEofActions() ) {
+ if ( redFsm->anyEofActions() ) {
out <<
" {\n"
" switch ( " << EA() << "[" << CS() << "] ) {\n";
{
/* If there are any transtion functions then output the array. If there
* are none, don't bother emitting an empty array that won't be used. */
- if ( anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActArrItem), A() );
+ if ( redFsm->anyActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
ACTIONS_ARRAY();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyConditions() ) {
+ if ( redFsm->anyConditions() ) {
OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
COND_KEYS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCondSpan), CSP() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() );
COND_KEY_SPANS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCond), C() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() );
CONDS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCondIndexOffset), CO() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() );
COND_INDEX_OFFSET();
CLOSE_ARRAY() <<
"\n";
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxSpan), SP() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() );
KEY_SPANS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxFlatIndexOffset), IO() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() );
FLAT_INDEX_OFFSET();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxIndex), I() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
INDICIES();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS();
CLOSE_ARRAY() <<
"\n";
- if ( anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TA() );
+ if ( redFsm->anyActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
TRANS_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
TO_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
FROM_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), EA() );
+ if ( redFsm->anyEofActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
EOF_ACTIONS();
CLOSE_ARRAY() <<
"\n";
" {\n"
" int _slen";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << ", _ps";
out <<
";\n"
" int _trans";
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
out << ", _cond";
out << ";\n";
- if ( anyToStateActions() || anyRegActions() || anyFromStateActions() ) {
+ if ( redFsm->anyToStateActions() ||
+ redFsm->anyRegActions() || redFsm->anyFromStateActions() )
+ {
out <<
- " " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts;\n"
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
" " << UINT() << " _nacts;\n";
}
out <<
" " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
- " " << PTR_CONST() << ARRAY_TYPE(maxIndex) << POINTER() << "_inds;\n";
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << "_inds;\n";
- if ( anyConditions() ) {
+ if ( redFsm->anyConditions() ) {
out <<
- " " << PTR_CONST() << ARRAY_TYPE(maxCond) << POINTER() << "_conds;\n"
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxCond) << POINTER() << "_conds;\n"
" " << WIDE_ALPH_TYPE() << " _widec;\n";
}
" goto _out;\n";
}
- if ( anyFromStateActions() ) {
+ if ( redFsm->anyFromStateActions() ) {
out <<
" _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
" _nacts = " << CAST(UINT()) << " *_acts++;\n"
"\n";
}
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
COND_TRANSLATE();
LOCATE_TRANS();
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << " _ps = " << CS() << ";\n";
out <<
" " << CS() << " = " << TT() << "[_trans];\n"
"\n";
- if ( anyRegActions() ) {
+ if ( redFsm->anyRegActions() ) {
out <<
" if ( " << TA() << "[_trans] == 0 )\n"
" goto _again;\n"
"\n";
}
- if ( anyRegActions() || anyActionGotos() || anyActionCalls() || anyActionRets() )
+ if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
+ redFsm->anyActionCalls() || redFsm->anyActionRets() )
out << "_again:\n";
- if ( anyToStateActions() ) {
+ if ( redFsm->anyToStateActions() ) {
out <<
" _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
" _nacts = " << CAST(UINT()) << " *_acts++;\n"
void FlatCodeGen::writeOutEOF()
{
- if ( anyEofActions() ) {
+ if ( redFsm->anyEofActions() ) {
out <<
" {\n"
- " " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts = " <<
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts = " <<
ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
" " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
" while ( _nacts-- > 0 ) {\n"
:
cgd(0),
redFsm(0),
- out(out),
- bAnyToStateActions(false),
- bAnyFromStateActions(false),
- bAnyRegActions(false),
- bAnyEofActions(false),
- bAnyActionGotos(false),
- bAnyActionCalls(false),
- bAnyActionRets(false),
- bAnyRegActionRets(false),
- bAnyRegActionByValControl(false),
- bAnyRegNextStmt(false),
- bAnyRegCurStateRef(false),
- bAnyRegBreak(false),
- bAnyLmSwitchError(false),
- bAnyConditions(false)
+ out(out)
{
}
-/* Does the machine have any actions. */
-bool FsmCodeGen::anyActions()
-{
- return redFsm->actionMap.length() > 0;
-}
-
unsigned int FsmCodeGen::arrayTypeSize( unsigned long maxVal )
{
long long maxValLL = (long long) maxVal;
string FsmCodeGen::GET_WIDE_KEY()
{
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
return "_widec";
else
return GET_KEY();
out << "\t" << CS() << " = " << START() << ";\n";
/* If there are any calls, then the stack top needs initialization. */
- if ( anyActionCalls() || anyActionRets() )
+ if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )
out << "\t" << TOP() << " = 0;\n";
if ( cgd->hasLongestMatch ) {
string FsmCodeGen::WIDE_ALPH_TYPE()
{
string ret;
- if ( maxKey <= keyOps->maxKey )
+ if ( redFsm->maxKey <= keyOps->maxKey )
ret = ALPH_TYPE();
else {
- long long maxKeyVal = maxKey.getLongLong();
+ long long maxKeyVal = redFsm->maxKey.getLongLong();
HostType *wideType = keyOps->typeSubsumes( keyOps->isSigned, maxKeyVal );
assert( wideType != 0 );
unsigned int arrayTypeSize( unsigned long maxVal );
- bool anyActions();
- bool anyToStateActions() { return bAnyToStateActions; }
- bool anyFromStateActions() { return bAnyFromStateActions; }
- bool anyRegActions() { return bAnyRegActions; }
- bool anyEofActions() { return bAnyEofActions; }
- bool anyActionGotos() { return bAnyActionGotos; }
- bool anyActionCalls() { return bAnyActionCalls; }
- bool anyActionRets() { return bAnyActionRets; }
- bool anyRegActionRets() { return bAnyRegActionRets; }
- bool anyRegActionByValControl() { return bAnyRegActionByValControl; }
- bool anyRegNextStmt() { return bAnyRegNextStmt; }
- bool anyRegCurStateRef() { return bAnyRegCurStateRef; }
- bool anyRegBreak() { return bAnyRegBreak; }
- bool anyLmSwitchError() { return bAnyLmSwitchError; }
- bool anyConditions() { return bAnyConditions; }
-
/* Set up labelNeeded flag for each state. Differs for each goto style so
* is virtual. */
virtual void setLabelsNeeded() {}
protected:
ostream &out;
- bool bAnyToStateActions;
- bool bAnyFromStateActions;
- bool bAnyRegActions;
- bool bAnyEofActions;
- bool bAnyActionGotos;
- bool bAnyActionCalls;
- bool bAnyActionRets;
- bool bAnyRegActionRets;
- bool bAnyRegActionByValControl;
- bool bAnyRegNextStmt;
- bool bAnyRegCurStateRef;
- bool bAnyRegBreak;
- bool bAnyLmSwitchError;
- bool bAnyConditions;
-
- int maxState;
- int maxSingleLen;
- int maxRangeLen;
- int maxKeyOffset;
- int maxIndexOffset;
- int maxIndex;
- int maxActListId;
- int maxActionLoc;
- int maxActArrItem;
- unsigned long long maxSpan;
- unsigned long long maxCondSpan;
- int maxFlatIndexOffset;
- Key maxKey;
- int maxCondOffset;
- int maxCondLen;
- int maxCondSpaceId;
- int maxCondIndexOffset;
- int maxCond;
-
bool useIndicies;
};
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
int totalIndex = st->outSingle.length() + st->outRange.length() +
(st->defTrans == 0 ? 0 : 1);
- sizeWithInds += arrayTypeSize(maxIndex) * totalIndex;
+ sizeWithInds += arrayTypeSize(redFsm->maxIndex) * totalIndex;
}
- sizeWithInds += arrayTypeSize(maxState) * redFsm->transSet.length();
- if ( anyActions() )
- sizeWithInds += arrayTypeSize(maxActListId) * redFsm->transSet.length();
+ sizeWithInds += arrayTypeSize(redFsm->maxState) * redFsm->transSet.length();
+ if ( redFsm->anyActions() )
+ sizeWithInds += arrayTypeSize(redFsm->maxActListId) * redFsm->transSet.length();
/* Calculate the cost of not using indicies. */
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
int totalIndex = st->outSingle.length() + st->outRange.length() +
(st->defTrans == 0 ? 0 : 1);
- sizeWithoutInds += arrayTypeSize(maxState) * totalIndex;
- if ( anyActions() )
- sizeWithoutInds += arrayTypeSize(maxActListId) * totalIndex;
+ sizeWithoutInds += arrayTypeSize(redFsm->maxState) * totalIndex;
+ if ( redFsm->anyActions() )
+ sizeWithoutInds += arrayTypeSize(redFsm->maxActListId) * totalIndex;
}
/* If using indicies reduces the size, use them. */
void FTabCodeGen::writeOutData()
{
- if ( anyConditions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxCondOffset), CO() );
+ if ( redFsm->anyConditions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
COND_OFFSETS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCondLen), CL() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
COND_LENS();
CLOSE_ARRAY() <<
"\n";
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCondSpaceId), C() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
COND_SPACES();
CLOSE_ARRAY() <<
"\n";
}
- OPEN_ARRAY( ARRAY_TYPE(maxKeyOffset), KO() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
KEY_OFFSETS();
CLOSE_ARRAY() <<
"\n";
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxSingleLen), SL() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
SINGLE_LENS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxRangeLen), RL() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
RANGE_LENS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxIndexOffset), IO() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
INDEX_OFFSETS();
CLOSE_ARRAY() <<
"\n";
if ( useIndicies ) {
- OPEN_ARRAY( ARRAY_TYPE(maxIndex), I() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
INDICIES();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS_WI();
CLOSE_ARRAY() <<
"\n";
- if ( anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActListId), TA() );
+ if ( redFsm->anyActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() );
TRANS_ACTIONS_WI();
CLOSE_ARRAY() <<
"\n";
}
}
else {
- OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS();
CLOSE_ARRAY() <<
"\n";
- if ( anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActListId), TA() );
+ if ( redFsm->anyActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() );
TRANS_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
}
- if ( anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
TO_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
FROM_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActListId), EA() );
+ if ( redFsm->anyEofActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), EA() );
EOF_ACTIONS();
CLOSE_ARRAY() <<
"\n";
" {\n"
" int _klen";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << ", _ps";
out <<
" " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
" int _trans;\n";
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
out << "\n";
" goto _out;\n";
}
- if ( anyFromStateActions() ) {
+ if ( redFsm->anyFromStateActions() ) {
out <<
" switch ( " << FSA() << "[" << CS() << "] ) {\n";
FROM_STATE_ACTION_SWITCH();
"\n";
}
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
COND_TRANSLATE();
LOCATE_TRANS();
out << "_match:\n";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << " _ps = " << CS() << ";\n";
if ( useIndicies )
" " << CS() << " = " << TT() << "[_trans];\n"
"\n";
- if ( anyRegActions() ) {
+ if ( redFsm->anyRegActions() ) {
out <<
" if ( " << TA() << "[_trans] == 0 )\n"
" goto _again;\n"
"\n";
}
- if ( anyRegActions() || anyActionGotos() || anyActionCalls() || anyActionRets() )
+ if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
+ redFsm->anyActionCalls() || redFsm->anyActionRets() )
out << "_again:\n";
- if ( anyToStateActions() ) {
+ if ( redFsm->anyToStateActions() ) {
out <<
" switch ( " << TSA() << "[" << CS() << "] ) {\n";
TO_STATE_ACTION_SWITCH();
void FTabCodeGen::writeOutEOF()
{
- if ( anyEofActions() ) {
+ if ( redFsm->anyEofActions() ) {
out <<
" {\n"
" switch ( " << EA() << "[" << CS() << "] ) {\n";
/* Only consider actions that are referenced. */
if ( act->numRefs() > 0 ) {
if ( item->type == InlineItem::Goto || item->type == InlineItem::GotoExpr )
- codeGen->bAnyActionGotos = true;
+ redFsm->bAnyActionGotos = true;
else if ( item->type == InlineItem::Call || item->type == InlineItem::CallExpr )
- codeGen->bAnyActionCalls = true;
+ redFsm->bAnyActionCalls = true;
else if ( item->type == InlineItem::Ret )
- codeGen->bAnyActionRets = true;
+ redFsm->bAnyActionRets = true;
}
/* Check for various things in regular actions. */
if ( act->numTransRefs > 0 || act->numToStateRefs > 0 || act->numFromStateRefs > 0 ) {
/* Any returns in regular actions? */
if ( item->type == InlineItem::Ret )
- codeGen->bAnyRegActionRets = true;
+ redFsm->bAnyRegActionRets = true;
/* Any next statements in the regular actions? */
if ( item->type == InlineItem::Next || item->type == InlineItem::NextExpr )
- codeGen->bAnyRegNextStmt = true;
+ redFsm->bAnyRegNextStmt = true;
/* Any by value control in regular actions? */
if ( item->type == InlineItem::CallExpr || item->type == InlineItem::GotoExpr )
- codeGen->bAnyRegActionByValControl = true;
+ redFsm->bAnyRegActionByValControl = true;
/* Any references to the current state in regular actions? */
if ( item->type == InlineItem::Curs )
- codeGen->bAnyRegCurStateRef = true;
+ redFsm->bAnyRegCurStateRef = true;
if ( item->type == InlineItem::Break )
- codeGen->bAnyRegBreak = true;
+ redFsm->bAnyRegBreak = true;
if ( item->type == InlineItem::LmSwitch && item->handlesError )
- codeGen->bAnyLmSwitchError = true;
+ redFsm->bAnyLmSwitchError = true;
}
if ( item->children != 0 )
void CodeGenData::setValueLimits()
{
- codeGen->maxSingleLen = 0;
- codeGen->maxRangeLen = 0;
- codeGen->maxKeyOffset = 0;
- codeGen->maxIndexOffset = 0;
- codeGen->maxActListId = 0;
- codeGen->maxActionLoc = 0;
- codeGen->maxActArrItem = 0;
- codeGen->maxSpan = 0;
- codeGen->maxCondSpan = 0;
- codeGen->maxFlatIndexOffset = 0;
- codeGen->maxCondOffset = 0;
- codeGen->maxCondLen = 0;
- codeGen->maxCondSpaceId = 0;
- codeGen->maxCondIndexOffset = 0;
+ redFsm->maxSingleLen = 0;
+ redFsm->maxRangeLen = 0;
+ redFsm->maxKeyOffset = 0;
+ redFsm->maxIndexOffset = 0;
+ redFsm->maxActListId = 0;
+ redFsm->maxActionLoc = 0;
+ redFsm->maxActArrItem = 0;
+ redFsm->maxSpan = 0;
+ redFsm->maxCondSpan = 0;
+ redFsm->maxFlatIndexOffset = 0;
+ redFsm->maxCondOffset = 0;
+ redFsm->maxCondLen = 0;
+ redFsm->maxCondSpaceId = 0;
+ redFsm->maxCondIndexOffset = 0;
/* In both of these cases the 0 index is reserved for no value, so the max
* is one more than it would be if they started at 0. */
- codeGen->maxIndex = redFsm->transSet.length();
- codeGen->maxCond = cgd->condSpaceList.length();
+ redFsm->maxIndex = redFsm->transSet.length();
+ redFsm->maxCond = cgd->condSpaceList.length();
/* The nextStateId - 1 is the last state id assigned. */
- codeGen->maxState = redFsm->nextStateId - 1;
+ redFsm->maxState = redFsm->nextStateId - 1;
for ( CondSpaceList::Iter csi = cgd->condSpaceList; csi.lte(); csi++ ) {
- if ( csi->condSpaceId > codeGen->maxCondSpaceId )
- codeGen->maxCondSpaceId = csi->condSpaceId;
+ if ( csi->condSpaceId > redFsm->maxCondSpaceId )
+ redFsm->maxCondSpaceId = csi->condSpaceId;
}
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Maximum cond length. */
- if ( st->stateCondList.length() > codeGen->maxCondLen )
- codeGen->maxCondLen = st->stateCondList.length();
+ if ( st->stateCondList.length() > redFsm->maxCondLen )
+ redFsm->maxCondLen = st->stateCondList.length();
/* Maximum single length. */
- if ( st->outSingle.length() > codeGen->maxSingleLen )
- codeGen->maxSingleLen = st->outSingle.length();
+ if ( st->outSingle.length() > redFsm->maxSingleLen )
+ redFsm->maxSingleLen = st->outSingle.length();
/* Maximum range length. */
- if ( st->outRange.length() > codeGen->maxRangeLen )
- codeGen->maxRangeLen = st->outRange.length();
+ if ( st->outRange.length() > redFsm->maxRangeLen )
+ redFsm->maxRangeLen = st->outRange.length();
/* The key offset index offset for the state after last is not used, skip it.. */
if ( ! st.last() ) {
- codeGen->maxCondOffset += st->stateCondList.length();
- codeGen->maxKeyOffset += st->outSingle.length() + st->outRange.length()*2;
- codeGen->maxIndexOffset += st->outSingle.length() + st->outRange.length() + 1;
+ redFsm->maxCondOffset += st->stateCondList.length();
+ redFsm->maxKeyOffset += st->outSingle.length() + st->outRange.length()*2;
+ redFsm->maxIndexOffset += st->outSingle.length() + st->outRange.length() + 1;
}
/* Max cond span. */
if ( st->condList != 0 ) {
unsigned long long span = keyOps->span( st->condLowKey, st->condHighKey );
- if ( span > codeGen->maxCondSpan )
- codeGen->maxCondSpan = span;
+ if ( span > redFsm->maxCondSpan )
+ redFsm->maxCondSpan = span;
}
/* Max key span. */
if ( st->transList != 0 ) {
unsigned long long span = keyOps->span( st->lowKey, st->highKey );
- if ( span > codeGen->maxSpan )
- codeGen->maxSpan = span;
+ if ( span > redFsm->maxSpan )
+ redFsm->maxSpan = span;
}
/* Max cond index offset. */
if ( ! st.last() ) {
if ( st->condList != 0 )
- codeGen->maxCondIndexOffset += keyOps->span( st->condLowKey, st->condHighKey );
+ redFsm->maxCondIndexOffset += keyOps->span( st->condLowKey, st->condHighKey );
}
/* Max flat index offset. */
if ( ! st.last() ) {
if ( st->transList != 0 )
- codeGen->maxFlatIndexOffset += keyOps->span( st->lowKey, st->highKey );
- codeGen->maxFlatIndexOffset += 1;
+ redFsm->maxFlatIndexOffset += keyOps->span( st->lowKey, st->highKey );
+ redFsm->maxFlatIndexOffset += 1;
}
}
for ( ActionTableMap::Iter at = redFsm->actionMap; at.lte(); at++ ) {
/* Maximum id of action lists. */
- if ( at->actListId+1 > codeGen->maxActListId )
- codeGen->maxActListId = at->actListId+1;
+ if ( at->actListId+1 > redFsm->maxActListId )
+ redFsm->maxActListId = at->actListId+1;
/* Maximum location of items in action array. */
- if ( at->location+1 > codeGen->maxActionLoc )
- codeGen->maxActionLoc = at->location+1;
+ if ( at->location+1 > redFsm->maxActionLoc )
+ redFsm->maxActionLoc = at->location+1;
/* Maximum values going into the action array. */
- if ( at->key.length() > codeGen->maxActArrItem )
- codeGen->maxActArrItem = at->key.length();
+ if ( at->key.length() > redFsm->maxActArrItem )
+ redFsm->maxActArrItem = at->key.length();
for ( ActionTable::Iter item = at->key; item.lte(); item++ ) {
- if ( item->value->actionId > codeGen->maxActArrItem )
- codeGen->maxActArrItem = item->value->actionId;
+ if ( item->value->actionId > redFsm->maxActArrItem )
+ redFsm->maxActArrItem = item->value->actionId;
}
}
}
for ( ActionList::Iter act = cgd->actionList; act.lte(); act++ ) {
/* Record the occurrence of various kinds of actions. */
if ( act->numToStateRefs > 0 )
- codeGen->bAnyToStateActions = true;
+ redFsm->bAnyToStateActions = true;
if ( act->numFromStateRefs > 0 )
- codeGen->bAnyFromStateActions = true;
+ redFsm->bAnyFromStateActions = true;
if ( act->numEofRefs > 0 )
- codeGen->bAnyEofActions = true;
+ redFsm->bAnyEofActions = true;
if ( act->numTransRefs > 0 )
- codeGen->bAnyRegActions = true;
+ redFsm->bAnyRegActions = true;
/* Recurse through the action's parse tree looking for various things. */
analyzeAction( act, act->inlineList );
st->bAnyRegCurStateRef = true;
if ( st->stateCondList.length() > 0 )
- codeGen->bAnyConditions = true;
+ redFsm->bAnyConditions = true;
}
/* Assign ids to actions that are referenced. */
* other things. We will use these in reporting the usage
* of fsm directives in action code. */
analyzeMachine();
- codeGen->maxKey = maxKey;
+ redFsm->maxKey = maxKey;
}
void CodeGenData::generateGraphviz()
"\n";
}
- if ( anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActArrItem), A() );
+ if ( redFsm->anyActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
ACTIONS_ARRAY();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
TO_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
FROM_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), EA() );
+ if ( redFsm->anyEofActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
EOF_ACTIONS();
CLOSE_ARRAY() <<
"\n";
out << " {\n";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << " int _ps = 0;\n";
- if ( anyToStateActions() || anyRegActions() || anyFromStateActions() ) {
+ if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
+ || redFsm->anyFromStateActions() )
+ {
out <<
- " " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts;\n"
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
" " << UINT() << " _nacts;\n";
}
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
out << "\n";
out << "_resume:\n";
- if ( anyFromStateActions() ) {
+ if ( redFsm->anyFromStateActions() ) {
out <<
" _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
" _nacts = " << CAST(UINT()) << " *_acts++;\n"
TRANSITIONS() <<
"\n";
- if ( anyRegActions() )
+ if ( redFsm->anyRegActions() )
EXEC_FUNCS() << "\n";
out << "_again:\n";
- if ( anyToStateActions() ) {
+ if ( redFsm->anyToStateActions() ) {
out <<
" _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
" _nacts = " << CAST(UINT()) << " *_acts++;\n"
void GotoCodeGen::writeOutEOF()
{
- if ( anyEofActions() ) {
+ if ( redFsm->anyEofActions() ) {
out <<
" {\n"
- " " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts = " <<
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts = " <<
ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
" " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
" while ( _nacts-- > 0 ) {\n"
#include "gendata.h"
#include "bstmap.h"
+bool IpGotoCodeGen::useAgainLabel()
+{
+ return redFsm->anyRegActionRets() ||
+ redFsm->anyRegActionByValControl() ||
+ redFsm->anyRegNextStmt();
+}
+
void IpGotoCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish )
{
ret << "{" << CTRL_FLOW() << "goto st" << gotoDest << ";}";
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
st->labelNeeded = false;
- if ( redFsm->errState != 0 && anyLmSwitchError() )
+ if ( redFsm->errState != 0 && redFsm->anyLmSwitchError() )
redFsm->errState->labelNeeded = true;
/* Walk all transitions and set only those that have targs. */
out << " {\n";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << " int _ps = 0;\n";
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
if ( cgd->hasEnd ) {
void IpGotoCodeGen::writeOutEOF()
{
- if ( anyEofActions() ) {
+ if ( redFsm->anyEofActions() ) {
out <<
" {\n"
" switch ( " << CS() << " ) {\n";
virtual void writeOutExec();
protected:
- bool useAgainLabel()
- { return anyRegActionRets() || anyRegActionByValControl() || anyRegNextStmt(); }
+ bool useAgainLabel();
/* Called from GotoCodeGen::STATE_GOTOS just before writing the gotos for
* each state. */
" {\n"
" int _klen";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << ", _ps";
out <<
";\n"
" int _trans;\n";
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
out << " int _widec;\n";
- if ( anyToStateActions() || anyRegActions() || anyFromStateActions() ) {
+ if ( redFsm->anyToStateActions() || redFsm->anyRegActions() ||
+ redFsm->anyFromStateActions() )
+ {
out <<
" int _acts;\n"
" int _nacts;\n";
" break _resume;\n";
}
- if ( anyFromStateActions() ) {
+ if ( redFsm->anyFromStateActions() ) {
out <<
" _acts = " << FSA() << "[" << CS() << "]" << ";\n"
" _nacts = " << CAST("int") << " " << A() << "[_acts++];\n"
"\n";
}
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
COND_TRANSLATE();
LOCATE_TRANS();
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << " _ps = " << CS() << ";\n";
if ( useIndicies )
" " << CS() << " = " << TT() << "[_trans];\n"
"\n";
- if ( anyRegActions() ) {
+ if ( redFsm->anyRegActions() ) {
out <<
" if ( " << TA() << "[_trans] == 0 )\n"
" break _again;\n"
/* Again loop, functions as again label. */
out << " } while (false);\n";
- if ( anyToStateActions() ) {
+ if ( redFsm->anyToStateActions() ) {
out <<
" _acts = " << TSA() << "[" << CS() << "]" << ";\n"
" _nacts = " << CAST("int") << " " << A() << "[_acts++];\n"
void JavaTabCodeGen::writeOutEOF()
{
- if ( anyEofActions() ) {
+ if ( redFsm->anyEofActions() ) {
out <<
" int _acts = " << EA() << "[" << CS() << "]" << ";\n"
" int _nacts = " << CAST("int") << " " << A() << "[_acts++];\n"
errState(0),
errTrans(0),
firstFinState(0),
- numFinStates(0)
+ numFinStates(0),
+ bAnyToStateActions(false),
+ bAnyFromStateActions(false),
+ bAnyRegActions(false),
+ bAnyEofActions(false),
+ bAnyActionGotos(false),
+ bAnyActionCalls(false),
+ bAnyActionRets(false),
+ bAnyRegActionRets(false),
+ bAnyRegActionByValControl(false),
+ bAnyRegNextStmt(false),
+ bAnyRegCurStateRef(false),
+ bAnyRegBreak(false),
+ bAnyLmSwitchError(false),
+ bAnyConditions(false)
{
}
+/* Does the machine have any actions. */
+bool RedFsmAp::anyActions()
+{
+ return actionMap.length() > 0;
+}
+
void RedFsmAp::depthFirstOrdering( RedStateAp *state )
{
/* Nothing to do if the state is already on the list. */
int numFinStates;
int nParts;
+ bool bAnyToStateActions;
+ bool bAnyFromStateActions;
+ bool bAnyRegActions;
+ bool bAnyEofActions;
+ bool bAnyActionGotos;
+ bool bAnyActionCalls;
+ bool bAnyActionRets;
+ bool bAnyRegActionRets;
+ bool bAnyRegActionByValControl;
+ bool bAnyRegNextStmt;
+ bool bAnyRegCurStateRef;
+ bool bAnyRegBreak;
+ bool bAnyLmSwitchError;
+ bool bAnyConditions;
+
+ int maxState;
+ int maxSingleLen;
+ int maxRangeLen;
+ int maxKeyOffset;
+ int maxIndexOffset;
+ int maxIndex;
+ int maxActListId;
+ int maxActionLoc;
+ int maxActArrItem;
+ unsigned long long maxSpan;
+ unsigned long long maxCondSpan;
+ int maxFlatIndexOffset;
+ Key maxKey;
+ int maxCondOffset;
+ int maxCondLen;
+ int maxCondSpaceId;
+ int maxCondIndexOffset;
+ int maxCond;
+
+ bool anyActions();
+ bool anyToStateActions() { return bAnyToStateActions; }
+ bool anyFromStateActions() { return bAnyFromStateActions; }
+ bool anyRegActions() { return bAnyRegActions; }
+ bool anyEofActions() { return bAnyEofActions; }
+ bool anyActionGotos() { return bAnyActionGotos; }
+ bool anyActionCalls() { return bAnyActionCalls; }
+ bool anyActionRets() { return bAnyActionRets; }
+ bool anyRegActionRets() { return bAnyRegActionRets; }
+ bool anyRegActionByValControl() { return bAnyRegActionByValControl; }
+ bool anyRegNextStmt() { return bAnyRegNextStmt; }
+ bool anyRegCurStateRef() { return bAnyRegCurStateRef; }
+ bool anyRegBreak() { return bAnyRegBreak; }
+ bool anyLmSwitchError() { return bAnyLmSwitchError; }
+ bool anyConditions() { return bAnyConditions; }
+
+
/* Is is it possible to extend a range by bumping ranges that span only
* one character to the singles array. */
bool canExtend( const RedTransList &list, int pos );
out << " " << ALPH_TYPE() << " *p = *_pp, *pe = *_ppe;\n";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << " int _ps = 0;\n";
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
if ( useAgainLabel() ) {
for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
trans->labelNeeded = false;
- if ( redFsm->errState != 0 && anyLmSwitchError() )
+ if ( redFsm->errState != 0 && redFsm->anyLmSwitchError() )
redFsm->errState->labelNeeded = true;
/* Walk all transitions and set only those that have targs. */
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
int totalIndex = st->outSingle.length() + st->outRange.length() +
(st->defTrans == 0 ? 0 : 1);
- sizeWithInds += arrayTypeSize(maxIndex) * totalIndex;
+ sizeWithInds += arrayTypeSize(redFsm->maxIndex) * totalIndex;
}
- sizeWithInds += arrayTypeSize(maxState) * redFsm->transSet.length();
- if ( anyActions() )
- sizeWithInds += arrayTypeSize(maxActionLoc) * redFsm->transSet.length();
+ sizeWithInds += arrayTypeSize(redFsm->maxState) * redFsm->transSet.length();
+ if ( redFsm->anyActions() )
+ sizeWithInds += arrayTypeSize(redFsm->maxActionLoc) * redFsm->transSet.length();
/* Calculate the cost of not using indicies. */
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
int totalIndex = st->outSingle.length() + st->outRange.length() +
(st->defTrans == 0 ? 0 : 1);
- sizeWithoutInds += arrayTypeSize(maxState) * totalIndex;
- if ( anyActions() )
- sizeWithoutInds += arrayTypeSize(maxActionLoc) * totalIndex;
+ sizeWithoutInds += arrayTypeSize(redFsm->maxState) * totalIndex;
+ if ( redFsm->anyActions() )
+ sizeWithoutInds += arrayTypeSize(redFsm->maxActionLoc) * totalIndex;
}
/* If using indicies reduces the size, use them. */
{
/* If there are any transtion functions then output the array. If there
* are none, don't bother emitting an empty array that won't be used. */
- if ( anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActArrItem), A() );
+ if ( redFsm->anyActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
ACTIONS_ARRAY();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyConditions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxCondOffset), CO() );
+ if ( redFsm->anyConditions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
COND_OFFSETS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCondLen), CL() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
COND_LENS();
CLOSE_ARRAY() <<
"\n";
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxCondSpaceId), C() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
COND_SPACES();
CLOSE_ARRAY() <<
"\n";
}
- OPEN_ARRAY( ARRAY_TYPE(maxKeyOffset), KO() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
KEY_OFFSETS();
CLOSE_ARRAY() <<
"\n";
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxSingleLen), SL() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
SINGLE_LENS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxRangeLen), RL() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
RANGE_LENS();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxIndexOffset), IO() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
INDEX_OFFSETS();
CLOSE_ARRAY() <<
"\n";
if ( useIndicies ) {
- OPEN_ARRAY( ARRAY_TYPE(maxIndex), I() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
INDICIES();
CLOSE_ARRAY() <<
"\n";
- OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS_WI();
CLOSE_ARRAY() <<
"\n";
- if ( anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TA() );
+ if ( redFsm->anyActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
TRANS_ACTIONS_WI();
CLOSE_ARRAY() <<
"\n";
}
}
else {
- OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS();
CLOSE_ARRAY() <<
"\n";
- if ( anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TA() );
+ if ( redFsm->anyActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
TRANS_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
}
- if ( anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
TO_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
FROM_STATE_ACTIONS();
CLOSE_ARRAY() <<
"\n";
}
- if ( anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), EA() );
+ if ( redFsm->anyEofActions() ) {
+ OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
EOF_ACTIONS();
CLOSE_ARRAY() <<
"\n";
" {\n"
" int _klen";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << ", _ps";
out <<
";\n"
" " << UINT() << " _trans;\n";
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
- if ( anyToStateActions() || anyRegActions() || anyFromStateActions() ) {
+ if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
+ || redFsm->anyFromStateActions() )
+ {
out <<
- " " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts;\n"
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
" " << UINT() << " _nacts;\n";
}
" goto _out;\n";
}
- if ( anyFromStateActions() ) {
+ if ( redFsm->anyFromStateActions() ) {
out <<
" _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
" _nacts = " << CAST(UINT()) << " *_acts++;\n"
"\n";
}
- if ( anyConditions() )
+ if ( redFsm->anyConditions() )
COND_TRANSLATE();
LOCATE_TRANS();
out << "_match:\n";
- if ( anyRegCurStateRef() )
+ if ( redFsm->anyRegCurStateRef() )
out << " _ps = " << CS() << ";\n";
if ( useIndicies )
" " << CS() << " = " << TT() << "[_trans];\n"
"\n";
- if ( anyRegActions() ) {
+ if ( redFsm->anyRegActions() ) {
out <<
" if ( " << TA() << "[_trans] == 0 )\n"
" goto _again;\n"
"\n";
}
- if ( anyRegActions() || anyActionGotos() || anyActionCalls() || anyActionRets() )
+ if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
+ redFsm->anyActionCalls() || redFsm->anyActionRets() )
out << "_again:\n";
- if ( anyToStateActions() ) {
+ if ( redFsm->anyToStateActions() ) {
out <<
" _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
" _nacts = " << CAST(UINT()) << " *_acts++;\n"
void TabCodeGen::writeOutEOF()
{
- if ( anyEofActions() ) {
+ if ( redFsm->anyEofActions() ) {
out <<
" {\n"
- " " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts = " <<
+ " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts = " <<
ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
" " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
" while ( _nacts-- > 0 ) {\n"