2 * Copyright 2001-2006 Adrian Thurston <thurston@cs.queensu.ca>
3 * 2004 Erich Ocean <eric.ocean@ampede.com>
4 * 2005 Alan West <alan@alanz.com>
7 /* This file is part of Ragel.
9 * Ragel is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Ragel is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Ragel; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "tabcodegen.h"
29 /* Determine if we should use indicies or not. */
30 void TabCodeGen::calcIndexSize()
32 int sizeWithInds = 0, sizeWithoutInds = 0;
34 /* Calculate cost of using with indicies. */
35 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
36 int totalIndex = st->outSingle.length() + st->outRange.length() +
37 (st->defTrans == 0 ? 0 : 1);
38 sizeWithInds += arrayTypeSize(redFsm->maxIndex) * totalIndex;
40 sizeWithInds += arrayTypeSize(redFsm->maxState) * redFsm->transSet.length();
41 if ( redFsm->anyActions() )
42 sizeWithInds += arrayTypeSize(redFsm->maxActionLoc) * redFsm->transSet.length();
44 /* Calculate the cost of not using indicies. */
45 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
46 int totalIndex = st->outSingle.length() + st->outRange.length() +
47 (st->defTrans == 0 ? 0 : 1);
48 sizeWithoutInds += arrayTypeSize(redFsm->maxState) * totalIndex;
49 if ( redFsm->anyActions() )
50 sizeWithoutInds += arrayTypeSize(redFsm->maxActionLoc) * totalIndex;
53 /* If using indicies reduces the size, use them. */
54 useIndicies = sizeWithInds < sizeWithoutInds;
57 std::ostream &TabCodeGen::TO_STATE_ACTION( RedStateAp *state )
60 if ( state->toStateAction != 0 )
61 act = state->toStateAction->location+1;
66 std::ostream &TabCodeGen::FROM_STATE_ACTION( RedStateAp *state )
69 if ( state->fromStateAction != 0 )
70 act = state->fromStateAction->location+1;
75 std::ostream &TabCodeGen::EOF_ACTION( RedStateAp *state )
78 if ( state->eofAction != 0 )
79 act = state->eofAction->location+1;
85 std::ostream &TabCodeGen::TRANS_ACTION( RedTransAp *trans )
87 /* If there are actions, emit them. Otherwise emit zero. */
89 if ( trans->action != 0 )
90 act = trans->action->location+1;
95 std::ostream &TabCodeGen::TO_STATE_ACTION_SWITCH()
97 /* Walk the list of functions, printing the cases. */
98 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
99 /* Write out referenced actions. */
100 if ( act->numToStateRefs > 0 ) {
101 /* Write the case label, the action and the case break. */
102 out << "\tcase " << act->actionId << ":\n";
103 ACTION( out, act, 0, false );
108 genLineDirective( out );
112 std::ostream &TabCodeGen::FROM_STATE_ACTION_SWITCH()
114 /* Walk the list of functions, printing the cases. */
115 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
116 /* Write out referenced actions. */
117 if ( act->numFromStateRefs > 0 ) {
118 /* Write the case label, the action and the case break. */
119 out << "\tcase " << act->actionId << ":\n";
120 ACTION( out, act, 0, false );
125 genLineDirective( out );
129 std::ostream &TabCodeGen::EOF_ACTION_SWITCH()
131 /* Walk the list of functions, printing the cases. */
132 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
133 /* Write out referenced actions. */
134 if ( act->numEofRefs > 0 ) {
135 /* Write the case label, the action and the case break. */
136 out << "\tcase " << act->actionId << ":\n";
137 ACTION( out, act, 0, true );
142 genLineDirective( out );
147 std::ostream &TabCodeGen::ACTION_SWITCH()
149 /* Walk the list of functions, printing the cases. */
150 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
151 /* Write out referenced actions. */
152 if ( act->numTransRefs > 0 ) {
153 /* Write the case label, the action and the case break. */
154 out << "\tcase " << act->actionId << ":\n";
155 ACTION( out, act, 0, false );
160 genLineDirective( out );
164 std::ostream &TabCodeGen::COND_OFFSETS()
167 int totalStateNum = 0, curKeyOffset = 0;
168 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
169 /* Write the key offset. */
173 if ( ++totalStateNum % IALL == 0 )
177 /* Move the key offset ahead. */
178 curKeyOffset += st->stateCondList.length();
184 std::ostream &TabCodeGen::KEY_OFFSETS()
187 int totalStateNum = 0, curKeyOffset = 0;
188 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
189 /* Write the key offset. */
193 if ( ++totalStateNum % IALL == 0 )
197 /* Move the key offset ahead. */
198 curKeyOffset += st->outSingle.length() + st->outRange.length()*2;
205 std::ostream &TabCodeGen::INDEX_OFFSETS()
208 int totalStateNum = 0, curIndOffset = 0;
209 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
210 /* Write the index offset. */
214 if ( ++totalStateNum % IALL == 0 )
218 /* Move the index offset ahead. */
219 curIndOffset += st->outSingle.length() + st->outRange.length();
220 if ( st->defTrans != 0 )
227 std::ostream &TabCodeGen::COND_LENS()
230 int totalStateNum = 0;
231 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
232 /* Write singles length. */
233 out << st->stateCondList.length();
236 if ( ++totalStateNum % IALL == 0 )
245 std::ostream &TabCodeGen::SINGLE_LENS()
248 int totalStateNum = 0;
249 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
250 /* Write singles length. */
251 out << st->outSingle.length();
254 if ( ++totalStateNum % IALL == 0 )
262 std::ostream &TabCodeGen::RANGE_LENS()
265 int totalStateNum = 0;
266 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
267 /* Emit length of range index. */
268 out << st->outRange.length();
271 if ( ++totalStateNum % IALL == 0 )
279 std::ostream &TabCodeGen::TO_STATE_ACTIONS()
282 int totalStateNum = 0;
283 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
284 /* Write any eof action. */
288 if ( ++totalStateNum % IALL == 0 )
296 std::ostream &TabCodeGen::FROM_STATE_ACTIONS()
299 int totalStateNum = 0;
300 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
301 /* Write any eof action. */
302 FROM_STATE_ACTION(st);
305 if ( ++totalStateNum % IALL == 0 )
313 std::ostream &TabCodeGen::EOF_ACTIONS()
316 int totalStateNum = 0;
317 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
318 /* Write any eof action. */
322 if ( ++totalStateNum % IALL == 0 )
330 std::ostream &TabCodeGen::EOF_TRANS()
333 int totalStateNum = 0;
334 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
335 /* Write any eof action. */
338 if ( st->eofTrans != 0 )
339 trans = st->eofTrans->id+1;
344 if ( ++totalStateNum % IALL == 0 )
353 std::ostream &TabCodeGen::COND_KEYS()
357 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
358 /* Loop the state's transitions. */
359 for ( StateCondList::Iter sc = st->stateCondList; sc.lte(); sc++ ) {
361 out << KEY( sc->lowKey ) << ", ";
362 if ( ++totalTrans % IALL == 0 )
366 out << KEY( sc->highKey ) << ", ";
367 if ( ++totalTrans % IALL == 0 )
372 /* Output one last number so we don't have to figure out when the last
373 * entry is and avoid writing a comma. */
378 std::ostream &TabCodeGen::COND_SPACES()
382 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
383 /* Loop the state's transitions. */
384 for ( StateCondList::Iter sc = st->stateCondList; sc.lte(); sc++ ) {
386 out << sc->condSpace->condSpaceId << ", ";
387 if ( ++totalTrans % IALL == 0 )
392 /* Output one last number so we don't have to figure out when the last
393 * entry is and avoid writing a comma. */
398 std::ostream &TabCodeGen::KEYS()
402 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
403 /* Loop the singles. */
404 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
405 out << KEY( stel->lowKey ) << ", ";
406 if ( ++totalTrans % IALL == 0 )
410 /* Loop the state's transitions. */
411 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
413 out << KEY( rtel->lowKey ) << ", ";
414 if ( ++totalTrans % IALL == 0 )
418 out << KEY( rtel->highKey ) << ", ";
419 if ( ++totalTrans % IALL == 0 )
424 /* Output one last number so we don't have to figure out when the last
425 * entry is and avoid writing a comma. */
430 std::ostream &TabCodeGen::INDICIES()
434 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
435 /* Walk the singles. */
436 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
437 out << stel->value->id << ", ";
438 if ( ++totalTrans % IALL == 0 )
442 /* Walk the ranges. */
443 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
444 out << rtel->value->id << ", ";
445 if ( ++totalTrans % IALL == 0 )
449 /* The state's default index goes next. */
450 if ( st->defTrans != 0 ) {
451 out << st->defTrans->id << ", ";
452 if ( ++totalTrans % IALL == 0 )
457 /* Output one last number so we don't have to figure out when the last
458 * entry is and avoid writing a comma. */
463 std::ostream &TabCodeGen::TRANS_TARGS()
467 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
468 /* Walk the singles. */
469 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
470 RedTransAp *trans = stel->value;
471 out << trans->targ->id << ", ";
472 if ( ++totalTrans % IALL == 0 )
476 /* Walk the ranges. */
477 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
478 RedTransAp *trans = rtel->value;
479 out << trans->targ->id << ", ";
480 if ( ++totalTrans % IALL == 0 )
484 /* The state's default target state. */
485 if ( st->defTrans != 0 ) {
486 RedTransAp *trans = st->defTrans;
487 out << trans->targ->id << ", ";
488 if ( ++totalTrans % IALL == 0 )
493 /* Output one last number so we don't have to figure out when the last
494 * entry is and avoid writing a comma. */
500 std::ostream &TabCodeGen::TRANS_ACTIONS()
504 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
505 /* Walk the singles. */
506 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
507 RedTransAp *trans = stel->value;
508 TRANS_ACTION( trans ) << ", ";
509 if ( ++totalTrans % IALL == 0 )
513 /* Walk the ranges. */
514 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
515 RedTransAp *trans = rtel->value;
516 TRANS_ACTION( trans ) << ", ";
517 if ( ++totalTrans % IALL == 0 )
521 /* The state's default index goes next. */
522 if ( st->defTrans != 0 ) {
523 RedTransAp *trans = st->defTrans;
524 TRANS_ACTION( trans ) << ", ";
525 if ( ++totalTrans % IALL == 0 )
530 /* Output one last number so we don't have to figure out when the last
531 * entry is and avoid writing a comma. */
536 std::ostream &TabCodeGen::TRANS_TARGS_WI()
538 /* Transitions must be written ordered by their id. */
539 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
540 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
541 transPtrs[trans->id] = trans;
543 /* Keep a count of the num of items in the array written. */
546 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
547 /* Write out the target state. */
548 RedTransAp *trans = transPtrs[t];
549 out << trans->targ->id;
550 if ( t < redFsm->transSet.length()-1 ) {
552 if ( ++totalStates % IALL == 0 )
562 std::ostream &TabCodeGen::TRANS_ACTIONS_WI()
564 /* Transitions must be written ordered by their id. */
565 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
566 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
567 transPtrs[trans->id] = trans;
569 /* Keep a count of the num of items in the array written. */
572 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
573 /* Write the function for the transition. */
574 RedTransAp *trans = transPtrs[t];
575 TRANS_ACTION( trans );
576 if ( t < redFsm->transSet.length()-1 ) {
578 if ( ++totalAct % IALL == 0 )
587 void TabCodeGen::LOCATE_TRANS()
590 " _keys = " << ARR_OFF( K(), KO() + "[" + CS() + "]" ) << ";\n"
591 " _trans = " << IO() << "[" << CS() << "];\n"
593 " _klen = " << SL() << "[" << CS() << "];\n"
594 " if ( _klen > 0 ) {\n"
595 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
596 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
597 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + _klen - 1;\n"
599 " if ( _upper < _lower )\n"
602 " _mid = _lower + ((_upper-_lower) >> 1);\n"
603 " if ( " << GET_WIDE_KEY() << " < *_mid )\n"
604 " _upper = _mid - 1;\n"
605 " else if ( " << GET_WIDE_KEY() << " > *_mid )\n"
606 " _lower = _mid + 1;\n"
608 " _trans += (_mid - _keys);\n"
613 " _trans += _klen;\n"
616 " _klen = " << RL() << "[" << CS() << "];\n"
617 " if ( _klen > 0 ) {\n"
618 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
619 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
620 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
622 " if ( _upper < _lower )\n"
625 " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
626 " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
627 " _upper = _mid - 2;\n"
628 " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
629 " _lower = _mid + 2;\n"
631 " _trans += ((_mid - _keys)>>1);\n"
635 " _trans += _klen;\n"
640 void TabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish )
642 ret << "{" << CS() << " = " << gotoDest << "; " <<
643 CTRL_FLOW() << "goto _again;}";
646 void TabCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish )
648 ret << "{" << CS() << " = (";
649 INLINE_LIST( ret, ilItem->children, 0, inFinish );
650 ret << "); " << CTRL_FLOW() << "goto _again;}";
653 void TabCodeGen::CURS( ostream &ret, bool inFinish )
658 void TabCodeGen::TARGS( ostream &ret, bool inFinish, int targState )
660 ret << "(" << CS() << ")";
663 void TabCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish )
665 ret << CS() << " = " << nextDest << ";";
668 void TabCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish )
670 ret << CS() << " = (";
671 INLINE_LIST( ret, ilItem->children, 0, inFinish );
675 void TabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish )
677 if ( prePushExpr != 0 ) {
679 INLINE_LIST( ret, prePushExpr, 0, false );
682 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = " <<
683 callDest << "; " << CTRL_FLOW() << "goto _again;}";
685 if ( prePushExpr != 0 )
689 void TabCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish )
691 if ( prePushExpr != 0 ) {
693 INLINE_LIST( ret, prePushExpr, 0, false );
696 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = (";
697 INLINE_LIST( ret, ilItem->children, targState, inFinish );
698 ret << "); " << CTRL_FLOW() << "goto _again;}";
700 if ( prePushExpr != 0 )
704 void TabCodeGen::RET( ostream &ret, bool inFinish )
706 ret << "{" << CS() << " = " << STACK() << "[--" <<
709 if ( postPopExpr != 0 ) {
711 INLINE_LIST( ret, postPopExpr, 0, false );
715 ret << CTRL_FLOW() << "goto _again;}";
718 void TabCodeGen::BREAK( ostream &ret, int targState )
721 ret << CTRL_FLOW() << "goto _out;";
724 void TabCodeGen::writeData()
726 /* If there are any transtion functions then output the array. If there
727 * are none, don't bother emitting an empty array that won't be used. */
728 if ( redFsm->anyActions() ) {
729 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
735 if ( redFsm->anyConditions() ) {
736 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
741 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
746 OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
751 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
757 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
762 OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
767 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
772 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
777 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
783 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
788 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
793 if ( redFsm->anyActions() ) {
794 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
801 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
806 if ( redFsm->anyActions() ) {
807 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
814 if ( redFsm->anyToStateActions() ) {
815 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
821 if ( redFsm->anyFromStateActions() ) {
822 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
823 FROM_STATE_ACTIONS();
828 if ( redFsm->anyEofActions() ) {
829 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
835 if ( redFsm->anyEofTrans() ) {
836 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex+1), ET() );
845 void TabCodeGen::COND_TRANSLATE()
848 " _widec = " << GET_KEY() << ";\n"
849 " _klen = " << CL() << "[" << CS() << "];\n"
850 " _keys = " << ARR_OFF( CK(), "(" + CO() + "[" + CS() + "]*2)" ) << ";\n"
851 " if ( _klen > 0 ) {\n"
852 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
853 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
854 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
856 " if ( _upper < _lower )\n"
859 " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
860 " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
861 " _upper = _mid - 2;\n"
862 " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
863 " _lower = _mid + 2;\n"
865 " switch ( " << C() << "[" << CO() << "[" << CS() << "]"
866 " + ((_mid - _keys)>>1)] ) {\n";
868 for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
869 CondSpace *condSpace = csi;
870 out << " case " << condSpace->condSpaceId << ": {\n";
871 out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
872 KEY(condSpace->baseKey) << " + (" << GET_KEY() <<
873 " - " << KEY(keyOps->minKey) << "));\n";
875 for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
876 out << TABS(2) << "if ( ";
877 CONDITION( out, *csi );
878 Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
879 out << " ) _widec += " << condValOffset << ";\n";
898 void TabCodeGen::writeExec()
901 outLabelUsed = false;
907 if ( redFsm->anyRegCurStateRef() )
912 " " << UINT() << " _trans;\n";
914 if ( redFsm->anyConditions() )
915 out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
917 if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
918 || redFsm->anyFromStateActions() )
921 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) <<
922 POINTER() << "_acts;\n"
923 " " << UINT() << " _nacts;\n";
927 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
933 " if ( " << P() << " == " << PE() << " )\n"
934 " goto _test_eof;\n";
937 if ( redFsm->errState != 0 ) {
940 " if ( " << CS() << " == " << redFsm->errState->id << " )\n"
946 if ( redFsm->anyFromStateActions() ) {
948 " _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
949 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
950 " while ( _nacts-- > 0 ) {\n"
951 " switch ( *_acts++ ) {\n";
952 FROM_STATE_ACTION_SWITCH();
959 if ( redFsm->anyConditions() )
967 out << " _trans = " << I() << "[_trans];\n";
969 if ( redFsm->anyEofTrans() )
970 out << "_eof_trans:\n";
972 if ( redFsm->anyRegCurStateRef() )
973 out << " _ps = " << CS() << ";\n";
976 " " << CS() << " = " << TT() << "[_trans];\n"
979 if ( redFsm->anyRegActions() ) {
981 " if ( " << TA() << "[_trans] == 0 )\n"
984 " _acts = " << ARR_OFF( A(), TA() + "[_trans]" ) << ";\n"
985 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
986 " while ( _nacts-- > 0 )\n {\n"
987 " switch ( *_acts++ )\n {\n";
995 if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
996 redFsm->anyActionCalls() || redFsm->anyActionRets() )
999 if ( redFsm->anyToStateActions() ) {
1001 " _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
1002 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
1003 " while ( _nacts-- > 0 ) {\n"
1004 " switch ( *_acts++ ) {\n";
1005 TO_STATE_ACTION_SWITCH();
1012 if ( redFsm->errState != 0 ) {
1013 outLabelUsed = true;
1015 " if ( " << CS() << " == " << redFsm->errState->id << " )\n"
1021 " if ( ++" << P() << " != " << PE() << " )\n"
1026 " " << P() << " += 1;\n"
1031 out << " _test_eof: {}\n";
1033 if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
1035 " if ( " << P() << " == " << EOFV() << " )\n"
1038 if ( redFsm->anyEofTrans() ) {
1040 " if ( " << ET() << "[" << CS() << "] > 0 ) {\n"
1041 " _trans = " << ET() << "[" << CS() << "] - 1;\n"
1042 " goto _eof_trans;\n"
1046 if ( redFsm->anyEofActions() ) {
1048 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) <<
1049 POINTER() << "__acts = " <<
1050 ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
1051 " " << UINT() << " __nacts = " << CAST(UINT()) << " *__acts++;\n"
1052 " while ( __nacts-- > 0 ) {\n"
1053 " switch ( *__acts++ ) {\n";
1054 EOF_ACTION_SWITCH();
1066 out << " _out: {}\n";