Editing pass.
[ragel.git] / rlgen-cd / flatcodegen.cpp
blob6273f757a5e6057bf9389575015c6fc1241cfd3b
1 /*
2 * Copyright 2004-2006 Adrian Thurston <thurston@cs.queensu.ca>
3 * 2004 Erich Ocean <eric.ocean@ampede.com>
4 * 2005 Alan West <alan@alanz.com>
5 */
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 "rlgen-cd.h"
25 #include "flatcodegen.h"
26 #include "redfsm.h"
27 #include "gendata.h"
29 std::ostream &FlatCodeGen::TO_STATE_ACTION( RedStateAp *state )
31 int act = 0;
32 if ( state->toStateAction != 0 )
33 act = state->toStateAction->location+1;
34 out << act;
35 return out;
38 std::ostream &FlatCodeGen::FROM_STATE_ACTION( RedStateAp *state )
40 int act = 0;
41 if ( state->fromStateAction != 0 )
42 act = state->fromStateAction->location+1;
43 out << act;
44 return out;
47 std::ostream &FlatCodeGen::EOF_ACTION( RedStateAp *state )
49 int act = 0;
50 if ( state->eofAction != 0 )
51 act = state->eofAction->location+1;
52 out << act;
53 return out;
56 std::ostream &FlatCodeGen::TRANS_ACTION( RedTransAp *trans )
58 /* If there are actions, emit them. Otherwise emit zero. */
59 int act = 0;
60 if ( trans->action != 0 )
61 act = trans->action->location+1;
62 out << act;
63 return out;
66 std::ostream &FlatCodeGen::TO_STATE_ACTION_SWITCH()
68 /* Walk the list of functions, printing the cases. */
69 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
70 /* Write out referenced actions. */
71 if ( act->numToStateRefs > 0 ) {
72 /* Write the case label, the action and the case break */
73 out << "\tcase " << act->actionId << ":\n";
74 ACTION( out, act, 0, false );
75 out << "\tbreak;\n";
79 genLineDirective( out );
80 return out;
83 std::ostream &FlatCodeGen::FROM_STATE_ACTION_SWITCH()
85 /* Walk the list of functions, printing the cases. */
86 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
87 /* Write out referenced actions. */
88 if ( act->numFromStateRefs > 0 ) {
89 /* Write the case label, the action and the case break */
90 out << "\tcase " << act->actionId << ":\n";
91 ACTION( out, act, 0, false );
92 out << "\tbreak;\n";
96 genLineDirective( out );
97 return out;
100 std::ostream &FlatCodeGen::EOF_ACTION_SWITCH()
102 /* Walk the list of functions, printing the cases. */
103 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
104 /* Write out referenced actions. */
105 if ( act->numEofRefs > 0 ) {
106 /* Write the case label, the action and the case break */
107 out << "\tcase " << act->actionId << ":\n";
108 ACTION( out, act, 0, true );
109 out << "\tbreak;\n";
113 genLineDirective( out );
114 return out;
118 std::ostream &FlatCodeGen::ACTION_SWITCH()
120 /* Walk the list of functions, printing the cases. */
121 for ( ActionList::Iter act = actionList; act.lte(); act++ ) {
122 /* Write out referenced actions. */
123 if ( act->numTransRefs > 0 ) {
124 /* Write the case label, the action and the case break */
125 out << "\tcase " << act->actionId << ":\n";
126 ACTION( out, act, 0, false );
127 out << "\tbreak;\n";
131 genLineDirective( out );
132 return out;
136 std::ostream &FlatCodeGen::FLAT_INDEX_OFFSET()
138 out << "\t";
139 int totalStateNum = 0, curIndOffset = 0;
140 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
141 /* Write the index offset. */
142 out << curIndOffset;
143 if ( !st.last() ) {
144 out << ", ";
145 if ( ++totalStateNum % IALL == 0 )
146 out << "\n\t";
149 /* Move the index offset ahead. */
150 if ( st->transList != 0 )
151 curIndOffset += keyOps->span( st->lowKey, st->highKey );
153 if ( st->defTrans != 0 )
154 curIndOffset += 1;
156 out << "\n";
157 return out;
160 std::ostream &FlatCodeGen::KEY_SPANS()
162 out << "\t";
163 int totalStateNum = 0;
164 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
165 /* Write singles length. */
166 unsigned long long span = 0;
167 if ( st->transList != 0 )
168 span = keyOps->span( st->lowKey, st->highKey );
169 out << span;
170 if ( !st.last() ) {
171 out << ", ";
172 if ( ++totalStateNum % IALL == 0 )
173 out << "\n\t";
176 out << "\n";
177 return out;
180 std::ostream &FlatCodeGen::TO_STATE_ACTIONS()
182 out << "\t";
183 int totalStateNum = 0;
184 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
185 /* Write any eof action. */
186 TO_STATE_ACTION(st);
187 if ( !st.last() ) {
188 out << ", ";
189 if ( ++totalStateNum % IALL == 0 )
190 out << "\n\t";
193 out << "\n";
194 return out;
197 std::ostream &FlatCodeGen::FROM_STATE_ACTIONS()
199 out << "\t";
200 int totalStateNum = 0;
201 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
202 /* Write any eof action. */
203 FROM_STATE_ACTION(st);
204 if ( !st.last() ) {
205 out << ", ";
206 if ( ++totalStateNum % IALL == 0 )
207 out << "\n\t";
210 out << "\n";
211 return out;
214 std::ostream &FlatCodeGen::EOF_ACTIONS()
216 out << "\t";
217 int totalStateNum = 0;
218 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
219 /* Write any eof action. */
220 EOF_ACTION(st);
221 if ( !st.last() ) {
222 out << ", ";
223 if ( ++totalStateNum % IALL == 0 )
224 out << "\n\t";
227 out << "\n";
228 return out;
231 std::ostream &FlatCodeGen::EOF_TRANS()
233 out << "\t";
234 int totalStateNum = 0;
235 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
236 /* Write any eof action. */
238 long trans = 0;
239 if ( st->eofTrans != 0 )
240 trans = st->eofTrans->id+1;
241 out << trans;
243 if ( !st.last() ) {
244 out << ", ";
245 if ( ++totalStateNum % IALL == 0 )
246 out << "\n\t";
249 out << "\n";
250 return out;
254 std::ostream &FlatCodeGen::COND_KEYS()
256 out << '\t';
257 int totalTrans = 0;
258 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
259 /* Emit just cond low key and cond high key. */
260 out << KEY( st->condLowKey ) << ", ";
261 out << KEY( st->condHighKey ) << ", ";
262 if ( ++totalTrans % IALL == 0 )
263 out << "\n\t";
266 /* Output one last number so we don't have to figure out when the last
267 * entry is and avoid writing a comma. */
268 out << 0 << "\n";
269 return out;
272 std::ostream &FlatCodeGen::COND_KEY_SPANS()
274 out << "\t";
275 int totalStateNum = 0;
276 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
277 /* Write singles length. */
278 unsigned long long span = 0;
279 if ( st->condList != 0 )
280 span = keyOps->span( st->condLowKey, st->condHighKey );
281 out << span;
282 if ( !st.last() ) {
283 out << ", ";
284 if ( ++totalStateNum % IALL == 0 )
285 out << "\n\t";
288 out << "\n";
289 return out;
292 std::ostream &FlatCodeGen::CONDS()
294 int totalTrans = 0;
295 out << '\t';
296 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
297 if ( st->condList != 0 ) {
298 /* Walk the singles. */
299 unsigned long long span = keyOps->span( st->condLowKey, st->condHighKey );
300 for ( unsigned long long pos = 0; pos < span; pos++ ) {
301 if ( st->condList[pos] != 0 )
302 out << st->condList[pos]->condSpaceId + 1 << ", ";
303 else
304 out << "0, ";
305 if ( ++totalTrans % IALL == 0 )
306 out << "\n\t";
311 /* Output one last number so we don't have to figure out when the last
312 * entry is and avoid writing a comma. */
313 out << 0 << "\n";
314 return out;
317 std::ostream &FlatCodeGen::COND_INDEX_OFFSET()
319 out << "\t";
320 int totalStateNum = 0, curIndOffset = 0;
321 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
322 /* Write the index offset. */
323 out << curIndOffset;
324 if ( !st.last() ) {
325 out << ", ";
326 if ( ++totalStateNum % IALL == 0 )
327 out << "\n\t";
330 /* Move the index offset ahead. */
331 if ( st->condList != 0 )
332 curIndOffset += keyOps->span( st->condLowKey, st->condHighKey );
334 out << "\n";
335 return out;
339 std::ostream &FlatCodeGen::KEYS()
341 out << '\t';
342 int totalTrans = 0;
343 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
344 /* Emit just low key and high key. */
345 out << KEY( st->lowKey ) << ", ";
346 out << KEY( st->highKey ) << ", ";
347 if ( ++totalTrans % IALL == 0 )
348 out << "\n\t";
351 /* Output one last number so we don't have to figure out when the last
352 * entry is and avoid writing a comma. */
353 out << 0 << "\n";
354 return out;
357 std::ostream &FlatCodeGen::INDICIES()
359 int totalTrans = 0;
360 out << '\t';
361 for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
362 if ( st->transList != 0 ) {
363 /* Walk the singles. */
364 unsigned long long span = keyOps->span( st->lowKey, st->highKey );
365 for ( unsigned long long pos = 0; pos < span; pos++ ) {
366 out << st->transList[pos]->id << ", ";
367 if ( ++totalTrans % IALL == 0 )
368 out << "\n\t";
372 /* The state's default index goes next. */
373 if ( st->defTrans != 0 )
374 out << st->defTrans->id << ", ";
376 if ( ++totalTrans % IALL == 0 )
377 out << "\n\t";
380 /* Output one last number so we don't have to figure out when the last
381 * entry is and avoid writing a comma. */
382 out << 0 << "\n";
383 return out;
386 std::ostream &FlatCodeGen::TRANS_TARGS()
388 /* Transitions must be written ordered by their id. */
389 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
390 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
391 transPtrs[trans->id] = trans;
393 /* Keep a count of the num of items in the array written. */
394 out << '\t';
395 int totalStates = 0;
396 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
397 /* Write out the target state. */
398 RedTransAp *trans = transPtrs[t];
399 out << trans->targ->id;
400 if ( t < redFsm->transSet.length()-1 ) {
401 out << ", ";
402 if ( ++totalStates % IALL == 0 )
403 out << "\n\t";
406 out << "\n";
407 delete[] transPtrs;
408 return out;
412 std::ostream &FlatCodeGen::TRANS_ACTIONS()
414 /* Transitions must be written ordered by their id. */
415 RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
416 for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
417 transPtrs[trans->id] = trans;
419 /* Keep a count of the num of items in the array written. */
420 out << '\t';
421 int totalAct = 0;
422 for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
423 /* Write the function for the transition. */
424 RedTransAp *trans = transPtrs[t];
425 TRANS_ACTION( trans );
426 if ( t < redFsm->transSet.length()-1 ) {
427 out << ", ";
428 if ( ++totalAct % IALL == 0 )
429 out << "\n\t";
432 out << "\n";
433 delete[] transPtrs;
434 return out;
437 void FlatCodeGen::LOCATE_TRANS()
439 out <<
440 " _keys = " << ARR_OFF( K(), "(" + CS() + "<<1)" ) << ";\n"
441 " _inds = " << ARR_OFF( I(), IO() + "[" + CS() + "]" ) << ";\n"
442 "\n"
443 " _slen = " << SP() << "[" << CS() << "];\n"
444 " _trans = _inds[ _slen > 0 && _keys[0] <=" << GET_WIDE_KEY() << " &&\n"
445 " " << GET_WIDE_KEY() << " <= _keys[1] ?\n"
446 " " << GET_WIDE_KEY() << " - _keys[0] : _slen ];\n"
447 "\n";
450 void FlatCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish )
452 ret << "{" << CS() << " = " << gotoDest << "; " <<
453 CTRL_FLOW() << "goto _again;}";
456 void FlatCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish )
458 ret << "{" << CS() << " = (";
459 INLINE_LIST( ret, ilItem->children, 0, inFinish );
460 ret << "); " << CTRL_FLOW() << "goto _again;}";
463 void FlatCodeGen::CURS( ostream &ret, bool inFinish )
465 ret << "(_ps)";
468 void FlatCodeGen::TARGS( ostream &ret, bool inFinish, int targState )
470 ret << "(" << CS() << ")";
473 void FlatCodeGen::NEXT( ostream &ret, int nextDest, bool inFinish )
475 ret << CS() << " = " << nextDest << ";";
478 void FlatCodeGen::NEXT_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish )
480 ret << CS() << " = (";
481 INLINE_LIST( ret, ilItem->children, 0, inFinish );
482 ret << ");";
485 void FlatCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish )
487 if ( prePushExpr != 0 ) {
488 ret << "{";
489 INLINE_LIST( ret, prePushExpr, 0, false );
492 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = " <<
493 callDest << "; " << CTRL_FLOW() << "goto _again;}";
495 if ( prePushExpr != 0 )
496 ret << "}";
500 void FlatCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish )
502 if ( prePushExpr != 0 ) {
503 ret << "{";
504 INLINE_LIST( ret, prePushExpr, 0, false );
507 ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = (";
508 INLINE_LIST( ret, ilItem->children, targState, inFinish );
509 ret << "); " << CTRL_FLOW() << "goto _again;}";
511 if ( prePushExpr != 0 )
512 ret << "}";
516 void FlatCodeGen::RET( ostream &ret, bool inFinish )
518 ret << "{" << CS() << " = " << STACK() << "[--" << TOP() << "];";
520 if ( postPopExpr != 0 ) {
521 ret << "{";
522 INLINE_LIST( ret, postPopExpr, 0, false );
523 ret << "}";
526 ret << CTRL_FLOW() << "goto _again;}";
529 void FlatCodeGen::BREAK( ostream &ret, int targState )
531 outLabelUsed = true;
532 ret << "{" << P() << "++; " << CTRL_FLOW() << "goto _out; }";
535 void FlatCodeGen::writeData()
537 /* If there are any transtion functions then output the array. If there
538 * are none, don't bother emitting an empty array that won't be used. */
539 if ( redFsm->anyActions() ) {
540 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
541 ACTIONS_ARRAY();
542 CLOSE_ARRAY() <<
543 "\n";
546 if ( redFsm->anyConditions() ) {
547 OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
548 COND_KEYS();
549 CLOSE_ARRAY() <<
550 "\n";
552 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() );
553 COND_KEY_SPANS();
554 CLOSE_ARRAY() <<
555 "\n";
557 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() );
558 CONDS();
559 CLOSE_ARRAY() <<
560 "\n";
562 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() );
563 COND_INDEX_OFFSET();
564 CLOSE_ARRAY() <<
565 "\n";
568 OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
569 KEYS();
570 CLOSE_ARRAY() <<
571 "\n";
573 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() );
574 KEY_SPANS();
575 CLOSE_ARRAY() <<
576 "\n";
578 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() );
579 FLAT_INDEX_OFFSET();
580 CLOSE_ARRAY() <<
581 "\n";
583 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
584 INDICIES();
585 CLOSE_ARRAY() <<
586 "\n";
588 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
589 TRANS_TARGS();
590 CLOSE_ARRAY() <<
591 "\n";
593 if ( redFsm->anyActions() ) {
594 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
595 TRANS_ACTIONS();
596 CLOSE_ARRAY() <<
597 "\n";
600 if ( redFsm->anyToStateActions() ) {
601 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
602 TO_STATE_ACTIONS();
603 CLOSE_ARRAY() <<
604 "\n";
607 if ( redFsm->anyFromStateActions() ) {
608 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
609 FROM_STATE_ACTIONS();
610 CLOSE_ARRAY() <<
611 "\n";
614 if ( redFsm->anyEofActions() ) {
615 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
616 EOF_ACTIONS();
617 CLOSE_ARRAY() <<
618 "\n";
621 if ( redFsm->anyEofTrans() ) {
622 OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex+1), ET() );
623 EOF_TRANS();
624 CLOSE_ARRAY() <<
625 "\n";
628 STATE_IDS();
631 void FlatCodeGen::COND_TRANSLATE()
633 out <<
634 " _widec = " << GET_KEY() << ";\n";
636 out <<
637 " _keys = " << ARR_OFF( CK(), "(" + CS() + "<<1)" ) << ";\n"
638 " _conds = " << ARR_OFF( C(), CO() + "[" + CS() + "]" ) << ";\n"
639 "\n"
640 " _slen = " << CSP() << "[" << CS() << "];\n"
641 " _cond = _slen > 0 && _keys[0] <=" << GET_WIDE_KEY() << " &&\n"
642 " " << GET_WIDE_KEY() << " <= _keys[1] ?\n"
643 " _conds[" << GET_WIDE_KEY() << " - _keys[0]] : 0;\n"
644 "\n";
646 out <<
647 " switch ( _cond ) {\n";
648 for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) {
649 CondSpace *condSpace = csi;
650 out << " case " << condSpace->condSpaceId + 1 << ": {\n";
651 out << TABS(2) << "_widec = " << CAST(WIDE_ALPH_TYPE()) << "(" <<
652 KEY(condSpace->baseKey) << " + (" << GET_KEY() <<
653 " - " << KEY(keyOps->minKey) << "));\n";
655 for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
656 out << TABS(2) << "if ( ";
657 CONDITION( out, *csi );
658 Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize());
659 out << " ) _widec += " << condValOffset << ";\n";
662 out << " }\n";
663 out << " break;\n";
666 SWITCH_DEFAULT();
668 out <<
669 " }\n";
672 void FlatCodeGen::writeExec()
674 testEofUsed = false;
675 outLabelUsed = false;
677 out <<
678 " {\n"
679 " int _slen";
681 if ( redFsm->anyRegCurStateRef() )
682 out << ", _ps";
684 out <<
685 ";\n"
686 " int _trans";
688 if ( redFsm->anyConditions() )
689 out << ", _cond";
690 out << ";\n";
692 if ( redFsm->anyToStateActions() ||
693 redFsm->anyRegActions() || redFsm->anyFromStateActions() )
695 out <<
696 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
697 " " << UINT() << " _nacts;\n";
700 out <<
701 " " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
702 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << "_inds;\n";
704 if ( redFsm->anyConditions() ) {
705 out <<
706 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxCond) << POINTER() << "_conds;\n"
707 " " << WIDE_ALPH_TYPE() << " _widec;\n";
710 out << "\n";
712 if ( hasEnd ) {
713 testEofUsed = true;
714 out <<
715 " if ( " << P() << " == " << PE() << " )\n"
716 " goto _test_eof;\n";
719 if ( redFsm->errState != 0 ) {
720 outLabelUsed = true;
721 out <<
722 " if ( " << CS() << " == " << redFsm->errState->id << " )\n"
723 " goto _out;\n";
726 out << "_resume:\n";
728 if ( redFsm->anyFromStateActions() ) {
729 out <<
730 " _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
731 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
732 " while ( _nacts-- > 0 ) {\n"
733 " switch ( *_acts++ ) {\n";
734 FROM_STATE_ACTION_SWITCH();
735 SWITCH_DEFAULT() <<
736 " }\n"
737 " }\n"
738 "\n";
741 if ( redFsm->anyConditions() )
742 COND_TRANSLATE();
744 LOCATE_TRANS();
746 if ( redFsm->anyEofTrans() )
747 out << "_eof_trans:\n";
749 if ( redFsm->anyRegCurStateRef() )
750 out << " _ps = " << CS() << ";\n";
752 out <<
753 " " << CS() << " = " << TT() << "[_trans];\n"
754 "\n";
756 if ( redFsm->anyRegActions() ) {
757 out <<
758 " if ( " << TA() << "[_trans] == 0 )\n"
759 " goto _again;\n"
760 "\n"
761 " _acts = " << ARR_OFF( A(), TA() + "[_trans]" ) << ";\n"
762 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
763 " while ( _nacts-- > 0 ) {\n"
764 " switch ( *(_acts++) )\n {\n";
765 ACTION_SWITCH();
766 SWITCH_DEFAULT() <<
767 " }\n"
768 " }\n"
769 "\n";
772 if ( redFsm->anyRegActions() || redFsm->anyActionGotos() ||
773 redFsm->anyActionCalls() || redFsm->anyActionRets() )
774 out << "_again:\n";
776 if ( redFsm->anyToStateActions() ) {
777 out <<
778 " _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
779 " _nacts = " << CAST(UINT()) << " *_acts++;\n"
780 " while ( _nacts-- > 0 ) {\n"
781 " switch ( *_acts++ ) {\n";
782 TO_STATE_ACTION_SWITCH();
783 SWITCH_DEFAULT() <<
784 " }\n"
785 " }\n"
786 "\n";
789 if ( redFsm->errState != 0 ) {
790 outLabelUsed = true;
791 out <<
792 " if ( " << CS() << " == " << redFsm->errState->id << " )\n"
793 " goto _out;\n";
796 if ( hasEnd ) {
797 out <<
798 " if ( ++" << P() << " != " << PE() << " )\n"
799 " goto _resume;\n";
801 else {
802 out <<
803 " " << P() << " += 1;\n"
804 " goto _resume;\n";
807 if ( testEofUsed )
808 out << " _test_eof: {}\n";
810 if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
811 out <<
812 " if ( " << P() << " == " << EOFV() << " )\n"
813 " {\n";
815 if ( redFsm->anyEofTrans() ) {
816 out <<
817 " if ( " << ET() << "[" << CS() << "] > 0 ) {\n"
818 " _trans = " << ET() << "[" << CS() << "] - 1;\n"
819 " goto _eof_trans;\n"
820 " }\n";
823 if ( redFsm->anyEofActions() ) {
824 out <<
825 " " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) <<
826 POINTER() << "__acts = " <<
827 ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
828 " " << UINT() << " __nacts = " << CAST(UINT()) << " *__acts++;\n"
829 " while ( __nacts-- > 0 ) {\n"
830 " switch ( *__acts++ ) {\n";
831 EOF_ACTION_SWITCH();
832 SWITCH_DEFAULT() <<
833 " }\n"
834 " }\n";
837 out <<
838 " }\n"
839 "\n";
842 if ( outLabelUsed )
843 out << " _out: {}\n";
845 out << " }\n";