From cf175365ed7debfb25f13ab57dbf12ffce10ddf5 Mon Sep 17 00:00:00 2001 From: thurston Date: Tue, 30 Jan 2007 06:05:28 +0000 Subject: [PATCH] Moved more analysis code from FsmCodeGen into CodeGenData. Eliminated the fsmName variable from FsmCodeGen. git-svn-id: http://svn.complang.org/ragel/trunk@35 052ea7fc-9027-0410-9066-f65837a77df0 --- rlcodegen/fsmcodegen.cpp | 112 +-------------------------------------------- rlcodegen/fsmcodegen.h | 4 -- rlcodegen/gendata.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++++-- rlcodegen/gendata.h | 3 ++ 4 files changed, 116 insertions(+), 118 deletions(-) diff --git a/rlcodegen/fsmcodegen.cpp b/rlcodegen/fsmcodegen.cpp index 4917c90..533ede7 100644 --- a/rlcodegen/fsmcodegen.cpp +++ b/rlcodegen/fsmcodegen.cpp @@ -52,7 +52,6 @@ bool onlyWhitespace( char *str ) /* Init code gen with in parameters. */ FsmCodeGen::FsmCodeGen( ostream &out ) : - fsmName(0), cgd(0), redFsm(0), out(out), @@ -79,115 +78,6 @@ bool FsmCodeGen::anyActions() return redFsm->actionMap.length() > 0; } -/* Assign ids to referenced actions. */ -void FsmCodeGen::assignActionIds() -{ - int nextActionId = 0; - for ( ActionList::Iter act = cgd->actionList; act.lte(); act++ ) { - /* Only ever interested in referenced actions. */ - if ( act->numRefs() > 0 ) - act->actionId = nextActionId++; - } -} - -void FsmCodeGen::setValueLimits() -{ - maxSingleLen = 0; - maxRangeLen = 0; - maxKeyOffset = 0; - maxIndexOffset = 0; - maxActListId = 0; - maxActionLoc = 0; - maxActArrItem = 0; - maxSpan = 0; - maxCondSpan = 0; - maxFlatIndexOffset = 0; - maxCondOffset = 0; - maxCondLen = 0; - maxCondSpaceId = 0; - 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. */ - maxIndex = redFsm->transSet.length(); - maxCond = cgd->condSpaceList.length(); - - /* The nextStateId - 1 is the last state id assigned. */ - maxState = redFsm->nextStateId - 1; - - for ( CondSpaceList::Iter csi = cgd->condSpaceList; csi.lte(); csi++ ) { - if ( csi->condSpaceId > maxCondSpaceId ) - maxCondSpaceId = csi->condSpaceId; - } - - for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) { - /* Maximum cond length. */ - if ( st->stateCondList.length() > maxCondLen ) - maxCondLen = st->stateCondList.length(); - - /* Maximum single length. */ - if ( st->outSingle.length() > maxSingleLen ) - maxSingleLen = st->outSingle.length(); - - /* Maximum range length. */ - if ( st->outRange.length() > maxRangeLen ) - maxRangeLen = st->outRange.length(); - - /* The key offset index offset for the state after last is not used, skip it.. */ - if ( ! st.last() ) { - maxCondOffset += st->stateCondList.length(); - maxKeyOffset += st->outSingle.length() + st->outRange.length()*2; - 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 > maxCondSpan ) - maxCondSpan = span; - } - - /* Max key span. */ - if ( st->transList != 0 ) { - unsigned long long span = keyOps->span( st->lowKey, st->highKey ); - if ( span > maxSpan ) - maxSpan = span; - } - - /* Max cond index offset. */ - if ( ! st.last() ) { - if ( st->condList != 0 ) - maxCondIndexOffset += keyOps->span( st->condLowKey, st->condHighKey ); - } - - /* Max flat index offset. */ - if ( ! st.last() ) { - if ( st->transList != 0 ) - maxFlatIndexOffset += keyOps->span( st->lowKey, st->highKey ); - maxFlatIndexOffset += 1; - } - } - - for ( ActionTableMap::Iter at = redFsm->actionMap; at.lte(); at++ ) { - /* Maximum id of action lists. */ - if ( at->actListId+1 > maxActListId ) - maxActListId = at->actListId+1; - - /* Maximum location of items in action array. */ - if ( at->location+1 > maxActionLoc ) - maxActionLoc = at->location+1; - - /* Maximum values going into the action array. */ - if ( at->key.length() > maxActArrItem ) - maxActArrItem = at->key.length(); - for ( ActionTable::Iter item = at->key; item.lte(); item++ ) { - if ( item->value->actionId > maxActArrItem ) - maxActArrItem = item->value->actionId; - } - } -} - - unsigned int FsmCodeGen::arrayTypeSize( unsigned long maxVal ) { long long maxValLL = (long long) maxVal; @@ -214,7 +104,7 @@ string FsmCodeGen::ARRAY_TYPE( unsigned long maxVal ) /* Write out the fsm name. */ string FsmCodeGen::FSM_NAME() { - return fsmName; + return cgd->fsmName; } /* Emit the offset of the start state as a decimal integer. */ diff --git a/rlcodegen/fsmcodegen.h b/rlcodegen/fsmcodegen.h index 1d15a88..2d0a07b 100644 --- a/rlcodegen/fsmcodegen.h +++ b/rlcodegen/fsmcodegen.h @@ -189,11 +189,7 @@ protected: /* Determine if we should use indicies. */ virtual void calcIndexSize() {} - void assignActionIds(); - void setValueLimits(); - /* Are there any regular transition functions, any out transition functions. */ - char *fsmName; CodeGenData *cgd; RedFsmAp *redFsm; diff --git a/rlcodegen/gendata.cpp b/rlcodegen/gendata.cpp index ee14c43..85e475a 100644 --- a/rlcodegen/gendata.cpp +++ b/rlcodegen/gendata.cpp @@ -359,7 +359,6 @@ void CodeGenData::makeCodeGen() break; } - codeGen->fsmName = fsmName; codeGen->cgd = this; } @@ -515,6 +514,116 @@ void CodeGenData::analyzeActionList( RedAction *redAct, InlineList *inlineList ) } } +/* Assign ids to referenced actions. */ +void CodeGenData::assignActionIds() +{ + int nextActionId = 0; + for ( ActionList::Iter act = cgd->actionList; act.lte(); act++ ) { + /* Only ever interested in referenced actions. */ + if ( act->numRefs() > 0 ) + act->actionId = nextActionId++; + } +} + +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; + + /* 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(); + + /* The nextStateId - 1 is the last state id assigned. */ + codeGen->maxState = redFsm->nextStateId - 1; + + for ( CondSpaceList::Iter csi = cgd->condSpaceList; csi.lte(); csi++ ) { + if ( csi->condSpaceId > codeGen->maxCondSpaceId ) + codeGen->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(); + + /* Maximum single length. */ + if ( st->outSingle.length() > codeGen->maxSingleLen ) + codeGen->maxSingleLen = st->outSingle.length(); + + /* Maximum range length. */ + if ( st->outRange.length() > codeGen->maxRangeLen ) + codeGen->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; + } + + /* Max cond span. */ + if ( st->condList != 0 ) { + unsigned long long span = keyOps->span( st->condLowKey, st->condHighKey ); + if ( span > codeGen->maxCondSpan ) + codeGen->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; + } + + /* Max cond index offset. */ + if ( ! st.last() ) { + if ( st->condList != 0 ) + codeGen->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; + } + } + + 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; + + /* Maximum location of items in action array. */ + if ( at->location+1 > codeGen->maxActionLoc ) + codeGen->maxActionLoc = at->location+1; + + /* Maximum values going into the action array. */ + if ( at->key.length() > codeGen->maxActArrItem ) + codeGen->maxActArrItem = at->key.length(); + for ( ActionTable::Iter item = at->key; item.lte(); item++ ) { + if ( item->value->actionId > codeGen->maxActArrItem ) + codeGen->maxActArrItem = item->value->actionId; + } + } +} + + + /* Gather various info on the machine. */ void CodeGenData::analyzeMachine() { @@ -568,10 +677,10 @@ void CodeGenData::analyzeMachine() } /* Assign ids to actions that are referenced. */ - codeGen->assignActionIds(); + assignActionIds(); /* Set the maximums of various values used for deciding types. */ - codeGen->setValueLimits(); + setValueLimits(); /* Determine if we should use indicies. */ codeGen->calcIndexSize(); diff --git a/rlcodegen/gendata.h b/rlcodegen/gendata.h index 4485e2d..fd0f7af 100644 --- a/rlcodegen/gendata.h +++ b/rlcodegen/gendata.h @@ -155,6 +155,9 @@ struct CodeGenData void analyzeAction( Action *act, InlineList *inlineList ); void findFinalActionRefs(); void analyzeMachine(); + + void setValueLimits(); + void assignActionIds(); void prepareMachine(); bool hasBeenPrepared; }; -- 2.7.4