-void TabCodeGen::COND_TRANSLATE()
-{
- out <<
- " _widec = " << GET_KEY() << ";\n"
- " _klen = " << CL() << "[" << CS() << "];\n"
- " _keys = " << ARR_OFF( CK(), "(" + CO() + "[" + CS() + "]*2)" ) << ";\n"
- " if ( _klen > 0 ) {\n"
- " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
- " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
- " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
- " while (1) {\n"
- " if ( _upper < _lower )\n"
- " break;\n"
- "\n"
- " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
- " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
- " _upper = _mid - 2;\n"
- " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
- " _lower = _mid + 2;\n"
- " else {\n"
- " switch ( " << C() << "[" << CO() << "[" << CS() << "]"
- " + ((_mid - _keys)>>1)] ) {\n";
-
- for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
- CondSpace *condSpace = csi;
- out << " case " << condSpace->condSpaceId << ": {\n";
- out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
- KEY(condSpace->baseKey) << " + (" << GET_KEY() <<
- " - " << KEY(keyOps->minKey) << "));\n";
-
- for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
- out << TABS(2) << "if ( ";
- CONDITION( out, *csi );
- Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
- out << " ) _widec += " << condValOffset << ";\n";
- }
-
- out <<
- " break;\n"
- " }\n";
- }
-
- SWITCH_DEFAULT();
-
- out <<
- " }\n"
- " break;\n"
- " }\n"
- " }\n"
- " }\n"
- "\n";
-}
-
-void TabCodeGen::writeOutExec()
-{
- outLabelUsed = false;
-
- out <<
- " {\n"
- " int _klen";
-
- if ( redFsm->anyRegCurStateRef() )
- out << ", _ps";
-
- out <<
- ";\n"
- " " << UINT() << " _trans;\n";
-
- if ( redFsm->anyConditions() )
- out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
-
- if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
- || redFsm->anyFromStateActions() )
- {
- out <<
- " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
- " " << UINT() << " _nacts;\n";
- }
-
- out <<
- " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
- "\n";
-
- if ( hasEnd ) {
- outLabelUsed = true;
- out <<
- " if ( " << P() << " == " << PE() << " )\n"
- " goto _out;\n";
- }
-
- out << "_resume:\n";
-
- if ( redFsm->errState != 0 ) {
- outLabelUsed = true;
- out <<
- " if ( " << CS() << " == " << redFsm->errState->id << " )\n"
- " goto _out;\n";
- }
-
- if ( redFsm->anyFromStateActions() ) {
- out <<
- " _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
- " _nacts = " << CAST(UINT()) << " *_acts++;\n"
- " while ( _nacts-- > 0 ) {\n"
- " switch ( *_acts++ ) {\n";
- FROM_STATE_ACTION_SWITCH();
- SWITCH_DEFAULT() <<
- " }\n"
- " }\n"
- "\n";
- }
-
- if ( redFsm->anyConditions() )
- COND_TRANSLATE();
-
- LOCATE_TRANS();
-
- out << "_match:\n";
-
- if ( redFsm->anyRegCurStateRef() )
- out << " _ps = " << CS() << ";\n";
-
- if ( useIndicies )
- out << " _trans = " << I() << "[_trans];\n";
-
- out <<
- " " << CS() << " = " << TT() << "[_trans];\n"
- "\n";
-
- if ( redFsm->anyRegActions() ) {
- out <<
- " if ( " << TA() << "[_trans] == 0 )\n"
- " goto _again;\n"
- "\n"
- " _acts = " << ARR_OFF( A(), TA() + "[_trans]" ) << ";\n"
- " _nacts = " << CAST(UINT()) << " *_acts++;\n"
- " while ( _nacts-- > 0 )\n {\n"
- " switch ( *_acts++ )\n {\n";
- ACTION_SWITCH();
- SWITCH_DEFAULT() <<
- " }\n"
- " }\n"
- "\n";
- }
-
- if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
- redFsm->anyActionCalls() || redFsm->anyActionRets() )
- out << "_again:\n";
-
- if ( redFsm->anyToStateActions() ) {
- out <<
- " _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
- " _nacts = " << CAST(UINT()) << " *_acts++;\n"
- " while ( _nacts-- > 0 ) {\n"
- " switch ( *_acts++ ) {\n";
- TO_STATE_ACTION_SWITCH();
- SWITCH_DEFAULT() <<
- " }\n"
- " }\n"
- "\n";
- }
-
- if ( hasEnd ) {
- out <<
- " if ( ++" << P() << " != " << PE() << " )\n"
- " goto _resume;\n";
- }
- else {
- out <<
- " " << P() << " += 1;\n"
- " goto _resume;\n";
- }
-
- if ( outLabelUsed )
- out << " _out: {}\n";
-
- out << " }\n";
-}
-
-
-void TabCodeGen::writeOutEOF()
-{
- if ( redFsm->anyEofActions() ) {
- out <<
- " {\n"
- " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts = " <<
- ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
- " " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
- " while ( _nacts-- > 0 ) {\n"
- " switch ( *_acts++ ) {\n";
- EOF_ACTION_SWITCH();
- SWITCH_DEFAULT() <<
- " }\n"
- " }\n"
- " }\n"
- "\n";
- }
-}