Moved the value limits which are collected during machine analysis time from
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Tue, 30 Jan 2007 18:52:31 +0000 (18:52 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Tue, 30 Jan 2007 18:52:31 +0000 (18:52 +0000)
CodeGenData to RedFsm.

git-svn-id: http://svn.complang.org/ragel/trunk@38 052ea7fc-9027-0410-9066-f65837a77df0

15 files changed:
rlcodegen/fflatcodegen.cpp
rlcodegen/fgotocodegen.cpp
rlcodegen/flatcodegen.cpp
rlcodegen/fsmcodegen.cpp
rlcodegen/fsmcodegen.h
rlcodegen/ftabcodegen.cpp
rlcodegen/gendata.cpp
rlcodegen/gotocodegen.cpp
rlcodegen/ipgotocodegen.cpp
rlcodegen/ipgotocodegen.h
rlcodegen/javacodegen.cpp
rlcodegen/redfsm.cpp
rlcodegen/redfsm.h
rlcodegen/splitcodegen.cpp
rlcodegen/tabcodegen.cpp

index 9224627..4e43b33 100644 (file)
@@ -151,23 +151,23 @@ std::ostream &FFlatCodeGen::ACTION_SWITCH()
 
 void FFlatCodeGen::writeOutData()
 {
-       if ( anyConditions() ) {
+       if ( redFsm->anyConditions() ) {
                OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
                COND_KEYS();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCondSpan), CSP() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() );
                COND_KEY_SPANS();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCond), C() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() );
                CONDS();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCondIndexOffset), CO() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() );
                COND_INDEX_OFFSET();
                CLOSE_ARRAY() <<
                "\n";
@@ -178,49 +178,49 @@ void FFlatCodeGen::writeOutData()
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxSpan), SP() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() );
        KEY_SPANS();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxFlatIndexOffset), IO() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() );
        FLAT_INDEX_OFFSET();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxIndex), I() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
        INDICIES();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
        TRANS_TARGS();
        CLOSE_ARRAY() <<
        "\n";
 
-       if ( anyActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActListId), TA() );
+       if ( redFsm->anyActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() );
                TRANS_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyToStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc),  TSA() );
+       if ( redFsm->anyToStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc),  TSA() );
                TO_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyFromStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+       if ( redFsm->anyFromStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
                FROM_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyEofActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActListId), EA() );
+       if ( redFsm->anyEofActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), EA() );
                EOF_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
@@ -251,24 +251,24 @@ void FFlatCodeGen::writeOutExec()
                "       {\n"
                "       int _slen";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << ", _ps";
        
        out << ";\n";
        out << "        int _trans";
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                out << ", _cond";
 
        out << ";\n";
 
        out <<
                "       " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
-               "       " << PTR_CONST() << ARRAY_TYPE(maxIndex) << POINTER() << "_inds;\n";
+               "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << "_inds;\n";
 
-       if ( anyConditions() ) {
+       if ( redFsm->anyConditions() ) {
                out << 
-                       "       " << PTR_CONST() << ARRAY_TYPE(maxCond) << POINTER() << "_conds;\n"
+                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxCond) << POINTER() << "_conds;\n"
                        "       " << WIDE_ALPH_TYPE() << " _widec;\n";
        }
 
@@ -288,7 +288,7 @@ void FFlatCodeGen::writeOutExec()
                        "               goto _out;\n";
        }
 
-       if ( anyFromStateActions() ) {
+       if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       switch ( " << FSA() << "[" << CS() << "] ) {\n";
                        FROM_STATE_ACTION_SWITCH();
@@ -297,18 +297,18 @@ void FFlatCodeGen::writeOutExec()
                        "\n";
        }
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                COND_TRANSLATE();
 
        LOCATE_TRANS();
        
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << "        _ps = " << CS() << ";\n";
 
        out << 
                "       " << CS() << " = " << TT() << "[_trans];\n\n";
 
-       if ( anyRegActions() ) {
+       if ( redFsm->anyRegActions() ) {
                out << 
                        "       if ( " << TA() << "[_trans] == 0 )\n"
                        "               goto _again;\n"
@@ -320,10 +320,11 @@ void FFlatCodeGen::writeOutExec()
                        "\n";
        }
 
-       if ( anyRegActions() || anyActionGotos() || anyActionCalls() || anyActionRets() )
+       if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
+                       redFsm->anyActionCalls() || redFsm->anyActionRets() )
                out << "_again:\n";
 
-       if ( anyToStateActions() ) {
+       if ( redFsm->anyToStateActions() ) {
                out <<
                        "       switch ( " << TSA() << "[" << CS() << "] ) {\n";
                        TO_STATE_ACTION_SWITCH();
@@ -351,7 +352,7 @@ void FFlatCodeGen::writeOutExec()
 
 void FFlatCodeGen::writeOutEOF()
 {
-       if ( anyEofActions() ) {
+       if ( redFsm->anyEofActions() ) {
                out <<
                        "       {\n"
                        "       switch ( " << EA() << "[" << CS() << "] ) {\n";
index 72a5ba5..7012b10 100644 (file)
@@ -168,22 +168,22 @@ void FGotoCodeGen::writeOutData()
                        "\n";
        }
 
-       if ( anyToStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+       if ( redFsm->anyToStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
                TO_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyFromStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+       if ( redFsm->anyFromStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
                FROM_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyEofActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), EA() );
+       if ( redFsm->anyEofActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
                EOF_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
@@ -196,10 +196,10 @@ void FGotoCodeGen::writeOutExec()
 
        out << "        {\n";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << "        int _ps = 0;\n";
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                out << "        " << WIDE_ALPH_TYPE() << " _widec;\n";
 
        if ( cgd->hasEnd ) {
@@ -211,7 +211,7 @@ void FGotoCodeGen::writeOutExec()
 
        out << "_resume:\n";
 
-       if ( anyFromStateActions() ) {
+       if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       switch ( " << FSA() << "[" << CS() << "] ) {\n";
                        FROM_STATE_ACTION_SWITCH();
@@ -229,12 +229,12 @@ void FGotoCodeGen::writeOutExec()
                TRANSITIONS() << 
                "\n";
 
-       if ( anyRegActions() )
+       if ( redFsm->anyRegActions() )
                EXEC_ACTIONS() << "\n";
 
        out << "_again:\n";
 
-       if ( anyToStateActions() ) {
+       if ( redFsm->anyToStateActions() ) {
                out <<
                        "       switch ( " << TSA() << "[" << CS() << "] ) {\n";
                        TO_STATE_ACTION_SWITCH();
@@ -263,7 +263,7 @@ void FGotoCodeGen::writeOutExec()
 
 void FGotoCodeGen::writeOutEOF()
 {
-       if ( anyEofActions() ) {
+       if ( redFsm->anyEofActions() ) {
                out <<
                        "       {\n"
                        "       switch ( " << EA() << "[" << CS() << "] ) {\n";
index 1567073..c3d0354 100644 (file)
@@ -490,30 +490,30 @@ void FlatCodeGen::writeOutData()
 {
        /* If there are any transtion functions then output the array. If there
         * are none, don't bother emitting an empty array that won't be used. */
-       if ( anyActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActArrItem), A() );
+       if ( redFsm->anyActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
                ACTIONS_ARRAY();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyConditions() ) {
+       if ( redFsm->anyConditions() ) {
                OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
                COND_KEYS();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCondSpan), CSP() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpan), CSP() );
                COND_KEY_SPANS();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCond), C() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCond), C() );
                CONDS();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCondIndexOffset), CO() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondIndexOffset), CO() );
                COND_INDEX_OFFSET();
                CLOSE_ARRAY() <<
                "\n";
@@ -524,49 +524,49 @@ void FlatCodeGen::writeOutData()
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxSpan), SP() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSpan), SP() );
        KEY_SPANS();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxFlatIndexOffset), IO() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxFlatIndexOffset), IO() );
        FLAT_INDEX_OFFSET();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxIndex), I() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
        INDICIES();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
        TRANS_TARGS();
        CLOSE_ARRAY() <<
        "\n";
 
-       if ( anyActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TA() );
+       if ( redFsm->anyActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
                TRANS_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyToStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+       if ( redFsm->anyToStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
                TO_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyFromStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+       if ( redFsm->anyFromStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
                FROM_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyEofActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), EA() );
+       if ( redFsm->anyEofActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
                EOF_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
@@ -638,30 +638,32 @@ void FlatCodeGen::writeOutExec()
                "       {\n"
                "       int _slen";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << ", _ps";
 
        out << 
                ";\n"
                "       int _trans";
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                out << ", _cond";
        out << ";\n";
 
-       if ( anyToStateActions() || anyRegActions() || anyFromStateActions() ) {
+       if ( redFsm->anyToStateActions() || 
+                       redFsm->anyRegActions() || redFsm->anyFromStateActions() )
+       {
                out << 
-                       "       " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts;\n"
+                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
                        "       " << UINT() << " _nacts;\n"; 
        }
 
        out <<
                "       " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
-               "       " << PTR_CONST() << ARRAY_TYPE(maxIndex) << POINTER() << "_inds;\n";
+               "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxIndex) << POINTER() << "_inds;\n";
 
-       if ( anyConditions() ) {
+       if ( redFsm->anyConditions() ) {
                out << 
-                       "       " << PTR_CONST() << ARRAY_TYPE(maxCond) << POINTER() << "_conds;\n"
+                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxCond) << POINTER() << "_conds;\n"
                        "       " << WIDE_ALPH_TYPE() << " _widec;\n";
        }
 
@@ -683,7 +685,7 @@ void FlatCodeGen::writeOutExec()
                        "               goto _out;\n";
        }
 
-       if ( anyFromStateActions() ) {
+       if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
                        "       _nacts = " << CAST(UINT()) << " *_acts++;\n"
@@ -696,19 +698,19 @@ void FlatCodeGen::writeOutExec()
                        "\n";
        }
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                COND_TRANSLATE();
 
        LOCATE_TRANS();
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << "        _ps = " << CS() << ";\n";
 
        out <<
                "       " << CS() << " = " << TT() << "[_trans];\n"
                "\n";
 
-       if ( anyRegActions() ) {
+       if ( redFsm->anyRegActions() ) {
                out <<
                        "       if ( " << TA() << "[_trans] == 0 )\n"
                        "               goto _again;\n"
@@ -724,10 +726,11 @@ void FlatCodeGen::writeOutExec()
                        "\n";
        }
 
-       if ( anyRegActions() || anyActionGotos() || anyActionCalls() || anyActionRets() )
+       if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
+                       redFsm->anyActionCalls() || redFsm->anyActionRets() )
                out << "_again:\n";
 
-       if ( anyToStateActions() ) {
+       if ( redFsm->anyToStateActions() ) {
                out <<
                        "       _acts = " << ARR_OFF( A(),  TSA() + "[" + CS() + "]" ) << ";\n"
                        "       _nacts = " << CAST(UINT()) << " *_acts++;\n"
@@ -759,10 +762,10 @@ void FlatCodeGen::writeOutExec()
 
 void FlatCodeGen::writeOutEOF()
 {
-       if ( anyEofActions() ) {
+       if ( redFsm->anyEofActions() ) {
                out << 
                        "       {\n"
-                       "       " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts = " << 
+                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts = " << 
                                        ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
                        "       " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
                        "       while ( _nacts-- > 0 ) {\n"
index 0ae1c16..8eab761 100644 (file)
@@ -54,30 +54,10 @@ FsmCodeGen::FsmCodeGen( ostream &out )
 :
        cgd(0), 
        redFsm(0), 
-       out(out),
-       bAnyToStateActions(false),
-       bAnyFromStateActions(false),
-       bAnyRegActions(false),
-       bAnyEofActions(false),
-       bAnyActionGotos(false),
-       bAnyActionCalls(false),
-       bAnyActionRets(false),
-       bAnyRegActionRets(false),
-       bAnyRegActionByValControl(false),
-       bAnyRegNextStmt(false),
-       bAnyRegCurStateRef(false),
-       bAnyRegBreak(false),
-       bAnyLmSwitchError(false),
-       bAnyConditions(false)
+       out(out)
 {
 }
 
-/* Does the machine have any actions. */
-bool FsmCodeGen::anyActions()
-{
-       return redFsm->actionMap.length() > 0;
-}
-
 unsigned int FsmCodeGen::arrayTypeSize( unsigned long maxVal )
 {
        long long maxValLL = (long long) maxVal;
@@ -168,7 +148,7 @@ string FsmCodeGen::ACCESS()
 
 string FsmCodeGen::GET_WIDE_KEY()
 {
-       if ( anyConditions() ) 
+       if ( redFsm->anyConditions() ) 
                return "_widec";
        else
                return GET_KEY();
@@ -466,7 +446,7 @@ void FsmCodeGen::writeOutInit()
        out << "\t" << CS() << " = " << START() << ";\n";
        
        /* If there are any calls, then the stack top needs initialization. */
-       if ( anyActionCalls() || anyActionRets() )
+       if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )
                out << "\t" << TOP() << " = 0;\n";
 
        if ( cgd->hasLongestMatch ) {
@@ -500,10 +480,10 @@ string FsmCodeGen::ALPH_TYPE()
 string FsmCodeGen::WIDE_ALPH_TYPE()
 {
        string ret;
-       if ( maxKey <= keyOps->maxKey )
+       if ( redFsm->maxKey <= keyOps->maxKey )
                ret = ALPH_TYPE();
        else {
-               long long maxKeyVal = maxKey.getLongLong();
+               long long maxKeyVal = redFsm->maxKey.getLongLong();
                HostType *wideType = keyOps->typeSubsumes( keyOps->isSigned, maxKeyVal );
                assert( wideType != 0 );
 
index bc16bff..42d0fd0 100644 (file)
@@ -166,22 +166,6 @@ protected:
 
        unsigned int arrayTypeSize( unsigned long maxVal );
 
-       bool anyActions();
-       bool anyToStateActions()        { return bAnyToStateActions; }
-       bool anyFromStateActions()      { return bAnyFromStateActions; }
-       bool anyRegActions()            { return bAnyRegActions; }
-       bool anyEofActions()            { return bAnyEofActions; }
-       bool anyActionGotos()           { return bAnyActionGotos; }
-       bool anyActionCalls()           { return bAnyActionCalls; }
-       bool anyActionRets()            { return bAnyActionRets; }
-       bool anyRegActionRets()         { return bAnyRegActionRets; }
-       bool anyRegActionByValControl() { return bAnyRegActionByValControl; }
-       bool anyRegNextStmt()           { return bAnyRegNextStmt; }
-       bool anyRegCurStateRef()        { return bAnyRegCurStateRef; }
-       bool anyRegBreak()              { return bAnyRegBreak; }
-       bool anyLmSwitchError()         { return bAnyLmSwitchError; }
-       bool anyConditions()            { return bAnyConditions; }
-
        /* Set up labelNeeded flag for each state. Differs for each goto style so
         * is virtual. */
        virtual void setLabelsNeeded() {}
@@ -199,40 +183,6 @@ protected:
 protected:
        ostream &out;
 
-       bool bAnyToStateActions;
-       bool bAnyFromStateActions;
-       bool bAnyRegActions;
-       bool bAnyEofActions;
-       bool bAnyActionGotos;
-       bool bAnyActionCalls;
-       bool bAnyActionRets;
-       bool bAnyRegActionRets;
-       bool bAnyRegActionByValControl;
-       bool bAnyRegNextStmt;
-       bool bAnyRegCurStateRef;
-       bool bAnyRegBreak;
-       bool bAnyLmSwitchError;
-       bool bAnyConditions;
-
-       int maxState;
-       int maxSingleLen;
-       int maxRangeLen;
-       int maxKeyOffset;
-       int maxIndexOffset;
-       int maxIndex;
-       int maxActListId;
-       int maxActionLoc;
-       int maxActArrItem;
-       unsigned long long maxSpan;
-       unsigned long long maxCondSpan;
-       int maxFlatIndexOffset;
-       Key maxKey;
-       int maxCondOffset;
-       int maxCondLen;
-       int maxCondSpaceId;
-       int maxCondIndexOffset;
-       int maxCond;
-
        bool useIndicies;
 };
 
index 94eafca..1158220 100644 (file)
@@ -35,19 +35,19 @@ void FTabCodeGen::calcIndexSize()
        for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
                int totalIndex = st->outSingle.length() + st->outRange.length() + 
                                (st->defTrans == 0 ? 0 : 1);
-               sizeWithInds += arrayTypeSize(maxIndex) * totalIndex;
+               sizeWithInds += arrayTypeSize(redFsm->maxIndex) * totalIndex;
        }
-       sizeWithInds += arrayTypeSize(maxState) * redFsm->transSet.length();
-       if ( anyActions() )
-               sizeWithInds += arrayTypeSize(maxActListId) * redFsm->transSet.length();
+       sizeWithInds += arrayTypeSize(redFsm->maxState) * redFsm->transSet.length();
+       if ( redFsm->anyActions() )
+               sizeWithInds += arrayTypeSize(redFsm->maxActListId) * redFsm->transSet.length();
 
        /* Calculate the cost of not using indicies. */
        for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
                int totalIndex = st->outSingle.length() + st->outRange.length() + 
                                (st->defTrans == 0 ? 0 : 1);
-               sizeWithoutInds += arrayTypeSize(maxState) * totalIndex;
-               if ( anyActions() )
-                       sizeWithoutInds += arrayTypeSize(maxActListId) * totalIndex;
+               sizeWithoutInds += arrayTypeSize(redFsm->maxState) * totalIndex;
+               if ( redFsm->anyActions() )
+                       sizeWithoutInds += arrayTypeSize(redFsm->maxActListId) * totalIndex;
        }
 
        /* If using indicies reduces the size, use them. */
@@ -180,13 +180,13 @@ std::ostream &FTabCodeGen::ACTION_SWITCH()
 
 void FTabCodeGen::writeOutData()
 {
-       if ( anyConditions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxCondOffset), CO() );
+       if ( redFsm->anyConditions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
                COND_OFFSETS();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCondLen), CL() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
                COND_LENS();
                CLOSE_ARRAY() <<
                "\n";
@@ -196,13 +196,13 @@ void FTabCodeGen::writeOutData()
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCondSpaceId), C() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
                COND_SPACES();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       OPEN_ARRAY( ARRAY_TYPE(maxKeyOffset), KO() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
        KEY_OFFSETS();
        CLOSE_ARRAY() <<
        "\n";
@@ -212,69 +212,69 @@ void FTabCodeGen::writeOutData()
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxSingleLen), SL() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
        SINGLE_LENS();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxRangeLen), RL() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
        RANGE_LENS();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxIndexOffset), IO() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
        INDEX_OFFSETS();
        CLOSE_ARRAY() <<
        "\n";
 
        if ( useIndicies ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxIndex), I() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
                INDICIES();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
                TRANS_TARGS_WI();
                CLOSE_ARRAY() <<
                "\n";
 
-               if ( anyActions() ) {
-                       OPEN_ARRAY( ARRAY_TYPE(maxActListId), TA() );
+               if ( redFsm->anyActions() ) {
+                       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() );
                        TRANS_ACTIONS_WI();
                        CLOSE_ARRAY() <<
                        "\n";
                }
        }
        else {
-               OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
                TRANS_TARGS();
                CLOSE_ARRAY() <<
                "\n";
 
-               if ( anyActions() ) {
-                       OPEN_ARRAY( ARRAY_TYPE(maxActListId), TA() );
+               if ( redFsm->anyActions() ) {
+                       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() );
                        TRANS_ACTIONS();
                        CLOSE_ARRAY() <<
                        "\n";
                }
        }
 
-       if ( anyToStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+       if ( redFsm->anyToStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
                TO_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyFromStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+       if ( redFsm->anyFromStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
                FROM_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyEofActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActListId), EA() );
+       if ( redFsm->anyEofActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), EA() );
                EOF_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
@@ -305,7 +305,7 @@ void FTabCodeGen::writeOutExec()
                "       {\n"
                "       int _klen";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << ", _ps";
 
        out <<
@@ -313,7 +313,7 @@ void FTabCodeGen::writeOutExec()
                "       " << PTR_CONST() << WIDE_ALPH_TYPE() << POINTER() << "_keys;\n"
                "       int _trans;\n";
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                out << "        " << WIDE_ALPH_TYPE() << " _widec;\n";
 
        out << "\n";
@@ -334,7 +334,7 @@ void FTabCodeGen::writeOutExec()
                        "               goto _out;\n";
        }
 
-       if ( anyFromStateActions() ) {
+       if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       switch ( " << FSA() << "[" << CS() << "] ) {\n";
                        FROM_STATE_ACTION_SWITCH();
@@ -343,14 +343,14 @@ void FTabCodeGen::writeOutExec()
                        "\n";
        }
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                COND_TRANSLATE();
 
        LOCATE_TRANS();
 
        out << "_match:\n";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << "        _ps = " << CS() << ";\n";
 
        if ( useIndicies )
@@ -360,7 +360,7 @@ void FTabCodeGen::writeOutExec()
                "       " << CS() << " = " << TT() << "[_trans];\n"
                "\n";
 
-       if ( anyRegActions() ) {
+       if ( redFsm->anyRegActions() ) {
                out << 
                        "       if ( " << TA() << "[_trans] == 0 )\n"
                        "               goto _again;\n"
@@ -372,10 +372,11 @@ void FTabCodeGen::writeOutExec()
                        "\n";
        }
 
-       if ( anyRegActions() || anyActionGotos() || anyActionCalls() || anyActionRets() )
+       if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
+                       redFsm->anyActionCalls() || redFsm->anyActionRets() )
                out << "_again:\n";
 
-       if ( anyToStateActions() ) {
+       if ( redFsm->anyToStateActions() ) {
                out <<
                        "       switch ( " << TSA() << "[" << CS() << "] ) {\n";
                        TO_STATE_ACTION_SWITCH();
@@ -405,7 +406,7 @@ void FTabCodeGen::writeOutExec()
 
 void FTabCodeGen::writeOutEOF()
 {
-       if ( anyEofActions() ) {
+       if ( redFsm->anyEofActions() ) {
                out <<
                        "       {\n"
                        "       switch ( " << EA() << "[" << CS() << "] ) {\n";
index 85e475a..05aae0e 100644 (file)
@@ -458,36 +458,36 @@ void CodeGenData::analyzeAction( Action *act, InlineList *inlineList )
                /* Only consider actions that are referenced. */
                if ( act->numRefs() > 0 ) {
                        if ( item->type == InlineItem::Goto || item->type == InlineItem::GotoExpr )
-                               codeGen->bAnyActionGotos = true;
+                               redFsm->bAnyActionGotos = true;
                        else if ( item->type == InlineItem::Call || item->type == InlineItem::CallExpr )
-                               codeGen->bAnyActionCalls = true;
+                               redFsm->bAnyActionCalls = true;
                        else if ( item->type == InlineItem::Ret )
-                               codeGen->bAnyActionRets = true;
+                               redFsm->bAnyActionRets = true;
                }
 
                /* Check for various things in regular actions. */
                if ( act->numTransRefs > 0 || act->numToStateRefs > 0 || act->numFromStateRefs > 0 ) {
                        /* Any returns in regular actions? */
                        if ( item->type == InlineItem::Ret )
-                               codeGen->bAnyRegActionRets = true;
+                               redFsm->bAnyRegActionRets = true;
 
                        /* Any next statements in the regular actions? */
                        if ( item->type == InlineItem::Next || item->type == InlineItem::NextExpr )
-                               codeGen->bAnyRegNextStmt = true;
+                               redFsm->bAnyRegNextStmt = true;
 
                        /* Any by value control in regular actions? */
                        if ( item->type == InlineItem::CallExpr || item->type == InlineItem::GotoExpr )
-                               codeGen->bAnyRegActionByValControl = true;
+                               redFsm->bAnyRegActionByValControl = true;
 
                        /* Any references to the current state in regular actions? */
                        if ( item->type == InlineItem::Curs )
-                               codeGen->bAnyRegCurStateRef = true;
+                               redFsm->bAnyRegCurStateRef = true;
 
                        if ( item->type == InlineItem::Break )
-                               codeGen->bAnyRegBreak = true;
+                               redFsm->bAnyRegBreak = true;
 
                        if ( item->type == InlineItem::LmSwitch && item->handlesError )
-                               codeGen->bAnyLmSwitchError = true;
+                               redFsm->bAnyLmSwitchError = true;
                }
 
                if ( item->children != 0 )
@@ -527,97 +527,97 @@ void CodeGenData::assignActionIds()
 
 void CodeGenData::setValueLimits()
 {
-       codeGen->maxSingleLen = 0;
-       codeGen->maxRangeLen = 0;
-       codeGen->maxKeyOffset = 0;
-       codeGen->maxIndexOffset = 0;
-       codeGen->maxActListId = 0;
-       codeGen->maxActionLoc = 0;
-       codeGen->maxActArrItem = 0;
-       codeGen->maxSpan = 0;
-       codeGen->maxCondSpan = 0;
-       codeGen->maxFlatIndexOffset = 0;
-       codeGen->maxCondOffset = 0;
-       codeGen->maxCondLen = 0;
-       codeGen->maxCondSpaceId = 0;
-       codeGen->maxCondIndexOffset = 0;
+       redFsm->maxSingleLen = 0;
+       redFsm->maxRangeLen = 0;
+       redFsm->maxKeyOffset = 0;
+       redFsm->maxIndexOffset = 0;
+       redFsm->maxActListId = 0;
+       redFsm->maxActionLoc = 0;
+       redFsm->maxActArrItem = 0;
+       redFsm->maxSpan = 0;
+       redFsm->maxCondSpan = 0;
+       redFsm->maxFlatIndexOffset = 0;
+       redFsm->maxCondOffset = 0;
+       redFsm->maxCondLen = 0;
+       redFsm->maxCondSpaceId = 0;
+       redFsm->maxCondIndexOffset = 0;
 
        /* In both of these cases the 0 index is reserved for no value, so the max
         * is one more than it would be if they started at 0. */
-       codeGen->maxIndex = redFsm->transSet.length();
-       codeGen->maxCond = cgd->condSpaceList.length(); 
+       redFsm->maxIndex = redFsm->transSet.length();
+       redFsm->maxCond = cgd->condSpaceList.length(); 
 
        /* The nextStateId - 1 is the last state id assigned. */
-       codeGen->maxState = redFsm->nextStateId - 1;
+       redFsm->maxState = redFsm->nextStateId - 1;
 
        for ( CondSpaceList::Iter csi = cgd->condSpaceList; csi.lte(); csi++ ) {
-               if ( csi->condSpaceId > codeGen->maxCondSpaceId )
-                       codeGen->maxCondSpaceId = csi->condSpaceId;
+               if ( csi->condSpaceId > redFsm->maxCondSpaceId )
+                       redFsm->maxCondSpaceId = csi->condSpaceId;
        }
 
        for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
                /* Maximum cond length. */
-               if ( st->stateCondList.length() > codeGen->maxCondLen )
-                       codeGen->maxCondLen = st->stateCondList.length();
+               if ( st->stateCondList.length() > redFsm->maxCondLen )
+                       redFsm->maxCondLen = st->stateCondList.length();
 
                /* Maximum single length. */
-               if ( st->outSingle.length() > codeGen->maxSingleLen )
-                       codeGen->maxSingleLen = st->outSingle.length();
+               if ( st->outSingle.length() > redFsm->maxSingleLen )
+                       redFsm->maxSingleLen = st->outSingle.length();
 
                /* Maximum range length. */
-               if ( st->outRange.length() > codeGen->maxRangeLen )
-                       codeGen->maxRangeLen = st->outRange.length();
+               if ( st->outRange.length() > redFsm->maxRangeLen )
+                       redFsm->maxRangeLen = st->outRange.length();
 
                /* The key offset index offset for the state after last is not used, skip it.. */
                if ( ! st.last() ) {
-                       codeGen->maxCondOffset += st->stateCondList.length();
-                       codeGen->maxKeyOffset += st->outSingle.length() + st->outRange.length()*2;
-                       codeGen->maxIndexOffset += st->outSingle.length() + st->outRange.length() + 1;
+                       redFsm->maxCondOffset += st->stateCondList.length();
+                       redFsm->maxKeyOffset += st->outSingle.length() + st->outRange.length()*2;
+                       redFsm->maxIndexOffset += st->outSingle.length() + st->outRange.length() + 1;
                }
 
                /* Max cond span. */
                if ( st->condList != 0 ) {
                        unsigned long long span = keyOps->span( st->condLowKey, st->condHighKey );
-                       if ( span > codeGen->maxCondSpan )
-                               codeGen->maxCondSpan = span;
+                       if ( span > redFsm->maxCondSpan )
+                               redFsm->maxCondSpan = span;
                }
 
                /* Max key span. */
                if ( st->transList != 0 ) {
                        unsigned long long span = keyOps->span( st->lowKey, st->highKey );
-                       if ( span > codeGen->maxSpan )
-                               codeGen->maxSpan = span;
+                       if ( span > redFsm->maxSpan )
+                               redFsm->maxSpan = span;
                }
 
                /* Max cond index offset. */
                if ( ! st.last() ) {
                        if ( st->condList != 0 )
-                               codeGen->maxCondIndexOffset += keyOps->span( st->condLowKey, st->condHighKey );
+                               redFsm->maxCondIndexOffset += keyOps->span( st->condLowKey, st->condHighKey );
                }
 
                /* Max flat index offset. */
                if ( ! st.last() ) {
                        if ( st->transList != 0 )
-                               codeGen->maxFlatIndexOffset += keyOps->span( st->lowKey, st->highKey );
-                       codeGen->maxFlatIndexOffset += 1;
+                               redFsm->maxFlatIndexOffset += keyOps->span( st->lowKey, st->highKey );
+                       redFsm->maxFlatIndexOffset += 1;
                }
        }
 
        for ( ActionTableMap::Iter at = redFsm->actionMap; at.lte(); at++ ) {
                /* Maximum id of action lists. */
-               if ( at->actListId+1 > codeGen->maxActListId )
-                       codeGen->maxActListId = at->actListId+1;
+               if ( at->actListId+1 > redFsm->maxActListId )
+                       redFsm->maxActListId = at->actListId+1;
 
                /* Maximum location of items in action array. */
-               if ( at->location+1 > codeGen->maxActionLoc )
-                       codeGen->maxActionLoc = at->location+1;
+               if ( at->location+1 > redFsm->maxActionLoc )
+                       redFsm->maxActionLoc = at->location+1;
 
                /* Maximum values going into the action array. */
-               if ( at->key.length() > codeGen->maxActArrItem )
-                       codeGen->maxActArrItem = at->key.length();
+               if ( at->key.length() > redFsm->maxActArrItem )
+                       redFsm->maxActArrItem = at->key.length();
                for ( ActionTable::Iter item = at->key; item.lte(); item++ ) {
-                       if ( item->value->actionId > codeGen->maxActArrItem )
-                               codeGen->maxActArrItem = item->value->actionId;
+                       if ( item->value->actionId > redFsm->maxActArrItem )
+                               redFsm->maxActArrItem = item->value->actionId;
                }
        }
 }
@@ -634,13 +634,13 @@ void CodeGenData::analyzeMachine()
        for ( ActionList::Iter act = cgd->actionList; act.lte(); act++ ) {
                /* Record the occurrence of various kinds of actions. */
                if ( act->numToStateRefs > 0 )
-                       codeGen->bAnyToStateActions = true;
+                       redFsm->bAnyToStateActions = true;
                if ( act->numFromStateRefs > 0 )
-                       codeGen->bAnyFromStateActions = true;
+                       redFsm->bAnyFromStateActions = true;
                if ( act->numEofRefs > 0 )
-                       codeGen->bAnyEofActions = true;
+                       redFsm->bAnyEofActions = true;
                if ( act->numTransRefs > 0 )
-                       codeGen->bAnyRegActions = true;
+                       redFsm->bAnyRegActions = true;
 
                /* Recurse through the action's parse tree looking for various things. */
                analyzeAction( act, act->inlineList );
@@ -673,7 +673,7 @@ void CodeGenData::analyzeMachine()
                        st->bAnyRegCurStateRef = true;
                
                if ( st->stateCondList.length() > 0 )
-                       codeGen->bAnyConditions = true;
+                       redFsm->bAnyConditions = true;
        }
 
        /* Assign ids to actions that are referenced. */
@@ -753,7 +753,7 @@ void CodeGenData::prepareMachine()
         * other things. We will use these in reporting the usage
         * of fsm directives in action code. */
        analyzeMachine();
-       codeGen->maxKey = maxKey;
+       redFsm->maxKey = maxKey;
 }
 
 void CodeGenData::generateGraphviz()
index f8cb323..1d37201 100644 (file)
@@ -619,29 +619,29 @@ void GotoCodeGen::writeOutData()
                        "\n";
        }
 
-       if ( anyActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActArrItem), A() );
+       if ( redFsm->anyActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
                ACTIONS_ARRAY();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyToStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+       if ( redFsm->anyToStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
                TO_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyFromStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+       if ( redFsm->anyFromStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
                FROM_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyEofActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), EA() );
+       if ( redFsm->anyEofActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
                EOF_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
@@ -654,16 +654,18 @@ void GotoCodeGen::writeOutExec()
 
        out << "        {\n";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << "        int _ps = 0;\n";
 
-       if ( anyToStateActions() || anyRegActions() || anyFromStateActions() ) {
+       if ( redFsm->anyToStateActions() || redFsm->anyRegActions() 
+                       || redFsm->anyFromStateActions() )
+       {
                out << 
-                       "       " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts;\n"
+                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
                        "       " << UINT() << " _nacts;\n";
        }
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                out << "        " << WIDE_ALPH_TYPE() << " _widec;\n";
 
        out << "\n";
@@ -677,7 +679,7 @@ void GotoCodeGen::writeOutExec()
 
        out << "_resume:\n";
 
-       if ( anyFromStateActions() ) {
+       if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       _acts = " << ARR_OFF( A(), FSA() + "[" + CS() + "]" ) << ";\n"
                        "       _nacts = " << CAST(UINT()) << " *_acts++;\n"
@@ -699,12 +701,12 @@ void GotoCodeGen::writeOutExec()
                TRANSITIONS() <<
                "\n";
 
-       if ( anyRegActions() )
+       if ( redFsm->anyRegActions() )
                EXEC_FUNCS() << "\n";
 
        out << "_again:\n";
 
-       if ( anyToStateActions() ) {
+       if ( redFsm->anyToStateActions() ) {
                out <<
                        "       _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
                        "       _nacts = " << CAST(UINT()) << " *_acts++;\n"
@@ -736,10 +738,10 @@ void GotoCodeGen::writeOutExec()
 
 void GotoCodeGen::writeOutEOF()
 {
-       if ( anyEofActions() ) {
+       if ( redFsm->anyEofActions() ) {
                out << 
                        "       {\n"
-                       "       " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts = " << 
+                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts = " << 
                                        ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
                        "       " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
                        "       while ( _nacts-- > 0 ) {\n"
index c632150..77020c7 100644 (file)
 #include "gendata.h"
 #include "bstmap.h"
 
+bool IpGotoCodeGen::useAgainLabel()
+{
+       return redFsm->anyRegActionRets() || 
+                       redFsm->anyRegActionByValControl() || 
+                       redFsm->anyRegNextStmt();
+}
+
 void IpGotoCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish )
 {
        ret << "{" << CTRL_FLOW() << "goto st" << gotoDest << ";}";
@@ -286,7 +293,7 @@ void IpGotoCodeGen::setLabelsNeeded()
                for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
                        st->labelNeeded = false;
 
-               if ( redFsm->errState != 0 && anyLmSwitchError() )
+               if ( redFsm->errState != 0 && redFsm->anyLmSwitchError() )
                        redFsm->errState->labelNeeded = true;
 
                /* Walk all transitions and set only those that have targs. */
@@ -350,10 +357,10 @@ void IpGotoCodeGen::writeOutExec()
 
        out << "        {\n";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << "        int _ps = 0;\n";
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                out << "        " << WIDE_ALPH_TYPE() << " _widec;\n";
 
        if ( cgd->hasEnd ) {
@@ -405,7 +412,7 @@ void IpGotoCodeGen::writeOutExec()
 
 void IpGotoCodeGen::writeOutEOF()
 {
-       if ( anyEofActions() ) {
+       if ( redFsm->anyEofActions() ) {
                out <<
                        "       {\n"
                        "       switch ( " << CS() << " ) {\n";
index 34f3db6..cdac17b 100644 (file)
@@ -59,8 +59,7 @@ public:
        virtual void writeOutExec();
 
 protected:
-       bool useAgainLabel()
-               { return anyRegActionRets() || anyRegActionByValControl() || anyRegNextStmt(); }
+       bool useAgainLabel();
 
        /* Called from GotoCodeGen::STATE_GOTOS just before writing the gotos for
         * each state. */
index f902620..bf9a4ef 100644 (file)
@@ -174,17 +174,19 @@ void JavaTabCodeGen::writeOutExec()
                "       {\n"
                "       int _klen";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << ", _ps";
 
        out << 
                ";\n"
                "       int _trans;\n";
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                out << "        int _widec;\n";
 
-       if ( anyToStateActions() || anyRegActions() || anyFromStateActions() ) {
+       if ( redFsm->anyToStateActions() || redFsm->anyRegActions() || 
+                       redFsm->anyFromStateActions() )
+       {
                out << 
                        "       int _acts;\n"
                        "       int _nacts;\n";
@@ -207,7 +209,7 @@ void JavaTabCodeGen::writeOutExec()
                        "               break _resume;\n";
        }
 
-       if ( anyFromStateActions() ) {
+       if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       _acts = " << FSA() << "[" << CS() << "]" << ";\n"
                        "       _nacts = " << CAST("int") << " " << A() << "[_acts++];\n"
@@ -220,12 +222,12 @@ void JavaTabCodeGen::writeOutExec()
                        "\n";
        }
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                COND_TRANSLATE();
 
        LOCATE_TRANS();
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << "        _ps = " << CS() << ";\n";
 
        if ( useIndicies )
@@ -235,7 +237,7 @@ void JavaTabCodeGen::writeOutExec()
                "       " << CS() << " = " << TT() << "[_trans];\n"
                "\n";
 
-       if ( anyRegActions() ) {
+       if ( redFsm->anyRegActions() ) {
                out <<
                        "       if ( " << TA() << "[_trans] == 0 )\n"
                        "               break _again;\n"
@@ -255,7 +257,7 @@ void JavaTabCodeGen::writeOutExec()
        /* Again loop, functions as again label. */
        out << "        } while (false);\n";
 
-       if ( anyToStateActions() ) {
+       if ( redFsm->anyToStateActions() ) {
                out <<
                        "       _acts = " << TSA() << "[" << CS() << "]" << ";\n"
                        "       _nacts = " << CAST("int") << " " << A() << "[_acts++];\n"
@@ -291,7 +293,7 @@ void JavaTabCodeGen::writeOutExec()
 
 void JavaTabCodeGen::writeOutEOF()
 {
-       if ( anyEofActions() ) {
+       if ( redFsm->anyEofActions() ) {
                out <<
                        "       int _acts = " << EA() << "[" << CS() << "]" << ";\n"
                        "       int _nacts = " << CAST("int") << " " << A() << "[_acts++];\n"
index ffcc207..c8495ee 100644 (file)
@@ -48,10 +48,30 @@ RedFsmAp::RedFsmAp()
        errState(0),
        errTrans(0),
        firstFinState(0),
-       numFinStates(0)
+       numFinStates(0),
+       bAnyToStateActions(false),
+       bAnyFromStateActions(false),
+       bAnyRegActions(false),
+       bAnyEofActions(false),
+       bAnyActionGotos(false),
+       bAnyActionCalls(false),
+       bAnyActionRets(false),
+       bAnyRegActionRets(false),
+       bAnyRegActionByValControl(false),
+       bAnyRegNextStmt(false),
+       bAnyRegCurStateRef(false),
+       bAnyRegBreak(false),
+       bAnyLmSwitchError(false),
+       bAnyConditions(false)
 {
 }
 
+/* Does the machine have any actions. */
+bool RedFsmAp::anyActions()
+{
+       return actionMap.length() > 0;
+}
+
 void RedFsmAp::depthFirstOrdering( RedStateAp *state )
 {
        /* Nothing to do if the state is already on the list. */
index 42df42e..7864f83 100644 (file)
@@ -411,6 +411,57 @@ struct RedFsmAp
        int numFinStates;
        int nParts;
 
+       bool bAnyToStateActions;
+       bool bAnyFromStateActions;
+       bool bAnyRegActions;
+       bool bAnyEofActions;
+       bool bAnyActionGotos;
+       bool bAnyActionCalls;
+       bool bAnyActionRets;
+       bool bAnyRegActionRets;
+       bool bAnyRegActionByValControl;
+       bool bAnyRegNextStmt;
+       bool bAnyRegCurStateRef;
+       bool bAnyRegBreak;
+       bool bAnyLmSwitchError;
+       bool bAnyConditions;
+
+       int maxState;
+       int maxSingleLen;
+       int maxRangeLen;
+       int maxKeyOffset;
+       int maxIndexOffset;
+       int maxIndex;
+       int maxActListId;
+       int maxActionLoc;
+       int maxActArrItem;
+       unsigned long long maxSpan;
+       unsigned long long maxCondSpan;
+       int maxFlatIndexOffset;
+       Key maxKey;
+       int maxCondOffset;
+       int maxCondLen;
+       int maxCondSpaceId;
+       int maxCondIndexOffset;
+       int maxCond;
+
+       bool anyActions();
+       bool anyToStateActions()        { return bAnyToStateActions; }
+       bool anyFromStateActions()      { return bAnyFromStateActions; }
+       bool anyRegActions()            { return bAnyRegActions; }
+       bool anyEofActions()            { return bAnyEofActions; }
+       bool anyActionGotos()           { return bAnyActionGotos; }
+       bool anyActionCalls()           { return bAnyActionCalls; }
+       bool anyActionRets()            { return bAnyActionRets; }
+       bool anyRegActionRets()         { return bAnyRegActionRets; }
+       bool anyRegActionByValControl() { return bAnyRegActionByValControl; }
+       bool anyRegNextStmt()           { return bAnyRegNextStmt; }
+       bool anyRegCurStateRef()        { return bAnyRegCurStateRef; }
+       bool anyRegBreak()              { return bAnyRegBreak; }
+       bool anyLmSwitchError()         { return bAnyLmSwitchError; }
+       bool anyConditions()            { return bAnyConditions; }
+
+
        /* Is is it possible to extend a range by bumping ranges that span only
         * one character to the singles array. */
        bool canExtend( const RedTransList &list, int pos );
index 289efba..c2fc5ae 100644 (file)
@@ -211,10 +211,10 @@ std::ostream &SplitCodeGen::PARTITION( int partition )
 
        out << "        " << ALPH_TYPE() << " *p = *_pp, *pe = *_ppe;\n";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << "        int _ps = 0;\n";
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                out << "        " << WIDE_ALPH_TYPE() << " _widec;\n";
 
        if ( useAgainLabel() ) {
@@ -483,7 +483,7 @@ void SplitCodeGen::setLabelsNeeded()
                for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
                        trans->labelNeeded = false;
 
-               if ( redFsm->errState != 0 && anyLmSwitchError() )
+               if ( redFsm->errState != 0 && redFsm->anyLmSwitchError() )
                        redFsm->errState->labelNeeded = true;
 
                /* Walk all transitions and set only those that have targs. */
index d74a3bd..4dc4cff 100644 (file)
@@ -35,19 +35,19 @@ void TabCodeGen::calcIndexSize()
        for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
                int totalIndex = st->outSingle.length() + st->outRange.length() + 
                                (st->defTrans == 0 ? 0 : 1);
-               sizeWithInds += arrayTypeSize(maxIndex) * totalIndex;
+               sizeWithInds += arrayTypeSize(redFsm->maxIndex) * totalIndex;
        }
-       sizeWithInds += arrayTypeSize(maxState) * redFsm->transSet.length();
-       if ( anyActions() )
-               sizeWithInds += arrayTypeSize(maxActionLoc) * redFsm->transSet.length();
+       sizeWithInds += arrayTypeSize(redFsm->maxState) * redFsm->transSet.length();
+       if ( redFsm->anyActions() )
+               sizeWithInds += arrayTypeSize(redFsm->maxActionLoc) * redFsm->transSet.length();
 
        /* Calculate the cost of not using indicies. */
        for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
                int totalIndex = st->outSingle.length() + st->outRange.length() + 
                                (st->defTrans == 0 ? 0 : 1);
-               sizeWithoutInds += arrayTypeSize(maxState) * totalIndex;
-               if ( anyActions() )
-                       sizeWithoutInds += arrayTypeSize(maxActionLoc) * totalIndex;
+               sizeWithoutInds += arrayTypeSize(redFsm->maxState) * totalIndex;
+               if ( redFsm->anyActions() )
+                       sizeWithoutInds += arrayTypeSize(redFsm->maxActionLoc) * totalIndex;
        }
 
        /* If using indicies reduces the size, use them. */
@@ -678,20 +678,20 @@ void TabCodeGen::writeOutData()
 {
        /* If there are any transtion functions then output the array. If there
         * are none, don't bother emitting an empty array that won't be used. */
-       if ( anyActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActArrItem), A() );
+       if ( redFsm->anyActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActArrItem), A() );
                ACTIONS_ARRAY();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyConditions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxCondOffset), CO() );
+       if ( redFsm->anyConditions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
                COND_OFFSETS();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCondLen), CL() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
                COND_LENS();
                CLOSE_ARRAY() <<
                "\n";
@@ -701,13 +701,13 @@ void TabCodeGen::writeOutData()
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxCondSpaceId), C() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
                COND_SPACES();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       OPEN_ARRAY( ARRAY_TYPE(maxKeyOffset), KO() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
        KEY_OFFSETS();
        CLOSE_ARRAY() <<
        "\n";
@@ -717,69 +717,69 @@ void TabCodeGen::writeOutData()
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxSingleLen), SL() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
        SINGLE_LENS();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxRangeLen), RL() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
        RANGE_LENS();
        CLOSE_ARRAY() <<
        "\n";
 
-       OPEN_ARRAY( ARRAY_TYPE(maxIndexOffset), IO() );
+       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
        INDEX_OFFSETS();
        CLOSE_ARRAY() <<
        "\n";
 
        if ( useIndicies ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxIndex), I() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
                INDICIES();
                CLOSE_ARRAY() <<
                "\n";
 
-               OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
                TRANS_TARGS_WI();
                CLOSE_ARRAY() <<
                "\n";
 
-               if ( anyActions() ) {
-                       OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TA() );
+               if ( redFsm->anyActions() ) {
+                       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
                        TRANS_ACTIONS_WI();
                        CLOSE_ARRAY() <<
                        "\n";
                }
        }
        else {
-               OPEN_ARRAY( ARRAY_TYPE(maxState), TT() );
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
                TRANS_TARGS();
                CLOSE_ARRAY() <<
                "\n";
 
-               if ( anyActions() ) {
-                       OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TA() );
+               if ( redFsm->anyActions() ) {
+                       OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
                        TRANS_ACTIONS();
                        CLOSE_ARRAY() <<
                        "\n";
                }
        }
 
-       if ( anyToStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), TSA() );
+       if ( redFsm->anyToStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
                TO_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyFromStateActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), FSA() );
+       if ( redFsm->anyFromStateActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
                FROM_STATE_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
        }
 
-       if ( anyEofActions() ) {
-               OPEN_ARRAY( ARRAY_TYPE(maxActionLoc), EA() );
+       if ( redFsm->anyEofActions() ) {
+               OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
                EOF_ACTIONS();
                CLOSE_ARRAY() <<
                "\n";
@@ -860,19 +860,21 @@ void TabCodeGen::writeOutExec()
                "       {\n"
                "       int _klen";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << ", _ps";
 
        out << 
                ";\n"
                "       " << UINT() << " _trans;\n";
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                out << "        " << WIDE_ALPH_TYPE() << " _widec;\n";
 
-       if ( anyToStateActions() || anyRegActions() || anyFromStateActions() ) {
+       if ( redFsm->anyToStateActions() || redFsm->anyRegActions() 
+                       || redFsm->anyFromStateActions() )
+       {
                out << 
-                       "       " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts;\n"
+                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts;\n"
                        "       " << UINT() << " _nacts;\n";
        }
 
@@ -896,7 +898,7 @@ void TabCodeGen::writeOutExec()
                        "               goto _out;\n";
        }
 
-       if ( anyFromStateActions() ) {
+       if ( redFsm->anyFromStateActions() ) {
                out <<
                        "       _acts = " << ARR_OFF( A(),  FSA() + "[" + CS() + "]" ) << ";\n"
                        "       _nacts = " << CAST(UINT()) << " *_acts++;\n"
@@ -909,14 +911,14 @@ void TabCodeGen::writeOutExec()
                        "\n";
        }
 
-       if ( anyConditions() )
+       if ( redFsm->anyConditions() )
                COND_TRANSLATE();
 
        LOCATE_TRANS();
 
        out << "_match:\n";
 
-       if ( anyRegCurStateRef() )
+       if ( redFsm->anyRegCurStateRef() )
                out << "        _ps = " << CS() << ";\n";
 
        if ( useIndicies )
@@ -926,7 +928,7 @@ void TabCodeGen::writeOutExec()
                "       " << CS() << " = " << TT() << "[_trans];\n"
                "\n";
 
-       if ( anyRegActions() ) {
+       if ( redFsm->anyRegActions() ) {
                out <<
                        "       if ( " << TA() << "[_trans] == 0 )\n"
                        "               goto _again;\n"
@@ -942,10 +944,11 @@ void TabCodeGen::writeOutExec()
                        "\n";
        }
 
-       if ( anyRegActions() || anyActionGotos() || anyActionCalls() || anyActionRets() )
+       if ( redFsm->anyRegActions() || redFsm->anyActionGotos() || 
+                       redFsm->anyActionCalls() || redFsm->anyActionRets() )
                out << "_again:\n";
 
-       if ( anyToStateActions() ) {
+       if ( redFsm->anyToStateActions() ) {
                out <<
                        "       _acts = " << ARR_OFF( A(), TSA() + "[" + CS() + "]" ) << ";\n"
                        "       _nacts = " << CAST(UINT()) << " *_acts++;\n"
@@ -978,10 +981,10 @@ void TabCodeGen::writeOutExec()
 
 void TabCodeGen::writeOutEOF()
 {
-       if ( anyEofActions() ) {
+       if ( redFsm->anyEofActions() ) {
                out << 
                        "       {\n"
-                       "       " << PTR_CONST() << ARRAY_TYPE(maxActArrItem) << POINTER() << "_acts = " << 
+                       "       " << PTR_CONST() << ARRAY_TYPE(redFsm->maxActArrItem) << POINTER() << "_acts = " << 
                                        ARR_OFF( A(), EA() + "[" + CS() + "]" ) << ";\n"
                        "       " << UINT() << " _nacts = " << CAST(UINT()) << " *_acts++;\n"
                        "       while ( _nacts-- > 0 ) {\n"