Lemon update 2016-02-17 01:46:19 on branch parser-performance

- Further improvements to the Lemon-generated code for yy_reduce(). (user: drh)
This commit is contained in:
Randy Heit 2016-03-20 10:53:42 -05:00
parent 8a18e5c7eb
commit ab4c3a0c5e
2 changed files with 13 additions and 7 deletions

View file

@ -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 */

View file

@ -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 */