Moved rlcodegen to rlgen-cd.
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 12 Feb 2007 05:32:59 +0000 (05:32 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 12 Feb 2007 05:32:59 +0000 (05:32 +0000)
git-svn-id: http://svn.complang.org/ragel/trunk@104 052ea7fc-9027-0410-9066-f65837a77df0

26 files changed:
Makefile.in
configure
configure.in
rlgen-cd/Makefile.in [moved from rlcodegen/Makefile.in with 100% similarity]
rlgen-cd/fflatcodegen.cpp [moved from rlcodegen/fflatcodegen.cpp with 100% similarity]
rlgen-cd/fflatcodegen.h [moved from rlcodegen/fflatcodegen.h with 100% similarity]
rlgen-cd/fgotocodegen.cpp [moved from rlcodegen/fgotocodegen.cpp with 100% similarity]
rlgen-cd/fgotocodegen.h [moved from rlcodegen/fgotocodegen.h with 100% similarity]
rlgen-cd/flatcodegen.cpp [moved from rlcodegen/flatcodegen.cpp with 100% similarity]
rlgen-cd/flatcodegen.h [moved from rlcodegen/flatcodegen.h with 100% similarity]
rlgen-cd/fsmcodegen.cpp [moved from rlcodegen/fsmcodegen.cpp with 100% similarity]
rlgen-cd/fsmcodegen.h [moved from rlcodegen/fsmcodegen.h with 100% similarity]
rlgen-cd/ftabcodegen.cpp [moved from rlcodegen/ftabcodegen.cpp with 100% similarity]
rlgen-cd/ftabcodegen.h [moved from rlcodegen/ftabcodegen.h with 100% similarity]
rlgen-cd/gotocodegen.cpp [moved from rlcodegen/gotocodegen.cpp with 100% similarity]
rlgen-cd/gotocodegen.h [moved from rlcodegen/gotocodegen.h with 100% similarity]
rlgen-cd/gvdotgen.cpp [new file with mode: 0644]
rlgen-cd/gvdotgen.h [new file with mode: 0644]
rlgen-cd/ipgotocodegen.cpp [moved from rlcodegen/ipgotocodegen.cpp with 100% similarity]
rlgen-cd/ipgotocodegen.h [moved from rlcodegen/ipgotocodegen.h with 100% similarity]
rlgen-cd/main.cpp [moved from rlcodegen/main.cpp with 100% similarity]
rlgen-cd/rlcodegen.h [moved from rlcodegen/rlcodegen.h with 100% similarity]
rlgen-cd/splitcodegen.cpp [moved from rlcodegen/splitcodegen.cpp with 100% similarity]
rlgen-cd/splitcodegen.h [moved from rlcodegen/splitcodegen.h with 100% similarity]
rlgen-cd/tabcodegen.cpp [moved from rlcodegen/tabcodegen.cpp with 100% similarity]
rlgen-cd/tabcodegen.h [moved from rlcodegen/tabcodegen.h with 100% similarity]

index d2ea594..1489137 100644 (file)
@@ -19,7 +19,7 @@
 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 
 
-BUILD_SUBDIRS = common ragel redfsm rlcodegen rlgen-java rlgen-ruby
+BUILD_SUBDIRS = common ragel redfsm rlgen-cd rlgen-java rlgen-ruby rlgen-dot
 ALL_SUBDIRS = $(BUILD_SUBDIRS) test examples doc
 
 #*************************************
index fbb8641..2374770 100755 (executable)
--- a/configure
+++ b/configure
@@ -2898,7 +2898,7 @@ _ACEOF
 
 fi
 
-                                                                                                    ac_config_files="$ac_config_files Makefile common/Makefile ragel/Makefile redfsm/Makefile rlcodegen/Makefile rlgen-java/Makefile rlgen-ruby/Makefile rlgen-dot/Makefile doc/Makefile test/Makefile"
+                                                                                                    ac_config_files="$ac_config_files Makefile common/Makefile ragel/Makefile redfsm/Makefile rlgen-cd/Makefile rlgen-java/Makefile rlgen-ruby/Makefile rlgen-dot/Makefile doc/Makefile test/Makefile"
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
 # tests run on this system so they can be shared between configure
@@ -3427,7 +3427,7 @@ do
   "common/Makefile" ) CONFIG_FILES="$CONFIG_FILES common/Makefile" ;;
   "ragel/Makefile" ) CONFIG_FILES="$CONFIG_FILES ragel/Makefile" ;;
   "redfsm/Makefile" ) CONFIG_FILES="$CONFIG_FILES redfsm/Makefile" ;;
-  "rlcodegen/Makefile" ) CONFIG_FILES="$CONFIG_FILES rlcodegen/Makefile" ;;
+  "rlgen-cd/Makefile" ) CONFIG_FILES="$CONFIG_FILES rlgen-cd/Makefile" ;;
   "rlgen-java/Makefile" ) CONFIG_FILES="$CONFIG_FILES rlgen-java/Makefile" ;;
   "rlgen-ruby/Makefile" ) CONFIG_FILES="$CONFIG_FILES rlgen-ruby/Makefile" ;;
   "rlgen-dot/Makefile" ) CONFIG_FILES="$CONFIG_FILES rlgen-dot/Makefile" ;;
index a5a6177..163ace7 100644 (file)
@@ -111,6 +111,6 @@ if test -n "$RUBY"; then
 fi
 
 dnl write output files
-AC_OUTPUT(Makefile common/Makefile ragel/Makefile redfsm/Makefile rlcodegen/Makefile rlgen-java/Makefile rlgen-ruby/Makefile rlgen-dot/Makefile doc/Makefile test/Makefile)
+AC_OUTPUT(Makefile common/Makefile ragel/Makefile redfsm/Makefile rlgen-cd/Makefile rlgen-java/Makefile rlgen-ruby/Makefile rlgen-dot/Makefile doc/Makefile test/Makefile)
 
 echo "configuration of ragel complete"
similarity index 100%
rename from rlcodegen/Makefile.in
rename to rlgen-cd/Makefile.in
similarity index 100%
rename from rlcodegen/fsmcodegen.h
rename to rlgen-cd/fsmcodegen.h
diff --git a/rlgen-cd/gvdotgen.cpp b/rlgen-cd/gvdotgen.cpp
new file mode 100644 (file)
index 0000000..3be8626
--- /dev/null
@@ -0,0 +1,307 @@
+/*
+ *  Copyright 2001-2007 Adrian Thurston <thurston@cs.queensu.ca>
+ */
+
+/*  This file is part of Ragel.
+ *
+ *  Ragel is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ * 
+ *  Ragel is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ * 
+ *  You should have received a copy of the GNU General Public License
+ *  along with Ragel; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+
+
+#include "rlcodegen.h"
+#include "gvdotgen.h"
+#include "gendata.h"
+
+using namespace std;
+
+std::ostream &GraphvizDotGen::KEY( Key key )
+{
+       if ( printPrintables && key.isPrintable() ) {
+               // Output values as characters, ensuring we escape the quote (") character
+               char cVal = (char) key.getVal();
+               switch ( cVal ) {
+                       case '"': case '\\':
+                               out << "'\\" << cVal << "'";
+                               break;
+                       case '\a':
+                               out << "'\\\\a'";
+                               break;
+                       case '\b':
+                               out << "'\\\\b'";
+                               break;
+                       case '\t':
+                               out << "'\\\\t'";
+                               break;
+                       case '\n':
+                               out << "'\\\\n'";
+                               break;
+                       case '\v':
+                               out << "'\\\\v'";
+                               break;
+                       case '\f':
+                               out << "'\\\\f'";
+                               break;
+                       case '\r':
+                               out << "'\\\\r'";
+                               break;
+                       case ' ':
+                               out << "SP";
+                               break;
+                       default:        
+                               out << "'" << cVal << "'";
+                               break;
+               }
+       }
+       else {
+               if ( keyOps->isSigned )
+                       out << key.getVal();
+               else
+                       out << (unsigned long) key.getVal();
+       }
+
+       return out;
+}
+
+std::ostream &GraphvizDotGen::TRANS_ACTION( RedStateAp *fromState, RedTransAp *trans )
+{
+       int n = 0;
+       RedAction *actions[3];
+
+       if ( fromState->fromStateAction != 0 )
+               actions[n++] = fromState->fromStateAction;
+       if ( trans->action != 0 )
+               actions[n++] = trans->action;
+       if ( trans->targ != 0 && trans->targ->toStateAction != 0 )
+               actions[n++] = trans->targ->toStateAction;
+
+       if ( n > 0 )
+               out << " / ";
+       
+       /* Loop the existing actions and write out what's there. */
+       for ( int a = 0; a < n; a++ ) {
+               for ( ActionTable::Iter actIt = actions[a]->key.first(); actIt.lte(); actIt++ ) {
+                       Action *action = actIt->value;
+                       out << action->nameOrLoc();
+                       if ( a < n-1 || !actIt.last() )
+                               out << ", ";
+               }
+       }
+       return out;
+}
+
+std::ostream &GraphvizDotGen::ACTION( RedAction *action )
+{
+       /* The action. */
+       out << " / ";
+       for ( ActionTable::Iter actIt = action->key.first(); actIt.lte(); actIt++ ) {
+               Action *action = actIt->value;
+               if ( action->name != 0 )
+                       out << action->name;
+               else
+                       out << action->loc.line << ":" << action->loc.col;
+               if ( !actIt.last() )
+                       out << ", ";
+       }
+       return out;
+}
+
+std::ostream &GraphvizDotGen::ONCHAR( Key lowKey, Key highKey )
+{
+       if ( lowKey > keyOps->maxKey ) {
+               CondSpace *condSpace = findCondSpace( lowKey, highKey );
+               Key values = ( lowKey - condSpace->baseKey ) / keyOps->alphSize();
+
+               lowKey = keyOps->minKey + 
+                       (lowKey - condSpace->baseKey - keyOps->alphSize() * values.getVal());
+               highKey = keyOps->minKey + 
+                       (highKey - condSpace->baseKey - keyOps->alphSize() * values.getVal());
+               KEY( lowKey );
+               if ( lowKey != highKey ) {
+                       out << "..";
+                       KEY( highKey );
+               }
+               out << "(";
+
+               for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
+                       bool set = values & (1 << csi.pos());
+                       if ( !set )
+                               out << "!";
+                       out << (*csi)->nameOrLoc();
+                       if ( !csi.last() )
+                               out << ", ";
+               }
+               out << ")";
+       }
+       else {
+               /* Output the key. Possibly a range. */
+               KEY( lowKey );
+               if ( highKey != lowKey ) {
+                       out << "..";
+                       KEY( highKey );
+               }
+       }
+       return out;
+}
+
+void GraphvizDotGen::writeTransList( RedStateAp *state )
+{
+       /* Build the set of unique transitions out of this state. */
+       RedTransSet stTransSet;
+       for ( RedTransList::Iter tel = state->outRange; tel.lte(); tel++ ) {
+               /* If we haven't seen the transitions before, the move forward
+                * emitting all the transitions on the same character. */
+               if ( stTransSet.insert( tel->value ) ) {
+                       /* Write out the from and to states. */
+                       out << "\t" << state->id << " -> ";
+
+                       if ( tel->value->targ == 0 )
+                               out << "err_" << state->id;
+                       else
+                               out << tel->value->targ->id;
+
+                       /* Begin the label. */
+                       out << " [ label = \""; 
+                       ONCHAR( tel->lowKey, tel->highKey );
+
+                       /* Walk the transition list, finding the same. */
+                       for ( RedTransList::Iter mtel = tel.next(); mtel.lte(); mtel++ ) {
+                               if ( mtel->value == tel->value ) {
+                                       out << ", ";
+                                       ONCHAR( mtel->lowKey, mtel->highKey );
+                               }
+                       }
+
+                       /* Write the action and close the transition. */
+                       TRANS_ACTION( state, tel->value );
+                       out << "\" ];\n";
+               }
+       }
+
+       /* Write the default transition. */
+       if ( state->defTrans != 0 ) {
+               /* Write out the from and to states. */
+               out << "\t" << state->id << " -> ";
+
+               if ( state->defTrans->targ == 0 )
+                       out << "err_" << state->id;
+               else
+                       out << state->defTrans->targ->id;
+
+               /* Begin the label. */
+               out << " [ label = \"DEF"; 
+
+               /* Write the action and close the transition. */
+               TRANS_ACTION( state, state->defTrans );
+               out << "\" ];\n";
+       }
+}
+
+void GraphvizDotGen::writeDotFile( )
+{
+       out << 
+               "digraph " << fsmName << " {\n"
+               "       rankdir=LR;\n";
+       
+       /* Define the psuedo states. Transitions will be done after the states
+        * have been defined as either final or not final. */
+       out << "        node [ shape = point ];\n";
+       out << "        ENTRY;\n";
+
+       /* Psuedo states for entry points in the entry map. */
+       for ( EntryIdVect::Iter en = entryPointIds; en.lte(); en++ ) {
+               RedStateAp *state = allStates + *en;
+               out << "        en_" << state->id << ";\n";
+       }
+
+       /* Psuedo states for final states with eof actions. */
+       for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
+               if ( st->eofAction != 0 )
+                       out << "        eof_" << st->id << ";\n";
+       }
+
+       out << "        node [ shape = circle, height = 0.2 ];\n";
+
+       /* Psuedo states for states whose default actions go to error. */
+       for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
+               bool needsErr = false;
+               if ( st->defTrans != 0 && st->defTrans->targ == 0 )
+                       needsErr = true;
+               else {
+                       for ( RedTransList::Iter tel = st->outRange; tel.lte(); tel++ ) {
+                               if ( tel->value->targ == 0 ) {
+                                       needsErr = true;
+                                       break;
+                               }
+                       }
+               }
+
+               if ( needsErr )
+                       out << "        err_" << st->id << " [ label=\"\"];\n";
+       }
+
+       /* Attributes common to all nodes, plus double circle for final states. */
+       out << "        node [ fixedsize = true, height = 0.65, shape = doublecircle ];\n";
+
+       /* List Final states. */
+       for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
+               if ( st->isFinal )
+                       out << "        " << st->id << ";\n";
+       }
+
+       /* List transitions. */
+       out << "        node [ shape = circle ];\n";
+
+       /* Walk the states. */
+       for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
+               writeTransList( st );
+
+       /* Transitions into the start state. */
+       out << "        ENTRY -> " << redFsm->startState->id << " [ label = \"IN";
+       out << "\" ];\n";
+
+       /* Transitions into the entry points. */
+       for ( EntryIdVect::Iter en = entryPointIds; en.lte(); en++ ) {
+               RedStateAp *state = allStates + *en;
+               char *name = entryPointNames[en.pos()];
+               out << "        en_" << state->id << " -> " << state->id <<
+                               " [ label = \"" << name << "\" ];\n";
+       }
+
+       /* Out action transitions. */
+       for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
+               if ( st->eofAction != 0 ) {
+                       out << "        " << st->id << " -> eof_" << 
+                                       st->id << " [ label = \"EOF"; 
+                       ACTION( st->eofAction ) << "\" ];\n";
+               }
+       }
+
+       out <<
+               "}\n";
+}
+
+void GraphvizDotGen::finishRagelDef()
+{
+       assert( outputFormat == OutGraphvizDot );
+       if ( !graphvizDone ) {
+               graphvizDone = true;
+
+               /* For dot file generation we want to pick default transitions. */
+               redFsm->chooseDefaultSpan();
+
+               /* Write out with it. */
+               writeDotFile();
+       }
+}
diff --git a/rlgen-cd/gvdotgen.h b/rlgen-cd/gvdotgen.h
new file mode 100644 (file)
index 0000000..1a65293
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  Copyright 2001-2007 Adrian Thurston <thurston@cs.queensu.ca>
+ */
+
+/*  This file is part of Ragel.
+ *
+ *  Ragel is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ * 
+ *  Ragel is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ * 
+ *  You should have received a copy of the GNU General Public License
+ *  along with Ragel; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+
+#ifndef _GVDOTGEN_H
+#define _GVDOTGEN_H
+
+#include <iostream>
+#include "gendata.h"
+
+class GraphvizDotGen : public CodeGenData
+{
+public:
+       GraphvizDotGen( ostream &out ) : CodeGenData(out) { }
+
+       /* Print an fsm to out stream. */
+       void writeTransList( RedStateAp *state );
+       void writeDotFile( );
+
+       virtual void finishRagelDef();
+
+private:
+       /* Writing labels and actions. */
+       std::ostream &ONCHAR( Key lowKey, Key highKey );
+       std::ostream &TRANS_ACTION( RedStateAp *fromState, RedTransAp *trans );
+       std::ostream &ACTION( RedAction *action );
+       std::ostream &KEY( Key key );
+};
+
+
+#endif /* _GVDOTGEN_H */
similarity index 100%
rename from rlcodegen/main.cpp
rename to rlgen-cd/main.cpp
similarity index 100%
rename from rlcodegen/rlcodegen.h
rename to rlgen-cd/rlcodegen.h
similarity index 100%
rename from rlcodegen/tabcodegen.h
rename to rlgen-cd/tabcodegen.h