From d6e45efb6ddeebc4a6856827525b7a59f78717f0 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Wed, 3 Dec 2014 17:27:04 -0500 Subject: build the equiv map and emit arrays from range-based equiv data Codegen based off of range-base equiv computation is now functional. Test suite passes. Using the original makeFlat. Next step is to modify makeFlat to use reduced input chars. refs #22 --- ragel/cdcodegen.cpp | 3 +-- ragel/redfsm.cpp | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ragel/cdcodegen.cpp b/ragel/cdcodegen.cpp index 9bee6fca..0ffe5690 100644 --- a/ragel/cdcodegen.cpp +++ b/ragel/cdcodegen.cpp @@ -1026,8 +1026,7 @@ void FsmCodeGen::finishRagelDef() /* Maybe do flat expand, otherwise choose single. */ if ( codeStyle == GenFlat || codeStyle == GenFFlat ) { - redFsm->makeFlat(); - redFsm->characterClass( fsmName ); + redFsm->characterClassRange( fsmName ); } else { redFsm->chooseSingle(); diff --git a/ragel/redfsm.cpp b/ragel/redfsm.cpp index 4bb6e72d..3c234e49 100644 --- a/ragel/redfsm.cpp +++ b/ragel/redfsm.cpp @@ -490,14 +490,39 @@ void RedFsmAp::characterClassRange( const char *fsmName ) equiv.transfer( newList ); } - std::cerr << fsmName << std::endl; + /* Produce Flat indicies. */ + makeFlat(); + + /* Build the map and emit arrays from the range-based equiv classes. Will + * likely crash if there are no transitions in the FSM. */ + long long maxSpan = keyOps->span( lowKey, highKey ); + long long *dest = new long long[maxSpan]; + memset( dest, 0, sizeof(long long) * maxSpan ); + + long long *emit = new long long[maxSpan]; + memset( emit, 0, sizeof(long long) * maxSpan ); + + long long targ = 0; + long long d = 0; for ( EquivClass *c = equiv.head; c != 0; c = c->next ) { - std::cerr << " class: " << c->lowKey.getVal() << - " " << c->highKey.getVal() << std::endl; + long long span = keyOps->span( c->lowKey, c->highKey ); + + dest[d] = targ; + emit[d] = 1; + d += 1; + for ( long long s = 1; s < span; s++ ) { + dest[d] = targ; + emit[d] = 0; + d += 1; + } + targ += 1; } this->lowKey = lowKey; this->highKey = highKey; + this->classMap = dest; + this->classEmit = emit; + equiv.empty(); } -- cgit v1.2.1