From 255ce65fec92c9734af5a3920f2d3775a712a56e Mon Sep 17 00:00:00 2001 From: thurston Date: Wed, 8 Oct 2008 17:47:19 +0000 Subject: [PATCH] More work on the direct access to the backend. The xml code gen should be preserved, not converted. Going to have to bring back some changed code. git-svn-id: http://svn.complang.org/ragel/trunk@487 052ea7fc-9027-0410-9066-f65837a77df0 --- common/common.cpp | 6 +- common/common.h | 6 +- ragel/xmlcodegen.cpp | 263 ++++++++++++++++++++++++++++++++++++++++++++++++++- ragel/xmlcodegen.h | 19 ++++ redfsm/gendata.cpp | 2 +- redfsm/gendata.h | 2 +- redfsm/xmlparse.kl | 2 - 7 files changed, 288 insertions(+), 12 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 7030b44..d5e945d 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -110,7 +110,7 @@ HostLang hostLangCSharp = { HostLang::CSharp, hostTypesCSharp, 9, hostTypesCShar HostLang *hostLang = &hostLangC; -HostType *findAlphType( char *s1 ) +HostType *findAlphType( const char *s1 ) { for ( int i = 0; i < hostLang->numHostTypes; i++ ) { if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && @@ -123,7 +123,7 @@ HostType *findAlphType( char *s1 ) return 0; } -HostType *findAlphType( char *s1, char *s2 ) +HostType *findAlphType( const char *s1, const char *s2 ) { for ( int i = 0; i < hostLang->numHostTypes; i++ ) { if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && @@ -137,7 +137,7 @@ HostType *findAlphType( char *s1, char *s2 ) return 0; } -HostType *findAlphTypeInternal( char *s1 ) +HostType *findAlphTypeInternal( const char *s1 ) { for ( int i = 0; i < hostLang->numHostTypes; i++ ) { if ( strcmp( s1, hostLang->hostTypes[i].internalName ) == 0 ) diff --git a/common/common.h b/common/common.h index 5370d02..4185a82 100644 --- a/common/common.h +++ b/common/common.h @@ -133,9 +133,9 @@ extern HostLang hostLangJava; extern HostLang hostLangRuby; extern HostLang hostLangCSharp; -HostType *findAlphType( char *s1 ); -HostType *findAlphType( char *s1, char *s2 ); -HostType *findAlphTypeInternal( char *s1 ); +HostType *findAlphType( const char *s1 ); +HostType *findAlphType( const char *s1, const char *s2 ); +HostType *findAlphTypeInternal( const char *s1 ); /* An abstraction of the key operators that manages key operations such as * comparison and increment according the signedness of the key. */ diff --git a/ragel/xmlcodegen.cpp b/ragel/xmlcodegen.cpp index 1f6a3d0..e197e07 100644 --- a/ragel/xmlcodegen.cpp +++ b/ragel/xmlcodegen.cpp @@ -25,6 +25,7 @@ #include "xmlparse.h" #include "parsedata.h" #include "fsmgraph.h" +#include "gendata.h" #include using namespace std; @@ -441,6 +442,156 @@ void XMLCodeGen::writeInlineList( InlineList *inlineList ) } } +void XMLCodeGen::makeKey( GenInlineList *outList, Key key ) +{ +} + +void XMLCodeGen::makeText( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeGoto( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeGotoExpr( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeCall( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeCallExpr( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeNext( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeNextExpr( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeEntry( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeLmSetActId( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeLmOnLast( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeLmOnNext( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeLmOnLagBehind( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeActionExec( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeLmSwitch( GenInlineList *outList, InlineItem *item ) +{ +} + +void XMLCodeGen::makeGenInlineList( GenInlineList *outList, InlineList *inList ) +{ + for ( InlineList::Iter item = *inList; item.lte(); item++ ) { + switch ( item->type ) { + case InlineItem::Text: + makeText( outList, item ); + break; + case InlineItem::Goto: + makeGoto( outList, item ); + break; + case InlineItem::GotoExpr: + makeGotoExpr( outList, item ); + break; + case InlineItem::Call: + makeCall( outList, item ); + break; + case InlineItem::CallExpr: + makeCallExpr( outList, item ); + break; + case InlineItem::Next: + makeNext( outList, item ); + break; + case InlineItem::NextExpr: + makeNextExpr( outList, item ); + break; + case InlineItem::Break: + out << ""; + break; + case InlineItem::Ret: + out << ""; + break; + case InlineItem::PChar: + out << ""; + break; + case InlineItem::Char: + out << ""; + break; + case InlineItem::Curs: + out << ""; + break; + case InlineItem::Targs: + out << ""; + break; + case InlineItem::Entry: + makeEntry( outList, item ); + break; + + case InlineItem::Hold: + out << ""; + break; + case InlineItem::Exec: + makeActionExec( outList, item ); + break; + + case InlineItem::LmSetActId: + out << "" << + item->longestMatchPart->longestMatchId << + ""; + break; + case InlineItem::LmSetTokEnd: + out << "1"; + break; + + case InlineItem::LmOnLast: + makeLmOnLast( outList, item ); + break; + case InlineItem::LmOnNext: + makeLmOnNext( outList, item ); + break; + case InlineItem::LmOnLagBehind: + makeLmOnLagBehind( outList, item ); + break; + case InlineItem::LmSwitch: + makeLmSwitch( outList, item ); + break; + + case InlineItem::LmInitAct: + out << ""; + break; + case InlineItem::LmInitTokStart: + out << ""; + break; + case InlineItem::LmSetTokStart: + out << ""; + break; + } + } +} + + void XMLCodeGen::writeAction( Action *action ) { out << " actionId << "\""; @@ -644,10 +795,9 @@ void XMLCodeGen::writeXML() { /* Open the definition. */ xmlParser.open_ragel_def( fsmName ); - out << "\n"; /* Alphabet type. */ - out << " " << keyOps->alphType->internalName << "\n"; + xmlParser.cgd->setAlphType( keyOps->alphType->internalName ); /* Getkey expression. */ if ( pd->getKeyExpr != 0 ) { @@ -749,3 +899,112 @@ void XMLCodeGen::writeXML() "\n"; } +void XMLCodeGen::makeBackend() +{ + /* Open the definition. */ + xmlParser.open_ragel_def( fsmName ); + + /* Alphabet type. */ + xmlParser.cgd->setAlphType( keyOps->alphType->internalName ); + + /* Getkey expression. */ + if ( pd->getKeyExpr != 0 ) { + out << " "; + writeInlineList( pd->getKeyExpr ); + out << "\n"; + } + + /* Access expression. */ + if ( pd->accessExpr != 0 ) { + out << " "; + writeInlineList( pd->accessExpr ); + out << "\n"; + } + + /* PrePush expression. */ + if ( pd->prePushExpr != 0 ) { + out << " "; + writeInlineList( pd->prePushExpr ); + out << "\n"; + } + + /* PostPop expression. */ + if ( pd->postPopExpr != 0 ) { + out << " "; + writeInlineList( pd->postPopExpr ); + out << "\n"; + } + + /* + * Variable expressions. + */ + + if ( pd->pExpr != 0 ) { + out << " "; + writeInlineList( pd->pExpr ); + out << "\n"; + } + + if ( pd->peExpr != 0 ) { + out << " "; + writeInlineList( pd->peExpr ); + out << "\n"; + } + + if ( pd->eofExpr != 0 ) { + out << " "; + writeInlineList( pd->eofExpr ); + out << "\n"; + } + + if ( pd->csExpr != 0 ) { + out << " "; + writeInlineList( pd->csExpr ); + out << "\n"; + } + + if ( pd->topExpr != 0 ) { + out << " "; + writeInlineList( pd->topExpr ); + out << "\n"; + } + + if ( pd->stackExpr != 0 ) { + out << " "; + writeInlineList( pd->stackExpr ); + out << "\n"; + } + + if ( pd->actExpr != 0 ) { + out << " "; + writeInlineList( pd->actExpr ); + out << "\n"; + } + + if ( pd->tokstartExpr != 0 ) { + out << " "; + writeInlineList( pd->tokstartExpr ); + out << "\n"; + } + + if ( pd->tokendExpr != 0 ) { + out << " "; + writeInlineList( pd->tokendExpr ); + out << "\n"; + } + + if ( pd->dataExpr != 0 ) { + out << " "; + writeInlineList( pd->dataExpr ); + out << "\n"; + } + + writeExports(); + + writeMachine(); + + out << + "\n"; +} + + diff --git a/ragel/xmlcodegen.h b/ragel/xmlcodegen.h index 0809e80..74a2bbd 100644 --- a/ragel/xmlcodegen.h +++ b/ragel/xmlcodegen.h @@ -31,6 +31,7 @@ struct TransAp; struct FsmAp; struct ParseData; +struct GenInlineList; struct RedActionTable : @@ -82,6 +83,7 @@ public: XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm, std::ostream &out, XmlParser &xmlParser ); void writeXML( ); + void makeBackend( ); private: void appendTrans( TransListVect &outList, Key lowKey, Key highKey, TransAp *trans ); @@ -120,6 +122,23 @@ private: void writeMachine(); void writeActionExec( InlineItem *item ); + void makeGenInlineList( GenInlineList *outList, InlineList *inList ); + void makeKey( GenInlineList *outList, Key key ); + void makeText( GenInlineList *outList, InlineItem *item ); + void makeGoto( GenInlineList *outList, InlineItem *item ); + void makeGotoExpr( GenInlineList *outList, InlineItem *item ); + void makeCall( GenInlineList *outList, InlineItem *item ); + void makeCallExpr( GenInlineList *outList, InlineItem *item ); + void makeNext( GenInlineList *outList, InlineItem *item ); + void makeNextExpr( GenInlineList *outList, InlineItem *item ); + void makeEntry( GenInlineList *outList, InlineItem *item ); + void makeLmSetActId( GenInlineList *outList, InlineItem *item ); + void makeLmOnLast( GenInlineList *outList, InlineItem *item ); + void makeLmOnNext( GenInlineList *outList, InlineItem *item ); + void makeLmOnLagBehind( GenInlineList *outList, InlineItem *item ); + void makeActionExec( GenInlineList *outList, InlineItem *item ); + void makeLmSwitch( GenInlineList *outList, InlineItem *item ); + char *fsmName; ParseData *pd; FsmAp *fsm; diff --git a/redfsm/gendata.cpp b/redfsm/gendata.cpp index bff07a3..f1f8bec 100644 --- a/redfsm/gendata.cpp +++ b/redfsm/gendata.cpp @@ -288,7 +288,7 @@ void CodeGenData::closeMachine() } -bool CodeGenData::setAlphType( char *data ) +bool CodeGenData::setAlphType( const char *data ) { HostType *alphType = findAlphTypeInternal( data ); if ( alphType == 0 ) diff --git a/redfsm/gendata.h b/redfsm/gendata.h index 13a12ac..81dde1c 100644 --- a/redfsm/gendata.h +++ b/redfsm/gendata.h @@ -178,7 +178,7 @@ struct CodeGenData GenCondSpace *findCondSpace( Key lowKey, Key highKey ); Condition *findCondition( Key key ); - bool setAlphType( char *data ); + bool setAlphType( const char *data ); void resolveTargetStates( GenInlineList *inlineList ); Key findMaxKey(); diff --git a/redfsm/xmlparse.kl b/redfsm/xmlparse.kl index 8f0b7af..bf81fc0 100644 --- a/redfsm/xmlparse.kl +++ b/redfsm/xmlparse.kl @@ -216,8 +216,6 @@ tag_export: TAG_ex '/' TAG_ex tag_alph_type: TAG_alphtype '/' TAG_alphtype final { - if ( ! cgd->setAlphType( $3->tag->content ) ) - error($1->loc) << "tag specifies unknown alphabet type" << endp; }; tag_getkey_expr: TAG_getkey inline_list '/' TAG_getkey -- 2.7.4