From ab4c3a0c5ee5b18a41bdc2ba39ca9d057398b5b2 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 20 Mar 2016 10:53:42 -0500 Subject: [PATCH] Lemon update 2016-02-17 01:46:19 on branch parser-performance - Further improvements to the Lemon-generated code for yy_reduce(). (user: drh) --- tools/lemon/lemon.c | 18 +++++++++++++----- tools/lemon/lempar.c | 2 -- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/lemon/lemon.c b/tools/lemon/lemon.c index 7eb72b6524..b32c032b6b 100644 --- a/tools/lemon/lemon.c +++ b/tools/lemon/lemon.c @@ -3404,10 +3404,14 @@ PRIVATE char *append_str(const char *zText, int n, int p1, int p2, int bNoSubst) ** zCode is a string that is the action associated with a rule. Expand ** the symbols in this string so that the refer to elements of the parser ** stack. +** +** Return 1 if the expanded code requires that "yylhsminor" local variable +** to be defined. */ -PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ +PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){ char *cp, *xp; int i; + int rc = 0; /* True if yylhsminor is used */ char lhsused = 0; /* True if the LHS element has been used */ char lhsdirect; /* True if LHS writes directly into stack */ char used[MAXRHS]; /* True for each RHS element which is used */ @@ -3457,9 +3461,7 @@ PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ if( lhsdirect ){ sprintf(zLhs, "yymsp[%d].minor.yy%d",1-rp->nrhs,rp->lhs->dtnum); }else{ - append_str(0,0,0,0,0); - append_str(" YYMINORTYPE yylhsminor;\n", 0, 0, 0, 0); - rp->codePrefix = Strsafe(append_str(0,0,0,0,0)); + rc = 1; sprintf(zLhs, "yylhsminor.yy%d",rp->lhs->dtnum); } @@ -3564,6 +3566,8 @@ PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){ /* Suffix code generation complete */ cp = append_str(0,0,0,0,0); if( cp ) rp->codeSuffix = Strsafe(cp); + + return rc; } /* @@ -4232,9 +4236,13 @@ void ReportTable( tplt_xfer(lemp->name,in,out,&lineno); /* Generate code which executes during each REDUCE action */ + i = 0; for(rp=lemp->rule; rp; rp=rp->next){ - translate_code(lemp, rp); + i += translate_code(lemp, rp); } + if( i ){ + fprintf(out," YYMINORTYPE yylhsminor;\n"); lineno++; + } /* First output rules other than the default: rule */ for(rp=lemp->rule; rp; rp=rp->next){ struct rule *rp2; /* Other rules with the same action */ diff --git a/tools/lemon/lempar.c b/tools/lemon/lempar.c index b3ab0da067..25ac970367 100644 --- a/tools/lemon/lempar.c +++ b/tools/lemon/lempar.c @@ -636,8 +636,6 @@ static void yy_reduce( } #endif /* NDEBUG */ - /* yygotominor = yyzerominor; */ - /* Check that the stack is large enough to grow by a single entry ** if the RHS of the rule is empty. This ensures that there is room ** enough on the stack to push the LHS value */