"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/gotoloop.cc" between
ragel-7.0.0.10.tar.gz and ragel-7.0.0.11.tar.gz

About: Ragel compiles executable finite state machines from regular languages (C, C++, Obj-C, C#, D, Java, Go and Ruby). Development version.

gotoloop.cc  (ragel-7.0.0.10):gotoloop.cc  (ragel-7.0.0.11)
/* /*
* Copyright 2001-2014 Adrian Thurston <thurston@colm.net> * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the * deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is * sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in al l * The above copyright notice and this permission notice shall be included in al l
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
skipping to change at line 31 skipping to change at line 31
*/ */
#include "ragel.h" #include "ragel.h"
#include "gotoloop.h" #include "gotoloop.h"
#include "redfsm.h" #include "redfsm.h"
#include "bstmap.h" #include "bstmap.h"
#include "gendata.h" #include "gendata.h"
#include "parsedata.h" #include "parsedata.h"
#include "inputdata.h" #include "inputdata.h"
void SwitchLoopGoto::tableDataPass() std::ostream &SwitchGotoLoop::ACTION_SWITCH()
{
taActions();
taToStateActions();
taFromStateActions();
taEofActions();
taNfaTargs();
taNfaOffsets();
taNfaPushActions();
taNfaPopTrans();
}
void SwitchLoopGoto::genAnalysis()
{
/* For directly executable machines there is no required state
* ordering. Choose a depth-first ordering to increase the
* potential for fall-throughs. */
redFsm->depthFirstOrdering();
/* Choose default transitions and the single transition. */
redFsm->chooseDefaultSpan();
/* Choose single. */
redFsm->moveSelectTransToSingle();
/* If any errors have occured in the input file then don't write anything
. */
if ( red->id->errorCount > 0 )
return;
/* Anlayze Machine will find the final action reference counts, among oth
er
* things. We will use these in reporting the usage of fsm directives in
* action code. */
red->analyzeMachine();
/* Run the analysis pass over the table data. */
setTableState( TableArray::AnalyzePass );
tableDataPass();
/* Switch the tables over to the code gen mode. */
setTableState( TableArray::GeneratePass );
}
void SwitchLoopGoto::writeData()
{
if ( redFsm->anyActions() )
taActions();
if ( redFsm->anyToStateActions() )
taToStateActions();
if ( redFsm->anyFromStateActions() )
taFromStateActions();
if ( redFsm->anyEofActions() )
taEofActions();
taNfaTargs();
taNfaOffsets();
taNfaPushActions();
taNfaPopTrans();
STATE_IDS();
}
std::ostream &SwitchLoopGoto::ACTION_SWITCH()
{ {
/* Walk the list of functions, printing the cases. */ /* Walk the list of functions, printing the cases. */
for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) { for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) {
/* Write out referenced actions. */ /* Write out referenced actions. */
if ( act->numTransRefs > 0 ) { if ( act->numTransRefs > 0 ) {
/* Write the case label, the action and the case break. * / /* Write the case label, the action and the case break. * /
out << "\t" << CASE( STR( act->actionId ) ) << "{\n"; out << "\t" << CASE( STR( act->actionId ) ) << "{\n";
ACTION( out, act, IlOpts( 0, false, false ) ); ACTION( out, act, IlOpts( 0, false, false ) );
out << "\n\t" << CEND() << "}\n"; out << "\n\t" << CEND() << "}\n";
} }
} }
return out; return out;
} }
std::ostream &SwitchLoopGoto::EOF_ACTION_SWITCH() std::ostream &SwitchGotoLoop::EOF_ACTION_SWITCH()
{ {
/* Walk the list of functions, printing the cases. */ /* Walk the list of functions, printing the cases. */
for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) { for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) {
/* Write out referenced actions. */ /* Write out referenced actions. */
if ( act->numEofRefs > 0 ) { if ( act->numEofRefs > 0 ) {
/* Write the case label, the action and the case break. * / /* Write the case label, the action and the case break. * /
out << "\t" << CASE( STR( act->actionId ) ) << "{\n"; out << "\t" << CASE( STR( act->actionId ) ) << "{\n";
ACTION( out, act, IlOpts( 0, true, false ) ); ACTION( out, act, IlOpts( 0, true, false ) );
out << "\n\t" << CEND() << "}\n"; out << "\n\t" << CEND() << "}\n";
} }
} }
return out; return out;
} }
std::ostream &SwitchLoopGoto::FROM_STATE_ACTION_SWITCH() std::ostream &SwitchGotoLoop::FROM_STATE_ACTION_SWITCH()
{ {
/* Walk the list of functions, printing the cases. */ /* Walk the list of functions, printing the cases. */
for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) { for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) {
/* Write out referenced actions. */ /* Write out referenced actions. */
if ( act->numFromStateRefs > 0 ) { if ( act->numFromStateRefs > 0 ) {
/* Write the case label, the action and the case break. * / /* Write the case label, the action and the case break. * /
out << "\t" << CASE( STR( act->actionId ) ) << "{\n"; out << "\t" << CASE( STR( act->actionId ) ) << "{\n";
ACTION( out, act, IlOpts( 0, false, false ) ); ACTION( out, act, IlOpts( 0, false, false ) );
out << "\n\t" << CEND() << "}\n"; out << "\n\t" << CEND() << "}\n";
} }
} }
return out; return out;
} }
std::ostream &SwitchLoopGoto::TO_STATE_ACTION_SWITCH() std::ostream &SwitchGotoLoop::TO_STATE_ACTION_SWITCH()
{ {
/* Walk the list of functions, printing the cases. */ /* Walk the list of functions, printing the cases. */
for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) { for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) {
/* Write out referenced actions. */ /* Write out referenced actions. */
if ( act->numToStateRefs > 0 ) { if ( act->numToStateRefs > 0 ) {
/* Write the case label, the action and the case break. * / /* Write the case label, the action and the case break. * /
out << "\t" << CASE( STR( act->actionId ) ) << "{\n"; out << "\t" << CASE( STR( act->actionId ) ) << "{\n";
ACTION( out, act, IlOpts( 0, false, false ) ); ACTION( out, act, IlOpts( 0, false, false ) );
out << "\n\t" << CEND() << "}\n"; out << "\n\t" << CEND() << "}\n";
} }
} }
return out; return out;
} }
void SwitchLoopGoto::NFA_PUSH_ACTION( RedNfaTarg *targ ) void SwitchGotoLoop::NFA_PUSH_ACTION( RedNfaTarg *targ )
{ {
int act = 0; int act = 0;
if ( targ->push != 0 ) if ( targ->push != 0 )
act = targ->push->actListId+1; act = targ->push->actListId+1;
nfaPushActions.value( act ); nfaPushActions.value( act );
} }
void SwitchLoopGoto::NFA_POP_TEST( RedNfaTarg *targ ) void SwitchGotoLoop::NFA_POP_TEST( RedNfaTarg *targ )
{ {
int act = 0; int act = 0;
if ( targ->popTest != 0 ) if ( targ->popTest != 0 )
act = targ->popTest->actListId+1; act = targ->popTest->actListId+1;
nfaPopTrans.value( act ); nfaPopTrans.value( act );
} }
std::ostream &SwitchLoopGoto::EXEC_FUNCS() std::ostream &SwitchGotoLoop::EXEC_FUNCS()
{ {
/* Make labels that set acts and jump to execFuncs. Loop func indicies. * / /* Make labels that set acts and jump to execFuncs. Loop func indicies. * /
for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); r edAct++ ) { for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); r edAct++ ) {
if ( redAct->numTransRefs > 0 ) { if ( redAct->numTransRefs > 0 ) {
out << " f" << redAct->actListId << ": " << out << " f" << redAct->actListId << ": " <<
"_acts = " << OFFSET( ARR_REF( actions ), itoa( r edAct->location+1 ) ) << ";" "" << acts << " = " << OFFSET( ARR_REF( actions ) , itoa( redAct->location+1 ) ) << ";"
" goto execFuncs;\n"; " goto execFuncs;\n";
} }
} }
out << out <<
"\n" "\n"
"execFuncs:\n"; "execFuncs:\n";
if ( redFsm->anyRegNbreak() ) if ( redFsm->anyRegNbreak() )
out << " _nbreak = 0;\n"; out << " _nbreak = 0;\n";
out << out <<
" _nacts = " << CAST( UINT() ) << DEREF( ARR_REF( actions ) " " << nacts << " = " << CAST( UINT() ) << DEREF( ARR_REF(
, "_acts" ) << ";\n" actions ), "" + string(acts) + "" ) << ";\n"
" _acts += 1;\n" " " << acts << " += 1;\n"
" while ( _nacts > 0 ) {\n" " while ( " << nacts << " > 0 ) {\n"
" switch ( " << DEREF( ARR_REF( actions ), "_acts" " switch ( " << DEREF( ARR_REF( actions ), "" + str
) << " ) {\n"; ing(acts) + "" ) << " ) {\n";
ACTION_SWITCH() << ACTION_SWITCH() <<
" }\n" " }\n"
" _acts += 1;\n" " " << acts << " += 1;\n"
" _nacts -= 1;\n" " " << nacts << " -= 1;\n"
" }\n" " }\n"
"\n"; "\n";
if ( redFsm->anyRegNbreak() ) { if ( redFsm->anyRegNbreak() ) {
out << out <<
" if ( _nbreak == 1 )\n" " if ( _nbreak == 1 )\n"
" goto _out;\n"; " goto _out;\n";
outLabelUsed = true; outLabelUsed = true;
} }
out << out <<
" goto _again;\n"; " goto _again;\n";
return out; return out;
} }
void SwitchLoopGoto::NFA_FROM_STATE_ACTION_EXEC() void SwitchGotoLoop::NFA_FROM_STATE_ACTION_EXEC()
{ {
if ( redFsm->anyFromStateActions() ) { if ( redFsm->anyFromStateActions() ) {
out << out <<
" _acts = " << OFFSET( ARR_REF( actions ), ARR_REF( " " << acts << " = " << OFFSET( ARR_REF( actions ),
fromStateActions ) + "[nfa_bp[nfa_len].state]" ) << ";\n" ARR_REF( fromStateActions ) + "[nfa_bp[nfa_len].state]" ) << ";\n"
" _nacts = " << CAST( UINT() ) << DEREF( ARR_REF( a " " << nacts << " = " << CAST( UINT() ) << DEREF( A
ctions ), "_acts" ) << ";\n" RR_REF( actions ), "" + string(acts) + "" ) << ";\n"
" _acts += 1;\n" " " << acts << " += 1;\n"
" while ( _nacts > 0 ) {\n" " while ( " << nacts << " > 0 ) {\n"
" switch ( " << DEREF( ARR_REF( actions ), " switch ( " << DEREF( ARR_REF( actions ),
"_acts" ) << " ) {\n"; "" + string(acts) + "" ) << " ) {\n";
FROM_STATE_ACTION_SWITCH() << FROM_STATE_ACTION_SWITCH() <<
" }\n" " }\n"
" _nacts -= 1;\n" " " << nacts << " -= 1;\n"
" _acts += 1;\n" " " << acts << " += 1;\n"
" }\n" " }\n"
"\n"; "\n";
} }
} }
void SwitchLoopGoto::writeExec() void SwitchGotoLoop::FROM_STATE_ACTIONS()
{ {
testEofUsed = false;
outLabelUsed = false;
out << " {\n";
if ( redFsm->anyRegCurStateRef() )
out << " int _ps = 0;\n";
if ( redFsm->anyToStateActions() || redFsm->anyRegActions()
|| redFsm->anyFromStateActions() )
{
out <<
" " << INDEX( ARR_TYPE( actions ), "_acts" ) << ";\
n"
" " << UINT() << " _nacts;\n";
}
out << "\n";
if ( redFsm->anyRegNbreak() ) {
out << " int _nbreak;\n";
}
if ( !noEnd ) {
testEofUsed = true;
out <<
" if ( " << P() << " == " << PE() << " )\n"
" goto _test_eof;\n";
}
if ( redFsm->errState != 0 ) {
outLabelUsed = true;
out <<
" if ( " << vCS() << " == " << redFsm->errState->id
<< " )\n"
" goto _out;\n";
}
out << "_resume:\n";
if ( redFsm->anyFromStateActions() ) { if ( redFsm->anyFromStateActions() ) {
out << out <<
" _acts = " << OFFSET( ARR_REF( actions ), " " << acts << " = " << OFFSET( ARR_REF( actions ),
ARR_REF( fromStateActions ) + "[" + vCS() + "]" ) << ";\n" ARR_REF( fromStateActions ) + "[" + vCS() + "]" ) << ";\n"
" _nacts = " << CAST( UINT() ) << DEREF( ARR_REF( a " " << nacts << " = " << CAST( UINT() ) << DEREF( A
ctions ), "_acts" ) << "; _acts += 1;\n" RR_REF( actions ), "" + string(acts) + "" ) << "; " << acts << " += 1;\n"
" while ( _nacts > 0 ) {\n" " while ( " << nacts << " > 0 ) {\n"
" switch ( " << DEREF( ARR_REF( actions ), " switch ( " << DEREF( ARR_REF( actions ),
"_acts" ) << " ) {\n"; "" + string(acts) + "" ) << " ) {\n";
FROM_STATE_ACTION_SWITCH() << FROM_STATE_ACTION_SWITCH() <<
" }\n" " }\n"
" _acts += 1;\n" " " << acts << " += 1;\n"
" _nacts -= 1;\n" " " << nacts << " -= 1;\n"
" }\n" " }\n"
"\n"; "\n";
} }
}
NFA_PUSH(); void SwitchGotoLoop::TO_STATE_ACTIONS()
{
out <<
" switch ( " << vCS() << " ) {\n";
STATE_GOTOS() <<
" }\n"
"\n";
TRANSITIONS() <<
"\n";
if ( redFsm->anyRegActions() )
EXEC_FUNCS() << "\n";
out << "_again:\n";
if ( redFsm->anyToStateActions() ) { if ( redFsm->anyToStateActions() ) {
out << out <<
" _acts = " << OFFSET( ARR_REF( actions ), " " << acts << " = " << OFFSET( ARR_REF( actions ),
ARR_REF( toStateActions ) + "[" + vCS() + "]" ) << ";\n" ARR_REF( toStateActions ) + "[" + vCS() + "]" ) << ";\n"
" _nacts = " << CAST( UINT() ) << DEREF( ARR_REF( a " " << nacts << " = " << CAST( UINT() ) << DEREF( A
ctions ), "_acts" ) << "; _acts += 1;\n" RR_REF( actions ), "" + string(acts) + "" ) << "; " << acts << " += 1;\n"
" while ( _nacts > 0 ) {\n" " while ( " << nacts << " > 0 ) {\n"
" switch ( " << DEREF( ARR_REF( actions ), " switch ( " << DEREF( ARR_REF( actions ),
"_acts" ) << " ) {\n"; "" + string(acts) + "" ) << " ) {\n";
TO_STATE_ACTION_SWITCH() << TO_STATE_ACTION_SWITCH() <<
" }\n" " }\n"
" _acts += 1;\n" " " << acts << " += 1;\n"
" _nacts -= 1;\n" " " << nacts << " -= 1;\n"
" }\n" " }\n"
"\n"; "\n";
} }
}
if ( redFsm->errState != 0 ) { void SwitchGotoLoop::REG_ACTIONS()
outLabelUsed = true; {
out << }
" if ( " << vCS() << " == " << redFsm->errState->id
<< " )\n"
" goto _out;\n";
}
if ( !noEnd ) {
out <<
" " << P() << " += 1;\n"
" if ( " << P() << " != " << PE() << " )\n"
" goto _resume;\n";
}
else {
out <<
" " << P() << " += 1;\n"
" goto _resume;\n";
}
if ( testEofUsed )
out << " _test_eof: {}\n";
if ( redFsm->anyEofTrans() || redFsm->anyEofActions() ) {
out <<
" if ( " << P() << " == " << vEOF() << " )\n"
" {\n";
if ( redFsm->anyEofTrans() ) {
out <<
" switch ( " << vCS() << " ) {\n";
for ( RedStateList::Iter st = redFsm->stateList; st.lte()
; st++ ) {
if ( st->eofTrans != 0 ) {
RedCondPair *cond = st->eofTrans->outCond
( 0 );
out << " case " << st->id << ": go
to ctr" << cond->id << ";\n";
}
}
out <<
" }\n";
}
if ( redFsm->anyEofActions() ) {
out <<
" " << INDEX( ARR_TYPE( actions ), "__acts"
) << ";\n"
" " << UINT() << " __nacts;\n"
" __acts = " << OFFSET( ARR_REF( actions ),
ARR_REF( eofActions ) + "[" + vCS
() + "]" ) << ";\n"
" __nacts = " << CAST( UINT() ) << DEREF( A
RR_REF( actions ), "__acts" ) << "; __acts += 1;\n"
" while ( __nacts > 0 ) {\n"
" switch ( " << DEREF( ARR_REF( act
ions ), "__acts" ) << " ) {\n";
EOF_ACTION_SWITCH() <<
" }\n"
" __acts += 1;\n"
" __nacts -= 1;\n"
" }\n";
}
void SwitchGotoLoop::EOF_ACTIONS()
{
if ( redFsm->anyEofActions() ) {
out << out <<
" }\n" " " << INDEX( ARR_TYPE( actions ), "__acts" ) << ";
"\n"; \n"
" " << UINT() << " __nacts;\n"
" __acts = " << OFFSET( ARR_REF( actions ),
ARR_REF( eofActions ) + "[" + vCS() + "]"
) << ";\n"
" __nacts = " << CAST( UINT() ) << DEREF( ARR_REF(
actions ), "__acts" ) << "; __acts += 1;\n"
" while ( __nacts > 0 ) {\n"
" switch ( " << DEREF( ARR_REF( actions ),
"__acts" ) << " ) {\n";
EOF_ACTION_SWITCH() <<
" }\n"
" __acts += 1;\n"
" __nacts -= 1;\n"
" }\n";
} }
if ( outLabelUsed )
out << " _out: {}\n";
NFA_POP();
out << " }\n";
} }
 End of changes. 29 change blocks. 
241 lines changed or deleted 71 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)