outputActive = false;
}
- XmlScanner xmlScanner( xmlFileName, cin );
- XmlParser xmlParser( inputFileName, xmlFileName, outputActive, wantComplete );
- xmlParser.init();
-
- xmlParser.openOutput();
-
/* Write the machines, then the surrounding code. */
- generate( xmlParser );
+ generateReduced( inputFileName, xmlFileName, outputActive, wantComplete );
/* Close the input and the intermediate file. */
delete inFile;
if ( gblErrorCount > 0 )
exit(1);
-// xml_parse( *xmlInFile, xmlFileName,
-// outputActive, wantComplete,
-// xmlScanner, xmlParser );
-
/* If writing to a file, delete the ostream, causing it to flush.
* Standard out is flushed automatically. */
if ( outputFileName != 0 ) {
sectionGraph->setStateNumbers( 0 );
}
-void ParseData::genBackend( XmlParser &xmlParser )
+void ParseData::generateReduced( XmlParser &xmlParser )
{
beginProcessing();
}
}
-void generate( XmlParser &xmlParser )
+void generateSpecificReduced( XmlParser &xmlParser )
{
- if ( machineSpec == 0 && machineName == 0 ) {
- /* No machine spec or machine name given. Generate everything. */
- for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
- ParseData *pd = parser->value->pd;
- if ( pd->instanceList.length() > 0 )
- pd->prepareMachineGen( 0 );
- }
-
- if ( gblErrorCount == 0 ) {
- for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
- ParseData *pd = parser->value->pd;
- if ( pd->instanceList.length() > 0 )
- pd->genBackend( xmlParser );
- }
- }
- }
- else if ( parserDict.length() > 0 ) {
+ if ( parserDict.length() > 0 ) {
/* There is either a machine spec or machine name given. */
ParseData *parseData = 0;
GraphDictEl *graphDictEl = 0;
/* Section/Machine to emit was found. Prepare and emit it. */
parseData->prepareMachineGen( graphDictEl );
if ( gblErrorCount == 0 )
- parseData->genBackend( xmlParser );
+ parseData->generateReduced( xmlParser );
+ }
+ }
+
+
+ for ( InputItemList::Iter ii = inputItems; ii.lte(); ii++ ) {
+ if ( ii->type == InputItem::Write ) {
+ CodeGenMapEl *mapEl = xmlParser.codeGenMap.find( (char*)ii->name.c_str() );
+ xmlParser.cgd = mapEl->value;
+ ::keyOps = &xmlParser.cgd->thisKeyOps;
+
+ xmlParser.cgd->writeStatement( ii->loc, ii->writeArgs.length()-1, ii->writeArgs.data );
}
+ else
+ xmlParser.cgd->out << ii->data.str();
}
+}
+
+void generateReduced( const char *sourceFileName, const char *xmlFileName,
+ bool outputActive, bool wantComplete )
+{
+ /* No machine spec or machine name given. Generate everything. */
+ for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
+ ParseData *pd = parser->value->pd;
+ if ( pd->instanceList.length() > 0 )
+ pd->prepareMachineGen( 0 );
+ }
+
+ XmlParser xmlParser( sourceFileName, xmlFileName, outputActive, wantComplete );
+ xmlParser.init();
+ xmlParser.openOutput();
+ if ( gblErrorCount > 0 )
+ return;
+
+ for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
+ ParseData *pd = parser->value->pd;
+ if ( pd->instanceList.length() > 0 )
+ pd->generateReduced( xmlParser );
+ }
for ( InputItemList::Iter ii = inputItems; ii.lte(); ii++ ) {
if ( ii->type == InputItem::Write ) {
void prepareMachineGen( GraphDictEl *graphDictEl );
void prepareMachineGenTBWrapped( GraphDictEl *graphDictEl );
void generateXML( ostream &out, XmlParser &xmlParser );
- void genBackend( XmlParser &xmlParser );
+ void generateReduced( XmlParser &xmlParser );
FsmAp *sectionGraph;
bool generatingSectionSubset;
void terminateAllParsers( );
void writeMachines( std::ostream &out, std::string hostData,
const char *inputFileName, XmlParser &xmlParser );
-void generate( XmlParser &xmlParser );
void xmlEscapeHost( std::ostream &out, char *data, long len );
+void generateReduced( const char *sourceFileName, const char *xmlFileName,
+ bool outputActive, bool wantComplete );
+
typedef Vector<const char *> ArgsVector;
extern ArgsVector includePaths;
xmlParser.cgd->closeMachine();
}
+void BackendGen::open_ragel_def( char *fsmName )
+{
+ CodeGenMapEl *mapEl = xmlParser.codeGenMap.find( fsmName );
+ if ( mapEl != 0 )
+ xmlParser.cgd = mapEl->value;
+ else {
+ xmlParser.cgd = makeCodeGen( xmlParser.sourceFileName, fsmName,
+ *xmlParser.outStream, xmlParser.wantComplete );
+ xmlParser.codeGenMap.insert( fsmName, xmlParser.cgd );
+ }
+}
+
+void BackendGen::close_ragel_def()
+{
+ /* Do this before distributing transitions out to singles and defaults
+ * makes life easier. */
+ xmlParser.cgd->redFsm->maxKey = xmlParser.cgd->findMaxKey();
+
+ xmlParser.cgd->redFsm->assignActionLocs();
+
+ /* Find the first final state (The final state with the lowest id). */
+ xmlParser.cgd->redFsm->findFirstFinState();
+
+ /* Call the user's callback. */
+ xmlParser.cgd->finishRagelDef();
+}
+
+
void BackendGen::makeBackend()
{
/* Open the definition. */
- xmlParser.open_ragel_def( fsmName );
+ open_ragel_def( fsmName );
/* Alphabet type. */
xmlParser.cgd->setAlphType( keyOps->alphType->internalName );
makeExports();
makeMachine();
- xmlParser.close_ragel_def();
+ close_ragel_def();
}
void makeStateConditions( StateAp *state );
void makeTransList( StateAp *state );
void makeTrans( Key lowKey, Key highKey, TransAp *trans );
+
+ void open_ragel_def( char *fsmName );
+ void close_ragel_def();
};
int token( int tokenId, int col, int line );
int token( XMLTag *tag, int col, int line );
- void open_ragel_def( char *fsmName );
- void close_ragel_def();
-
void openOutput();
/* Report an error encountered by the parser. */
bool outputActive, bool wantComplete,
XmlScanner &scanner, XmlParser &parser );
+CodeGenData *makeCodeGen( const char *sourceFileName,
+ const char *fsmName, ostream &out, bool wantComplete );
+
#endif /* _XMLPARSE_H */
}
}
-void XmlParser::open_ragel_def( char *fsmName )
-{
- CodeGenMapEl *mapEl = codeGenMap.find( fsmName );
- if ( mapEl != 0 )
- cgd = mapEl->value;
- else {
- cgd = makeCodeGen( sourceFileName, fsmName, *outStream, wantComplete );
- codeGenMap.insert( fsmName, cgd );
- }
-}
-
-void XmlParser::close_ragel_def()
-{
- /* Do this before distributing transitions out to singles and defaults
- * makes life easier. */
- cgd->redFsm->maxKey = cgd->findMaxKey();
-
- cgd->redFsm->assignActionLocs();
-
- /* Find the first final state (The final state with the lowest id). */
- cgd->redFsm->findFirstFinState();
-
- /* Call the user's callback. */
- cgd->finishRagelDef();
-}
-
%%{
parser XmlParser;