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::COND_KEYS()
334 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
335 /* Loop the state's transitions. */
336 for ( StateCondList::Iter sc = st->stateCondList; sc.lte(); sc++ ) {
338 out << KEY( sc->lowKey ) << ", ";
339 if ( ++totalTrans % IALL == 0 )
343 out << KEY( sc->highKey ) << ", ";
344 if ( ++totalTrans % IALL == 0 )
349 /* Output one last number so we don't have to figure out when the last
350 * entry is and avoid writing a comma. */
355 std::ostream &TabCodeGen::COND_SPACES()
359 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
360 /* Loop the state's transitions. */
361 for ( StateCondList::Iter sc = st->stateCondList; sc.lte(); sc++ ) {
363 out << sc->condSpace->condSpaceId << ", ";
364 if ( ++totalTrans % IALL == 0 )
369 /* Output one last number so we don't have to figure out when the last
370 * entry is and avoid writing a comma. */
375 std::ostream &TabCodeGen::KEYS()
379 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
380 /* Loop the singles. */
381 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
382 out << KEY( stel->lowKey ) << ", ";
383 if ( ++totalTrans % IALL == 0 )
387 /* Loop the state's transitions. */
388 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
390 out << KEY( rtel->lowKey ) << ", ";
391 if ( ++totalTrans % IALL == 0 )
395 out << KEY( rtel->highKey ) << ", ";
396 if ( ++totalTrans % IALL == 0 )
401 /* Output one last number so we don't have to figure out when the last
402 * entry is and avoid writing a comma. */
407 std::ostream &TabCodeGen::INDICIES()
411 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
412 /* Walk the singles. */
413 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
414 out << stel->value->id << ", ";
415 if ( ++totalTrans % IALL == 0 )
419 /* Walk the ranges. */
420 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
421 out << rtel->value->id << ", ";
422 if ( ++totalTrans % IALL == 0 )
426 /* The state's default index goes next. */
427 if ( st->defTrans != 0 ) {
428 out << st->defTrans->id << ", ";
429 if ( ++totalTrans % IALL == 0 )
434 /* Output one last number so we don't have to figure out when the last
435 * entry is and avoid writing a comma. */
440 std::ostream &TabCodeGen::TRANS_TARGS()
444 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
445 /* Walk the singles. */
446 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
447 RedTransAp *trans = stel->value;
448 out << trans->targ->id << ", ";
449 if ( ++totalTrans % IALL == 0 )
453 /* Walk the ranges. */
454 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
455 RedTransAp *trans = rtel->value;
456 out << trans->targ->id << ", ";
457 if ( ++totalTrans % IALL == 0 )
461 /* The state's default target state. */
462 if ( st->defTrans != 0 ) {
463 RedTransAp *trans = st->defTrans;
464 out << trans->targ->id << ", ";
465 if ( ++totalTrans % IALL == 0 )
470 /* Output one last number so we don't have to figure out when the last
471 * entry is and avoid writing a comma. */
477 std::ostream &TabCodeGen::TRANS_ACTIONS()
481 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
482 /* Walk the singles. */
483 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
484 RedTransAp *trans = stel->value;
485 TRANS_ACTION( trans ) << ", ";
486 if ( ++totalTrans % IALL == 0 )
490 /* Walk the ranges. */
491 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
492 RedTransAp *trans = rtel->value;
493 TRANS_ACTION( trans ) << ", ";
494 if ( ++totalTrans % IALL == 0 )
498 /* The state's default index goes next. */
499 if ( st->defTrans != 0 ) {
500 RedTransAp *trans = st->defTrans;
501 TRANS_ACTION( trans ) << ", ";
502 if ( ++totalTrans % IALL == 0 )
507 /* Output one last number so we don't have to figure out when the last
508 * entry is and avoid writing a comma. */
513 std::ostream &TabCodeGen::TRANS_TARGS_WI()
515 /* Transitions must be written ordered by their id. */
516 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
517 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
518 transPtrs[trans->id] = trans;
520 /* Keep a count of the num of items in the array written. */
523 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
524 /* Write out the target state. */
525 RedTransAp *trans = transPtrs[t];
526 out << trans->targ->id;
527 if ( t < redFsm->transSet.length()-1 ) {
529 if ( ++totalStates % IALL == 0 )
539 std::ostream &TabCodeGen::TRANS_ACTIONS_WI()
541 /* Transitions must be written ordered by their id. */
542 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
543 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
544 transPtrs[trans->id] = trans;
546 /* Keep a count of the num of items in the array written. */
549 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
550 /* Write the function for the transition. */
551 RedTransAp *trans = transPtrs[t];
552 TRANS_ACTION( trans );
553 if ( t < redFsm->transSet.length()-1 ) {
555 if ( ++totalAct % IALL == 0 )
564 void TabCodeGen::LOCATE_TRANS()
567 " _keys = " << ARR_OFF( K(), KO() + "[" + CS() + "]" ) << ";\n"
568 " _trans = " << IO() << "[" << CS() << "];\n"
570 " _klen = " << SL() << "[" << CS() << "];\n"
571 " if ( _klen > 0 ) {\n"
572 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
573 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
574 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + _klen - 1;\n"
576 " if ( _upper < _lower )\n"
579 " _mid = _lower + ((_upper-_lower) >> 1);\n"
580 " if ( " << GET_WIDE_KEY() << " < *_mid )\n"
581 " _upper = _mid - 1;\n"
582 " else if ( " << GET_WIDE_KEY() << " > *_mid )\n"
583 " _lower = _mid + 1;\n"
585 " _trans += (_mid - _keys);\n"
590 " _trans += _klen;\n"
593 " _klen = " << RL() << "[" << 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) - 2;\n"
599 " if ( _upper < _lower )\n"
602 " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
603 " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
604 " _upper = _mid - 2;\n"
605 " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
606 " _lower = _mid + 2;\n"
608 " _trans += ((_mid - _keys)>>1);\n"
612 " _trans += _klen;\n"
617 void TabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish )
619 ret << "{" << CS() << " = " << gotoDest << "; " <<
620 CTRL_FLOW() << "goto _again;}";
623 void TabCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish )
625 ret << "{" << CS() << " = (";
626 INLINE_LIST( ret, ilItem->children, 0, inFinish );
627 ret << "); " << CTRL_FLOW() << "goto _again;}";
630 void TabCodeGen::CURS( ostream &ret, bool inFinish )
635 void TabCodeGen::TARGS( ostream &ret, bool inFinish, int targState )
637 ret << "(" << CS() << ")";
640 void TabCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish )
642 ret << CS() << " = " << nextDest << ";";
645 void TabCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish )
647 ret << CS() << " = (";
648 INLINE_LIST( ret, ilItem->children, 0, inFinish );
652 void TabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish )
654 if ( prePushExpr != 0 ) {
656 INLINE_LIST( ret, prePushExpr, 0, false );
659 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = " <<
660 callDest << "; " << CTRL_FLOW() << "goto _again;}";
662 if ( prePushExpr != 0 )
666 void TabCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish )
668 if ( prePushExpr != 0 ) {
670 INLINE_LIST( ret, prePushExpr, 0, false );
673 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = (";
674 INLINE_LIST( ret, ilItem->children, targState, inFinish );
675 ret << "); " << CTRL_FLOW() << "goto _again;}";
677 if ( prePushExpr != 0 )
681 void TabCodeGen::RET( ostream &ret, bool inFinish )
683 ret << "{" << CS() << " = " << STACK() << "[--" <<
686 if ( postPopExpr != 0 ) {
688 INLINE_LIST( ret, postPopExpr, 0, false );
692 ret << CTRL_FLOW() << "goto _again;}";
695 void TabCodeGen::BREAK( ostream &ret, int targState )
698 ret << CTRL_FLOW() << "goto _out;";
701 void TabCodeGen::writeData()
703 /* If there are any transtion functions then output the array. If there
704 * are none, don't bother emitting an empty array that won't be used. */
705 if ( redFsm->anyActions() ) {
706 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
712 if ( redFsm->anyConditions() ) {
713 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
718 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
723 OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
728 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
734 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
739 OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
744 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
749 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
754 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
760 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
765 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
770 if ( redFsm->anyActions() ) {
771 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
778 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
783 if ( redFsm->anyActions() ) {
784 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
791 if ( redFsm->anyToStateActions() ) {
792 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
798 if ( redFsm->anyFromStateActions() ) {
799 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
800 FROM_STATE_ACTIONS();
805 if ( redFsm->anyEofActions() ) {
806 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
815 void TabCodeGen::COND_TRANSLATE()
818 " _widec = " << GET_KEY() << ";\n"
819 " _klen = " << CL() << "[" << CS() << "];\n"
820 " _keys = " << ARR_OFF( CK(), "(" + CO() + "[" + CS() + "]*2)" ) << ";\n"
821 " if ( _klen > 0 ) {\n"
822 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
823 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
824 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
826 " if ( _upper < _lower )\n"
829 " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
830 " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
831 " _upper = _mid - 2;\n"
832 " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
833 " _lower = _mid + 2;\n"
835 " switch ( " << C() << "[" << CO() << "[" << CS() << "]"
836 " + ((_mid - _keys)>>1)] ) {\n";
838 for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
839 CondSpace *condSpace = csi;
840 out << " case " << condSpace->condSpaceId << ": {\n";
841 out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
842 KEY(condSpace->baseKey) << " + (" << GET_KEY() <<
843 " - " << KEY(keyOps->minKey) << "));\n";
845 for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
846 out << TABS(2) << "if ( ";
847 CONDITION( out, *csi );
848 Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
849 out << " ) _widec += " << condValOffset << ";\n";
868 void TabCodeGen::writeExec()
871 outLabelUsed = false;
877 if ( redFsm->anyRegCurStateRef() )
882 " " << UINT() << " _trans;\n";
884 if ( redFsm->anyConditions() )
885 out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
887 if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
888 || redFsm->anyFromStateActions() )
891 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
892 " " << UINT() << " _nacts;\n";
896 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
902 " if ( " << P() << " == " << PE() << " )\n"
903 " goto _test_eof;\n";
906 if ( redFsm->errState != 0 ) {
909 " if ( " << CS() << " == " << redFsm->errState->id << " )\n"
915 if ( redFsm->anyFromStateActions() ) {
917 " _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
918 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
919 " while ( _nacts-- > 0 ) {\n"
920 " switch ( *_acts++ ) {\n";
921 FROM_STATE_ACTION_SWITCH();
928 if ( redFsm->anyConditions() )
935 if ( redFsm->anyRegCurStateRef() )
936 out << " _ps = " << CS() << ";\n";
939 out << " _trans = " << I() << "[_trans];\n";
942 " " << CS() << " = " << TT() << "[_trans];\n"
945 if ( redFsm->anyRegActions() ) {
947 " if ( " << TA() << "[_trans] == 0 )\n"
950 " _acts = " << ARR_OFF( A(), TA() + "[_trans]" ) << ";\n"
951 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
952 " while ( _nacts-- > 0 )\n {\n"
953 " switch ( *_acts++ )\n {\n";
961 if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
962 redFsm->anyActionCalls() || redFsm->anyActionRets() )
965 if ( redFsm->anyToStateActions() ) {
967 " _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
968 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
969 " while ( _nacts-- > 0 ) {\n"
970 " switch ( *_acts++ ) {\n";
971 TO_STATE_ACTION_SWITCH();
978 if ( redFsm->errState != 0 ) {
981 " if ( " << CS() << " == " << redFsm->errState->id << " )\n"
987 " if ( ++" << P() << " != " << PE() << " )\n"
992 " " << P() << " += 1;\n"
997 out << " _test_eof: {}\n";
999 if ( redFsm->anyEofActions() ) {
1001 " if ( " << P() << " == " << EOFV() << " )\n"
1003 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) <<
1004 POINTER() << "__acts = " << ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
1005 " " << UINT() << " __nacts = " << CAST(UINT()) << " *__acts++;\n"
1006 " while ( __nacts-- > 0 ) {\n"
1007 " switch ( *__acts++ ) {\n";
1008 EOF_ACTION_SWITCH();
1017 out << " _out: {}\n";
1023 void TabCodeGen::writeEOF()