2 * Copyright 2001-2006 Adrian Thurston <thurston@cs.queensu.ca>
3 * 2004 Eric 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
24 #include "rlcodegen.h"
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(maxIndex) * totalIndex;
40 sizeWithInds += arrayTypeSize(maxState) * redFsm->transSet.length();
42 sizeWithInds += arrayTypeSize(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(maxState) * totalIndex;
50 sizeWithoutInds += arrayTypeSize(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 = cgd->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 = cgd->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 = cgd->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 = cgd->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 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = " <<
655 callDest << "; " << CTRL_FLOW() << "goto _again;}";
658 void TabCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish )
660 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = (";
661 INLINE_LIST( ret, ilItem->children, targState, inFinish );
662 ret << "); " << CTRL_FLOW() << "goto _again;}";
665 void TabCodeGen::RET( ostream &ret, bool inFinish )
667 ret << "{" << CS() << " = " << STACK() << "[--" <<
668 TOP() << "]; " << CTRL_FLOW() << "goto _again;}";
671 void TabCodeGen::BREAK( ostream &ret, int targState )
674 ret << CTRL_FLOW() << "goto _out;";
677 void TabCodeGen::writeOutData()
679 /* If there are any transtion functions then output the array. If there
680 * are none, don't bother emitting an empty array that won't be used. */
681 if ( anyActions() ) {
682 OPEN_ARRAY( ARRAY_TYPE(maxActArrItem), A() );
688 if ( anyConditions() ) {
689 OPEN_ARRAY( ARRAY_TYPE(maxCondOffset), CO() );
694 OPEN_ARRAY( ARRAY_TYPE(maxCondLen), CL() );
699 OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
704 OPEN_ARRAY( ARRAY_TYPE(maxCondSpaceId), C() );
710 OPEN_ARRAY( ARRAY_TYPE(maxKeyOffset), KO() );
715 OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
720 OPEN_ARRAY( ARRAY_TYPE(maxSingleLen), SL() );
725 OPEN_ARRAY( ARRAY_TYPE(maxRangeLen), RL() );
730 OPEN_ARRAY( ARRAY_TYPE(maxIndexOffset), IO() );
736 OPEN_ARRAY( ARRAY_TYPE(maxIndex), I() );
741 OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
746 if ( anyActions() ) {
747 OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TA() );
754 OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
759 if ( anyActions() ) {
760 OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TA() );
767 if ( anyToStateActions() ) {
768 OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
774 if ( anyFromStateActions() ) {
775 OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
776 FROM_STATE_ACTIONS();
781 if ( anyEofActions() ) {
782 OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), EA() );
788 STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n"
791 if ( cgd->writeFirstFinal ) {
792 STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n"
796 if ( cgd->writeErr ) {
797 STATIC_VAR( "int", ERROR() ) << " = " << ERROR_STATE() << ";\n"
802 void TabCodeGen::COND_TRANSLATE()
805 " _widec = " << GET_KEY() << ";\n"
806 " _klen = " << CL() << "[" << CS() << "];\n"
807 " _keys = " << ARR_OFF( CK(), "(" + CO() + "[" + CS() + "]*2)" ) << ";\n"
808 " if ( _klen > 0 ) {\n"
809 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
810 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
811 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
813 " if ( _upper < _lower )\n"
816 " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
817 " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
818 " _upper = _mid - 2;\n"
819 " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
820 " _lower = _mid + 2;\n"
822 " switch ( " << C() << "[" << CO() << "[" << CS() << "]"
823 " + ((_mid - _keys)>>1)] ) {\n";
825 for ( CondSpaceList::Iter csi = cgd->condSpaceList; csi.lte(); csi++ ) {
826 CondSpace *condSpace = csi;
827 out << " case " << condSpace->condSpaceId << ": {\n";
828 out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
829 KEY(condSpace->baseKey) << " + (" << GET_KEY() <<
830 " - " << KEY(keyOps->minKey) << "));\n";
832 for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
833 out << TABS(2) << "if ( ";
834 CONDITION( out, *csi );
835 Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
836 out << " ) _widec += " << condValOffset << ";\n";
855 void TabCodeGen::writeOutExec()
857 outLabelUsed = false;
863 if ( anyRegCurStateRef() )
868 " " << UINT() << " _trans;\n";
870 if ( anyConditions() )
871 out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
873 if ( anyToStateActions() || anyRegActions() || anyFromStateActions() ) {
875 " " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts;\n"
876 " " << UINT() << " _nacts;\n";
880 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
886 " if ( " << P() << " == " << PE() << " )\n"
892 if ( redFsm->errState != 0 ) {
895 " if ( " << CS() << " == " << redFsm->errState->id << " )\n"
899 if ( anyFromStateActions() ) {
901 " _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
902 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
903 " while ( _nacts-- > 0 ) {\n"
904 " switch ( *_acts++ ) {\n";
905 FROM_STATE_ACTION_SWITCH();
912 if ( anyConditions() )
919 if ( anyRegCurStateRef() )
920 out << " _ps = " << CS() << ";\n";
923 out << " _trans = " << I() << "[_trans];\n";
926 " " << CS() << " = " << TT() << "[_trans];\n"
929 if ( anyRegActions() ) {
931 " if ( " << TA() << "[_trans] == 0 )\n"
934 " _acts = " << ARR_OFF( A(), TA() + "[_trans]" ) << ";\n"
935 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
936 " while ( _nacts-- > 0 )\n {\n"
937 " switch ( *_acts++ )\n {\n";
945 if ( anyRegActions() || anyActionGotos() || anyActionCalls() || anyActionRets() )
948 if ( anyToStateActions() ) {
950 " _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
951 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
952 " while ( _nacts-- > 0 ) {\n"
953 " switch ( *_acts++ ) {\n";
954 TO_STATE_ACTION_SWITCH();
963 " if ( ++" << P() << " != " << PE() << " )\n"
968 " " << P() << " += 1;\n"
973 out << " _out: {}\n";
979 void TabCodeGen::writeOutEOF()
981 if ( anyEofActions() ) {
984 " " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts = " <<
985 ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
986 " " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
987 " while ( _nacts-- > 0 ) {\n"
988 " switch ( *_acts++ ) {\n";