summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2013-02-10 09:25:02 -0500
committerAdrian Thurston <thurston@complang.org>2013-02-10 09:25:02 -0500
commitd0274f50a36f9e0c28bdbd6a230a775c661b2ecb (patch)
tree8b63e90c3a865b9b824327e0b5822907986d2ada
parent6e9be06ee366728bb85fe3bc2b977597b655d09c (diff)
downloadcolm-d0274f50a36f9e0c28bdbd6a230a775c661b2ecb.tar.gz
write the skip-token label only if it is used
-rw-r--r--colm/bytecode.h1
-rw-r--r--colm/fsmcodegen.cc19
-rw-r--r--colm/fsmcodegen.h2
3 files changed, 17 insertions, 5 deletions
diff --git a/colm/bytecode.h b/colm/bytecode.h
index 26482f2d..cb777481 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -495,7 +495,6 @@ void allocGlobal( struct ColmProgram *prg );
Tree **executeCode( struct ColmProgram *prg, Execution *exec, Tree **sp, Code *instr );
void rcodeDownref( struct ColmProgram *prg, Tree **sp, Code *instr );
Code *popReverseCode( RtCodeVect *allRev );
-void sendBackBuffered( FsmRun *fsmRun, StreamImpl *inputStream );
#ifdef __cplusplus
}
diff --git a/colm/fsmcodegen.cc b/colm/fsmcodegen.cc
index 2c9c3387..ce357e13 100644
--- a/colm/fsmcodegen.cc
+++ b/colm/fsmcodegen.cc
@@ -47,7 +47,8 @@ FsmCodeGen::FsmCodeGen( const char *sourceFileName, const char *fsmName, ostream
codeGenErrCount(0),
dataPrefix(true),
writeFirstFinal(true),
- writeErr(true)
+ writeErr(true),
+ skipTokenLabelNeeded(false)
{
}
@@ -194,6 +195,8 @@ void FsmCodeGen::LM_SWITCH( ostream &ret, InlineItem *item,
" }\n"
"\t"
" goto skip_toklen;\n";
+
+ skipTokenLabelNeeded = true;
}
void FsmCodeGen::LM_ON_LAST( ostream &ret, InlineItem *item )
@@ -220,6 +223,8 @@ void FsmCodeGen::LM_ON_LAG_BEHIND( ostream &ret, InlineItem *item )
ret << " " << TOKLEN() << " = " << TOKEND() << ";\n";
EMIT_TOKEN( ret, item->longestMatchPart->tdLangEl );
ret << " goto skip_toklen;\n";
+
+ skipTokenLabelNeeded = true;
}
@@ -874,9 +879,15 @@ void FsmCodeGen::writeExec()
out <<
"out:\n"
" if ( " << P() << " != 0 )\n"
- " " << TOKLEN() << " += " << P() << " - " << BLOCK_START() << ";\n"
- "skip_toklen:\n"
- " {}\n"
+ " " << TOKLEN() << " += " << P() << " - " << BLOCK_START() << ";\n";
+
+ if ( skipTokenLabelNeeded ) {
+ out <<
+ "skip_toklen:\n"
+ " {}\n";
+ }
+
+ out <<
"}\n"
"\n";
}
diff --git a/colm/fsmcodegen.h b/colm/fsmcodegen.h
index 39ae1876..29fcb98d 100644
--- a/colm/fsmcodegen.h
+++ b/colm/fsmcodegen.h
@@ -75,6 +75,7 @@ public:
RedFsm *redFsm, FsmTables *fsmTables );
protected:
+
string FSM_NAME();
string START_STATE_ID();
ostream &ACTIONS_ARRAY();
@@ -165,6 +166,7 @@ public:
bool dataPrefix;
bool writeFirstFinal;
bool writeErr;
+ bool skipTokenLabelNeeded;
std::ostream &TO_STATE_ACTION_SWITCH();
std::ostream &FROM_STATE_ACTION_SWITCH();