summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2014-11-26 13:24:29 -0500
committerAdrian Thurston <thurston@complang.org>2014-11-26 13:24:29 -0500
commit04c9eb721a62533c82c65afe481908308625bf99 (patch)
treec437020e48d121aa118e1afeaa298c25332c2947
parent480f2f1c7df01f12d959b61114a6a993149ffe75 (diff)
downloadragel-04c9eb721a62533c82c65afe481908308625bf99.tar.gz
more conversion to TableArray in C/D binary search codegen
-rw-r--r--ragel/cdcodegen.cpp4
-rw-r--r--ragel/cdcodegen.h4
-rw-r--r--ragel/cdftable.cpp31
-rw-r--r--ragel/cdtable.cpp115
4 files changed, 78 insertions, 76 deletions
diff --git a/ragel/cdcodegen.cpp b/ragel/cdcodegen.cpp
index 4e823e82..28707cff 100644
--- a/ragel/cdcodegen.cpp
+++ b/ragel/cdcodegen.cpp
@@ -114,12 +114,16 @@ FsmCodeGen::FsmCodeGen( ostream &out )
taA( "actions", *this ),
taCK( "cond_keys", *this ),
+ taCL( "cond_lengths", *this ),
taCSP( "cond_key_spans", *this ),
taC( "cond_spaces", *this ),
taCO( "cond_offsets", *this ),
taK( "trans_keys", *this ),
+ taKO( "key_offsets", *this ),
taSP( "key_spans", *this ),
taIO( "index_offsets", *this ),
+ taSL( "single_lengths", *this ),
+ taRL( "range_lengths", *this ),
taI( "indicies", *this ),
taTT( "trans_targs", *this ),
taTA( "trans_actions", *this ),
diff --git a/ragel/cdcodegen.h b/ragel/cdcodegen.h
index 79d21a16..a92952ed 100644
--- a/ragel/cdcodegen.h
+++ b/ragel/cdcodegen.h
@@ -164,12 +164,16 @@ protected:
TableArray taA;
TableArray taCK;
+ TableArray taCL;
TableArray taCSP;
TableArray taC;
TableArray taCO;
TableArray taK;
+ TableArray taKO;
TableArray taSP;
TableArray taIO;
+ TableArray taSL;
+ TableArray taRL;
TableArray taI;
TableArray taTT;
TableArray taTA;
diff --git a/ragel/cdftable.cpp b/ragel/cdftable.cpp
index c8f0faf7..4724be48 100644
--- a/ragel/cdftable.cpp
+++ b/ragel/cdftable.cpp
@@ -181,48 +181,17 @@ std::ostream &FTabCodeGen::ACTION_SWITCH()
void FTabCodeGen::writeData()
{
if ( redFsm->anyConditions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
COND_OFFSETS();
- CLOSE_ARRAY() <<
- "\n";
-
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
COND_LENS();
- CLOSE_ARRAY() <<
- "\n";
-
COND_KEYS();
-
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
COND_SPACES();
- CLOSE_ARRAY() <<
- "\n";
}
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
KEY_OFFSETS();
- CLOSE_ARRAY() <<
- "\n";
-
- OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
KEYS();
- CLOSE_ARRAY() <<
- "\n";
-
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
SINGLE_LENS();
- CLOSE_ARRAY() <<
- "\n";
-
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
RANGE_LENS();
- CLOSE_ARRAY() <<
- "\n";
-
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
INDEX_OFFSETS();
- CLOSE_ARRAY() <<
- "\n";
if ( useIndicies ) {
OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
diff --git a/ragel/cdtable.cpp b/ragel/cdtable.cpp
index d257699d..ade15522 100644
--- a/ragel/cdtable.cpp
+++ b/ragel/cdtable.cpp
@@ -163,11 +163,13 @@ std::ostream &TabCodeGen::ACTION_SWITCH()
std::ostream &TabCodeGen::COND_OFFSETS()
{
+ taCO.OPEN( ARRAY_TYPE(redFsm->maxCondOffset) );
+
out << "\t";
int totalStateNum = 0, curKeyOffset = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Write the key offset. */
- out << curKeyOffset;
+ taCO.VAL( curKeyOffset );
if ( !st.last() ) {
out << ", ";
if ( ++totalStateNum % IALL == 0 )
@@ -178,16 +180,22 @@ std::ostream &TabCodeGen::COND_OFFSETS()
curKeyOffset += st->stateCondList.length();
}
out << "\n";
+
+ taCO.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &TabCodeGen::KEY_OFFSETS()
{
+ taKO.OPEN( ARRAY_TYPE(redFsm->maxKeyOffset) );
+
out << "\t";
int totalStateNum = 0, curKeyOffset = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Write the key offset. */
- out << curKeyOffset;
+ taKO.VAL( curKeyOffset );
if ( !st.last() ) {
out << ", ";
if ( ++totalStateNum % IALL == 0 )
@@ -198,17 +206,23 @@ std::ostream &TabCodeGen::KEY_OFFSETS()
curKeyOffset += st->outSingle.length() + st->outRange.length()*2;
}
out << "\n";
+
+ taKO.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &TabCodeGen::INDEX_OFFSETS()
{
+ taIO.OPEN( ARRAY_TYPE(redFsm->maxIndexOffset) );
+
out << "\t";
int totalStateNum = 0, curIndOffset = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Write the index offset. */
- out << curIndOffset;
+ taIO.VAL( curIndOffset );
if ( !st.last() ) {
out << ", ";
if ( ++totalStateNum % IALL == 0 )
@@ -221,16 +235,22 @@ std::ostream &TabCodeGen::INDEX_OFFSETS()
curIndOffset += 1;
}
out << "\n";
+
+ taIO.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &TabCodeGen::COND_LENS()
{
+ taCL.OPEN( ARRAY_TYPE(redFsm->maxCondLen) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Write singles length. */
- out << st->stateCondList.length();
+ taCL.VAL( st->stateCondList.length() );
if ( !st.last() ) {
out << ", ";
if ( ++totalStateNum % IALL == 0 )
@@ -238,17 +258,22 @@ std::ostream &TabCodeGen::COND_LENS()
}
}
out << "\n";
+
+ taCL.CLOSE();
+ out << "\n";
return out;
}
std::ostream &TabCodeGen::SINGLE_LENS()
{
+ taSL.OPEN( ARRAY_TYPE(redFsm->maxSingleLen) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Write singles length. */
- out << st->outSingle.length();
+ taSL.VAL( st->outSingle.length() );
if ( !st.last() ) {
out << ", ";
if ( ++totalStateNum % IALL == 0 )
@@ -256,16 +281,20 @@ std::ostream &TabCodeGen::SINGLE_LENS()
}
}
out << "\n";
+ taSL.CLOSE();
+ out << "\n";
return out;
}
std::ostream &TabCodeGen::RANGE_LENS()
{
+ taRL.OPEN( ARRAY_TYPE(redFsm->maxRangeLen) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Emit length of range index. */
- out << st->outRange.length();
+ taRL.VAL( st->outRange.length() );
if ( !st.last() ) {
out << ", ";
if ( ++totalStateNum % IALL == 0 )
@@ -273,6 +302,10 @@ std::ostream &TabCodeGen::RANGE_LENS()
}
}
out << "\n";
+
+ taRL.CLOSE();
+ out << "\n";
+
return out;
}
@@ -353,7 +386,7 @@ std::ostream &TabCodeGen::EOF_TRANS()
std::ostream &TabCodeGen::COND_KEYS()
{
- OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
+ taCK.OPEN( WIDE_ALPH_TYPE() );
out << '\t';
int totalTrans = 0;
@@ -361,12 +394,14 @@ std::ostream &TabCodeGen::COND_KEYS()
/* Loop the state's transitions. */
for ( GenStateCondList::Iter sc = st->stateCondList; sc.lte(); sc++ ) {
/* Lower key. */
- out << KEY( sc->lowKey ) << ", ";
+ taCK.KEY( sc->lowKey );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
/* Upper key. */
- out << KEY( sc->highKey ) << ", ";
+ taCK.KEY( sc->highKey );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
@@ -374,23 +409,27 @@ std::ostream &TabCodeGen::COND_KEYS()
/* Output one last number so we don't have to figure out when the last
* entry is and avoid writing a comma. */
- out << 0 << "\n";
+ taCK.KEY( 0 );
+ out << "\n";
- CLOSE_ARRAY() <<
- "\n";
+ taCK.CLOSE();
+ out << "\n";
return out;
}
std::ostream &TabCodeGen::COND_SPACES()
{
+ taC.OPEN( ARRAY_TYPE(redFsm->maxCondSpaceId) );
+
out << '\t';
int totalTrans = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Loop the state's transitions. */
for ( GenStateCondList::Iter sc = st->stateCondList; sc.lte(); sc++ ) {
/* Cond Space id. */
- out << sc->condSpace->condSpaceId << ", ";
+ taC.VAL( sc->condSpace->condSpaceId );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
@@ -398,18 +437,24 @@ std::ostream &TabCodeGen::COND_SPACES()
/* Output one last number so we don't have to figure out when the last
* entry is and avoid writing a comma. */
- out << 0 << "\n";
+ taC.VAL( 0 );
+ out << "\n";
+
+ taC.CLOSE();
+ out << "\n";
return out;
}
std::ostream &TabCodeGen::KEYS()
{
+ taK.OPEN( WIDE_ALPH_TYPE() );
out << '\t';
int totalTrans = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Loop the singles. */
for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
- out << KEY( stel->lowKey ) << ", ";
+ taK.KEY( stel->lowKey );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
@@ -417,12 +462,14 @@ std::ostream &TabCodeGen::KEYS()
/* Loop the state's transitions. */
for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
/* Lower key. */
- out << KEY( rtel->lowKey ) << ", ";
+ taK.KEY( rtel->lowKey );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
/* Upper key. */
- out << KEY( rtel->highKey ) << ", ";
+ taK.KEY( rtel->highKey );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
@@ -430,7 +477,12 @@ std::ostream &TabCodeGen::KEYS()
/* Output one last number so we don't have to figure out when the last
* entry is and avoid writing a comma. */
- out << 0 << "\n";
+ taK.KEY( 0 );
+ out << "\n";
+
+ taK.CLOSE();
+ out << "\n";
+
return out;
}
@@ -762,48 +814,21 @@ void TabCodeGen::writeData()
ACTIONS_ARRAY();
if ( redFsm->anyConditions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondOffset), CO() );
COND_OFFSETS();
- CLOSE_ARRAY() <<
- "\n";
-
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondLen), CL() );
COND_LENS();
- CLOSE_ARRAY() <<
- "\n";
-
COND_KEYS();
-
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxCondSpaceId), C() );
COND_SPACES();
- CLOSE_ARRAY() <<
- "\n";
}
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxKeyOffset), KO() );
KEY_OFFSETS();
- CLOSE_ARRAY() <<
- "\n";
- OPEN_ARRAY( WIDE_ALPH_TYPE(), K() );
KEYS();
- CLOSE_ARRAY() <<
- "\n";
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxSingleLen), SL() );
SINGLE_LENS();
- CLOSE_ARRAY() <<
- "\n";
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxRangeLen), RL() );
RANGE_LENS();
- CLOSE_ARRAY() <<
- "\n";
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset), IO() );
INDEX_OFFSETS();
- CLOSE_ARRAY() <<
- "\n";
if ( useIndicies ) {
OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );