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 int TabCodeGen::TO_STATE_ACTION( RedStateAp *state )
60 if ( state->toStateAction != 0 )
61 act = state->toStateAction->location+1;
65 int TabCodeGen::FROM_STATE_ACTION( RedStateAp *state )
68 if ( state->fromStateAction != 0 )
69 act = state->fromStateAction->location+1;
73 int TabCodeGen::EOF_ACTION( RedStateAp *state )
76 if ( state->eofAction != 0 )
77 act = state->eofAction->location+1;
82 int TabCodeGen::TRANS_ACTION( RedTransAp *trans )
84 /* If there are actions, emit them. Otherwise emit zero. */
86 if ( trans->action != 0 )
87 act = trans->action->location+1;
91 std::ostream &TabCodeGen::TO_STATE_ACTION_SWITCH()
93 /* Walk the list of functions, printing the cases. */
94 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
95 /* Write out referenced actions. */
96 if ( act->numToStateRefs > 0 ) {
97 /* Write the case label, the action and the case break. */
98 out << "\tcase " << act->actionId << ":\n";
99 ACTION( out, act, 0, false );
104 genLineDirective( out );
108 std::ostream &TabCodeGen::FROM_STATE_ACTION_SWITCH()
110 /* Walk the list of functions, printing the cases. */
111 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
112 /* Write out referenced actions. */
113 if ( act->numFromStateRefs > 0 ) {
114 /* Write the case label, the action and the case break. */
115 out << "\tcase " << act->actionId << ":\n";
116 ACTION( out, act, 0, false );
121 genLineDirective( out );
125 std::ostream &TabCodeGen::EOF_ACTION_SWITCH()
127 /* Walk the list of functions, printing the cases. */
128 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
129 /* Write out referenced actions. */
130 if ( act->numEofRefs > 0 ) {
131 /* Write the case label, the action and the case break. */
132 out << "\tcase " << act->actionId << ":\n";
133 ACTION( out, act, 0, true );
138 genLineDirective( out );
143 std::ostream &TabCodeGen::ACTION_SWITCH()
145 /* Walk the list of functions, printing the cases. */
146 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
147 /* Write out referenced actions. */
148 if ( act->numTransRefs > 0 ) {
149 /* Write the case label, the action and the case break. */
150 out << "\tcase " << act->actionId << ":\n";
151 ACTION( out, act, 0, false );
156 genLineDirective( out );
160 std::ostream &TabCodeGen::COND_OFFSETS()
163 int totalStateNum = 0, curKeyOffset = 0;
164 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
165 /* Write the key offset. */
166 ARRAY_ITEM( curKeyOffset, ++totalStateNum, st.last() );
168 /* Move the key offset ahead. */
169 curKeyOffset += st->stateCondList.length();
175 std::ostream &TabCodeGen::KEY_OFFSETS()
178 int totalStateNum = 0, curKeyOffset = 0;
179 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
180 /* Write the key offset. */
181 ARRAY_ITEM( curKeyOffset, ++totalStateNum, st.last() );
183 /* Move the key offset ahead. */
184 curKeyOffset += st->outSingle.length() + st->outRange.length()*2;
191 std::ostream &TabCodeGen::INDEX_OFFSETS()
194 int totalStateNum = 0, curIndOffset = 0;
195 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
196 /* Write the index offset. */
197 ARRAY_ITEM( curIndOffset, ++totalStateNum, st.last() );
199 /* Move the index offset ahead. */
200 curIndOffset += st->outSingle.length() + st->outRange.length();
201 if ( st->defTrans != 0 )
208 std::ostream &TabCodeGen::COND_LENS()
211 int totalStateNum = 0;
212 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
213 /* Write singles length. */
214 ARRAY_ITEM( st->stateCondList.length(), ++totalStateNum, st.last() );
221 std::ostream &TabCodeGen::SINGLE_LENS()
224 int totalStateNum = 0;
225 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
226 /* Write singles length. */
227 ARRAY_ITEM( st->outSingle.length(), ++totalStateNum, st.last() );
233 std::ostream &TabCodeGen::RANGE_LENS()
236 int totalStateNum = 0;
237 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
238 /* Emit length of range index. */
239 ARRAY_ITEM( st->outRange.length(), ++totalStateNum, st.last() );
245 std::ostream &TabCodeGen::TO_STATE_ACTIONS()
248 int totalStateNum = 0;
249 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
250 /* Write any eof action. */
251 ARRAY_ITEM( TO_STATE_ACTION(st), ++totalStateNum, st.last() );
257 std::ostream &TabCodeGen::FROM_STATE_ACTIONS()
260 int totalStateNum = 0;
261 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
262 /* Write any eof action. */
263 ARRAY_ITEM( FROM_STATE_ACTION(st), ++totalStateNum, st.last() );
269 std::ostream &TabCodeGen::EOF_ACTIONS()
272 int totalStateNum = 0;
273 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
274 /* Write any eof action. */
275 ARRAY_ITEM( EOF_ACTION(st), ++totalStateNum, st.last() );
281 std::ostream &TabCodeGen::COND_KEYS()
285 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
286 /* Loop the state's transitions. */
287 for ( StateCondList::Iter sc = st->stateCondList; sc.lte(); sc++ ) {
289 ARRAY_ITEM( KEY( sc->lowKey ), ++totalTrans, false );
290 ARRAY_ITEM( KEY( sc->highKey ), ++totalTrans, false );
294 /* Output one last number so we don't have to figure out when the last
295 * entry is and avoid writing a comma. */
296 ARRAY_ITEM( 0, ++totalTrans, true );
301 std::ostream &TabCodeGen::COND_SPACES()
305 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
306 /* Loop the state's transitions. */
307 for ( StateCondList::Iter sc = st->stateCondList; sc.lte(); sc++ ) {
309 ARRAY_ITEM( KEY( sc->condSpace->condSpaceId ), ++totalTrans, false );
313 /* Output one last number so we don't have to figure out when the last
314 * entry is and avoid writing a comma. */
315 ARRAY_ITEM( 0, ++totalTrans, true );
320 std::ostream &TabCodeGen::KEYS()
324 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
325 /* Loop the singles. */
326 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
327 ARRAY_ITEM( KEY( stel->lowKey ), ++totalTrans, false );
330 /* Loop the state's transitions. */
331 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
333 ARRAY_ITEM( KEY( rtel->lowKey ), ++totalTrans, false );
336 ARRAY_ITEM( KEY( rtel->highKey ), ++totalTrans, false );
340 /* Output one last number so we don't have to figure out when the last
341 * entry is and avoid writing a comma. */
342 ARRAY_ITEM( 0, ++totalTrans, true );
347 std::ostream &TabCodeGen::INDICIES()
351 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
352 /* Walk the singles. */
353 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
354 ARRAY_ITEM( KEY( stel->value->id ), ++totalTrans, false );
357 /* Walk the ranges. */
358 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
359 ARRAY_ITEM( KEY( rtel->value->id ), ++totalTrans, false );
362 /* The state's default index goes next. */
363 if ( st->defTrans != 0 ) {
364 ARRAY_ITEM( KEY( st->defTrans->id ), ++totalTrans, false );
368 /* Output one last number so we don't have to figure out when the last
369 * entry is and avoid writing a comma. */
370 ARRAY_ITEM( 0, ++totalTrans, true );
375 std::ostream &TabCodeGen::TRANS_TARGS()
379 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
380 /* Walk the singles. */
381 for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
382 RedTransAp *trans = stel->value;
383 ARRAY_ITEM( KEY( trans->targ->id ), ++totalTrans, false );
386 /* Walk the ranges. */
387 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
388 RedTransAp *trans = rtel->value;
389 ARRAY_ITEM( KEY( trans->targ->id ), ++totalTrans, false );
392 /* The state's default target state. */
393 if ( st->defTrans != 0 ) {
394 RedTransAp *trans = st->defTrans;
395 ARRAY_ITEM( KEY( trans->targ->id ), ++totalTrans, false );
399 /* Output one last number so we don't have to figure out when the last
400 * entry is and avoid writing a comma. */
401 ARRAY_ITEM( 0, ++totalTrans, true );
407 std::ostream &TabCodeGen::TRANS_ACTIONS()
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 RedTransAp *trans = stel->value;
415 ARRAY_ITEM( TRANS_ACTION( trans ), ++totalTrans, false );
418 /* Walk the ranges. */
419 for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
420 RedTransAp *trans = rtel->value;
421 ARRAY_ITEM( TRANS_ACTION( trans ), ++totalTrans, false );
424 /* The state's default index goes next. */
425 if ( st->defTrans != 0 ) {
426 RedTransAp *trans = st->defTrans;
427 ARRAY_ITEM( TRANS_ACTION( trans ), ++totalTrans, false );
431 /* Output one last number so we don't have to figure out when the last
432 * entry is and avoid writing a comma. */
433 ARRAY_ITEM( 0, ++totalTrans, true );
438 std::ostream &TabCodeGen::TRANS_TARGS_WI()
440 /* Transitions must be written ordered by their id. */
441 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
442 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
443 transPtrs[trans->id] = trans;
445 /* Keep a count of the num of items in the array written. */
448 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
449 /* Write out the target state. */
450 RedTransAp *trans = transPtrs[t];
451 ARRAY_ITEM( trans->targ->id, ++totalStates, ( t >= redFsm->transSet.length()-1 ) );
459 std::ostream &TabCodeGen::TRANS_ACTIONS_WI()
461 /* Transitions must be written ordered by their id. */
462 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
463 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
464 transPtrs[trans->id] = trans;
466 /* Keep a count of the num of items in the array written. */
469 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
470 /* Write the function for the transition. */
471 RedTransAp *trans = transPtrs[t];
472 ARRAY_ITEM( TRANS_ACTION( trans ), ++totalAct, ( t >= redFsm->transSet.length()-1 ) );
479 void TabCodeGen::LOCATE_TRANS()
482 " _keys = " << ARR_OFF( K(), KO() + "[" + CS() + "]" ) << ";\n"
483 " _trans = " << IO() << "[" << CS() << "];\n"
485 " _klen = " << SL() << "[" << CS() << "];\n"
486 " if ( _klen > 0 ) {\n"
487 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
488 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
489 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + _klen - 1;\n"
491 " if ( _upper < _lower )\n"
494 " _mid = _lower + ((_upper-_lower) >> 1);\n"
495 " if ( " << GET_WIDE_KEY() << " < *_mid )\n"
496 " _upper = _mid - 1;\n"
497 " else if ( " << GET_WIDE_KEY() << " > *_mid )\n"
498 " _lower = _mid + 1;\n"
500 " _trans += (_mid - _keys);\n"
505 " _trans += _klen;\n"
508 " _klen = " << RL() << "[" << CS() << "];\n"
509 " if ( _klen > 0 ) {\n"
510 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
511 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
512 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
514 " if ( _upper < _lower )\n"
517 " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
518 " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
519 " _upper = _mid - 2;\n"
520 " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
521 " _lower = _mid + 2;\n"
523 " _trans += ((_mid - _keys)>>1);\n"
527 " _trans += _klen;\n"
532 void TabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish )
534 ret << "{" << CS() << " = " << gotoDest << "; " <<
535 CTRL_FLOW() << "goto _again;}";
538 void TabCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish )
540 ret << "{" << CS() << " = (";
541 INLINE_LIST( ret, ilItem->children, 0, inFinish );
542 ret << "); " << CTRL_FLOW() << "goto _again;}";
545 void TabCodeGen::CURS( ostream &ret, bool inFinish )
550 void TabCodeGen::TARGS( ostream &ret, bool inFinish, int targState )
552 ret << "(" << CS() << ")";
555 void TabCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish )
557 ret << CS() << " = " << nextDest << ";";
560 void TabCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish )
562 ret << CS() << " = (";
563 INLINE_LIST( ret, ilItem->children, 0, inFinish );
567 void TabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish )
569 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = " <<
570 callDest << "; " << CTRL_FLOW() << "goto _again;}";
573 void TabCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish )
575 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = (";
576 INLINE_LIST( ret, ilItem->children, targState, inFinish );
577 ret << "); " << CTRL_FLOW() << "goto _again;}";
580 void TabCodeGen::RET( ostream &ret, bool inFinish )
582 ret << "{" << CS() << " = " << STACK() << "[--" <<
583 TOP() << "]; " << CTRL_FLOW() << "goto _again;}";
586 void TabCodeGen::BREAK( ostream &ret, int targState )
589 ret << CTRL_FLOW() << "goto _out;";
592 void TabCodeGen::writeOutData()
594 /* If there are any transtion functions then output the array. If there
595 * are none, don't bother emitting an empty array that won't be used. */
596 if ( redFsm->anyActions() ) {
597 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
603 if ( redFsm->anyConditions() ) {
604 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
609 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
614 OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
619 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
625 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
630 OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
635 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
640 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
645 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
651 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
656 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
661 if ( redFsm->anyActions() ) {
662 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
669 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
674 if ( redFsm->anyActions() ) {
675 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
682 if ( redFsm->anyToStateActions() ) {
683 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
689 if ( redFsm->anyFromStateActions() ) {
690 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
691 FROM_STATE_ACTIONS();
696 if ( redFsm->anyEofActions() ) {
697 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
703 STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n"
706 if ( writeFirstFinal ) {
707 STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n"
712 STATIC_VAR( "int", ERROR() ) << " = " << ERROR_STATE() << ";\n"
717 void TabCodeGen::COND_TRANSLATE()
720 " _widec = " << GET_KEY() << ";\n"
721 " _klen = " << CL() << "[" << CS() << "];\n"
722 " _keys = " << ARR_OFF( CK(), "(" + CO() + "[" + CS() + "]*2)" ) << ";\n"
723 " if ( _klen > 0 ) {\n"
724 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_lower = _keys;\n"
725 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_mid;\n"
726 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_upper = _keys + (_klen<<1) - 2;\n"
728 " if ( _upper < _lower )\n"
731 " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
732 " if ( " << GET_WIDE_KEY() << " < _mid[0] )\n"
733 " _upper = _mid - 2;\n"
734 " else if ( " << GET_WIDE_KEY() << " > _mid[1] )\n"
735 " _lower = _mid + 2;\n"
737 " switch ( " << C() << "[" << CO() << "[" << CS() << "]"
738 " + ((_mid - _keys)>>1)] ) {\n";
740 for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
741 CondSpace *condSpace = csi;
742 out << " case " << condSpace->condSpaceId << ": {\n";
743 out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
744 KEY(condSpace->baseKey) << " + (" << GET_KEY() <<
745 " - " << KEY(keyOps->minKey) << "));\n";
747 for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
748 out << TABS(2) << "if ( ";
749 CONDITION( out, *csi );
750 Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
751 out << " ) _widec += " << condValOffset << ";\n";
770 void TabCodeGen::writeOutExec()
772 outLabelUsed = false;
778 if ( redFsm->anyRegCurStateRef() )
783 " " << UINT() << " _trans;\n";
785 if ( redFsm->anyConditions() )
786 out << " " << WIDE_ALPH_TYPE() << " _widec;\n";
788 if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
789 || redFsm->anyFromStateActions() )
792 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
793 " " << UINT() << " _nacts;\n";
797 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
803 " if ( " << P() << " == " << PE() << " )\n"
809 if ( redFsm->errState != 0 ) {
812 " if ( " << CS() << " == " << redFsm->errState->id << " )\n"
816 if ( redFsm->anyFromStateActions() ) {
818 " _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
819 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
820 " while ( _nacts-- > 0 ) {\n"
821 " switch ( *_acts++ ) {\n";
822 FROM_STATE_ACTION_SWITCH();
829 if ( redFsm->anyConditions() )
836 if ( redFsm->anyRegCurStateRef() )
837 out << " _ps = " << CS() << ";\n";
840 out << " _trans = " << I() << "[_trans];\n";
843 " " << CS() << " = " << TT() << "[_trans];\n"
846 if ( redFsm->anyRegActions() ) {
848 " if ( " << TA() << "[_trans] == 0 )\n"
851 " _acts = " << ARR_OFF( A(), TA() + "[_trans]" ) << ";\n"
852 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
853 " while ( _nacts-- > 0 )\n {\n"
854 " switch ( *_acts++ )\n {\n";
862 if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
863 redFsm->anyActionCalls() || redFsm->anyActionRets() )
866 if ( redFsm->anyToStateActions() ) {
868 " _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
869 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
870 " while ( _nacts-- > 0 ) {\n"
871 " switch ( *_acts++ ) {\n";
872 TO_STATE_ACTION_SWITCH();
881 " if ( ++" << P() << " != " << PE() << " )\n"
886 " " << P() << " += 1;\n"
891 out << " _out: {}\n";
897 void TabCodeGen::writeOutEOF()
899 if ( redFsm->anyEofActions() ) {
902 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts = " <<
903 ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
904 " " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
905 " while ( _nacts-- > 0 ) {\n"
906 " switch ( *_acts++ ) {\n";