summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-05-09 17:42:07 -0400
committerAdrian Thurston <thurston@colm.net>2018-05-09 17:42:07 -0400
commit6a7b7c076145e8762531888c77a858ec03922be6 (patch)
treee62dc7207cbf283194cc1dc82fe4bd9f152a3d89
parent478391cbc2146b9e9f6a4b32c29181a00f2b2c40 (diff)
downloadcolm-6a7b7c076145e8762531888c77a858ec03922be6.tar.gz
moved all the parse finish codegen to one function
-rw-r--r--src/parsetree.h6
-rw-r--r--src/synthesis.cc104
2 files changed, 45 insertions, 65 deletions
diff --git a/src/parsetree.h b/src/parsetree.h
index e18b9d43..437b94c9 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -2866,6 +2866,7 @@ struct LangVarRef
void popRefQuals( Compiler *pd, CodeVect &code,
VarRefLookup &lookup, CallArgVect *args, bool temps ) const;
+ bool isFinishCall( VarRefLookup &lookup ) const;
InputLoc loc;
Namespace *nspace;
@@ -3130,7 +3131,10 @@ struct LangTerm
void evaluateCapture( Compiler *pd, CodeVect &code, bool isTree ) const;
UniqueType *evaluateNew( Compiler *pd, CodeVect &code ) const;
UniqueType *evaluateConstruct( Compiler *pd, CodeVect &code ) const;
- void parseFrag( Compiler *pd, CodeVect &code, int stopId ) const;
+
+ static void parseFrag( Compiler *pd, CodeVect &code, int stopId );
+ static void parseFinish( Compiler *pd, CodeVect &code, int stopId, bool revert );
+
UniqueType *evaluateParse( Compiler *pd, CodeVect &code, bool tree, bool stop ) const;
UniqueType *evaluateReadReduce( Compiler *pd, CodeVect &code ) const;
void evaluateSendStream( Compiler *pd, CodeVect &code ) const;
diff --git a/src/synthesis.cc b/src/synthesis.cc
index a7eab5c8..2c80110d 100644
--- a/src/synthesis.cc
+++ b/src/synthesis.cc
@@ -1023,6 +1023,16 @@ void LangVarRef::resetActiveRefs( Compiler *pd, VarRefLookup &lookup,
}
}
+bool LangVarRef::isFinishCall( VarRefLookup &lookup ) const
+{
+ if ( lookup.objMethod->opcodeWV == IN_PARSE_FINISH_WV ||
+ lookup.objMethod->opcodeWC == IN_PARSE_FINISH_WC )
+ {
+ return true;
+ }
+ return false;
+}
+
void LangVarRef::callOperation( Compiler *pd, CodeVect &code, VarRefLookup &lookup ) const
{
/* This is for writing if it is a non-const builtin. */
@@ -1039,21 +1049,16 @@ void LangVarRef::callOperation( Compiler *pd, CodeVect &code, VarRefLookup &look
bool revert = lookup.lastPtrInQual >= 0 || !isLocalRef() || isInbuiltObject();
bool unwind = false;
- /* The call instruction. */
- if ( pd->revertOn && revert ) {
- if ( lookup.objMethod->opcodeWV == IN_PARSE_FINISH_WV ) {
- code.append( IN_GET_PARSER_STREAM );
+ if ( isFinishCall( lookup ) ) {
+ code.append( IN_GET_PARSER_STREAM );
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FINISH_WV );
- code.appendHalf( 0 );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FINISH_EXIT_WV );
+ LangTerm::parseFinish( pd, code, 0, revert );
- code.append( IN_GET_STREAM_MEM_R );
- code.appendHalf( 0 );
- }
- else {
+ code.append( IN_GET_STREAM_MEM_R );
+ code.appendHalf( 0 );
+ }
+ else {
+ if ( pd->revertOn && revert ) {
if ( lookup.objMethod->opcodeWV == IN_CALL_WV ||
lookup.objMethod->opcodeWC == IN_EXIT )
unwind = true;
@@ -1062,20 +1067,6 @@ void LangVarRef::callOperation( Compiler *pd, CodeVect &code, VarRefLookup &look
code.append( IN_FN );
code.append( lookup.objMethod->opcodeWV );
}
- }
- else {
- if ( lookup.objMethod->opcodeWC == IN_PARSE_FINISH_WC ) {
- code.append( IN_GET_PARSER_STREAM );
-
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FINISH_WC );
- code.appendHalf( 0 );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FINISH_EXIT_WC );
-
- code.append( IN_GET_STREAM_MEM_R );
- code.appendHalf( 0 );
- }
else {
if ( lookup.objMethod->opcodeWC == IN_CALL_WC ||
lookup.objMethod->opcodeWC == IN_EXIT )
@@ -1431,7 +1422,7 @@ UniqueType *LangTerm::evaluateConstruct( Compiler *pd, CodeVect &code ) const
}
-void LangTerm::parseFrag( Compiler *pd, CodeVect &code, int stopId ) const
+void LangTerm::parseFrag( Compiler *pd, CodeVect &code, int stopId )
{
/* Parse instruction, dependent on whether or not we are producing
* revert or commit code. */
@@ -1451,6 +1442,24 @@ void LangTerm::parseFrag( Compiler *pd, CodeVect &code, int stopId ) const
}
}
+void LangTerm::parseFinish( Compiler *pd, CodeVect &code, int stopId, bool revert )
+{
+ if ( pd->revertOn && revert ) {
+ code.append( IN_PARSE_LOAD );
+ code.append( IN_PARSE_FINISH_WV );
+ code.appendHalf( stopId );
+ code.append( IN_PCR_CALL );
+ code.append( IN_PARSE_FINISH_EXIT_WV );
+ }
+ else {
+ code.append( IN_PARSE_LOAD );
+ code.append( IN_PARSE_FINISH_WC );
+ code.appendHalf( stopId );
+ code.append( IN_PCR_CALL );
+ code.append( IN_PARSE_FINISH_EXIT_WC );
+ }
+}
+
UniqueType *LangTerm::evaluateReadReduce( Compiler *pd, CodeVect &code ) const
{
UniqueType *parserUT = typeRef->uniqueType;
@@ -1620,26 +1629,7 @@ UniqueType *LangTerm::evaluateParse( Compiler *pd, CodeVect &code,
* Finish operation
*/
- /* Parse instruction, dependent on whether or not we are producing revert
- * or commit code. */
- if ( pd->revertOn ) {
- /* Finish immediately. */
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FINISH_WV );
- code.appendHalf( stopId );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FINISH_EXIT_WV );
- }
- else {
- /* Finish immediately. */
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FINISH_WC );
- code.appendHalf( stopId );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FINISH_EXIT_WC );
- }
-
- /* Parser is on the top of the stack. */
+ parseFinish( pd, code, stopId, true );
/* Pull out the error and save it off. */
code.append( IN_DUP_VAL );
@@ -1734,22 +1724,8 @@ void LangTerm::evaluateSendParser( Compiler *pd, CodeVect &code, bool strings )
parseFrag( pd, code, 0 );
}
- if ( eof ) {
- if ( pd->revertOn ) {
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FINISH_WV );
- code.appendHalf( 0 );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FINISH_EXIT_WV );
- }
- else {
- code.append( IN_PARSE_LOAD );
- code.append( IN_PARSE_FINISH_WC );
- code.appendHalf( 0 );
- code.append( IN_PCR_CALL );
- code.append( IN_PARSE_FINISH_EXIT_WC );
- }
- }
+ if ( eof )
+ parseFinish( pd, code, 0, true );
}
UniqueType *LangTerm::evaluateSend( Compiler *pd, CodeVect &code ) const