]> granicus.if.org Git - re2c/commitdiff
- Make -gf use jump table
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 6 May 2007 20:57:10 +0000 (20:57 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 6 May 2007 20:57:10 +0000 (20:57 +0000)
- Fix condition_09.cgif

re2c/code.cc
re2c/test/condition_09.cgif.c
re2c/test/condition_09.cgif.re
re2c/test/push.fg.c

index 46f6ca3a5537763246faa5342d3d4b6fbc34221e..ea147f7774081c0e9164ed9383705aec7fcfbf61 100644 (file)
@@ -1737,28 +1737,77 @@ void genGetState(std::ostream &o, uint& ind, uint start_label)
        if (fFlag && !bWroteGetState)
        {
                vUsedLabels.insert(start_label);
-               o << indent(ind) << "switch(" << mapCodeName["YYGETSTATE"];
-               if (!bUseYYGetStateNaked)
-               {
-                       o << "()";
-               }
-               o << ") {\n";
-               if (bUseStateAbort)
+               if (gFlag)
                {
-                       o << indent(ind) << "default: abort();\n";
-                       o << indent(ind) << "case -1: goto " << labelPrefix << start_label << ";\n";
+                       o << indent(ind++) << "static void *" << mapCodeName["yystable"] << "[" << "] = {\n";
+
+                       for (size_t i=0; i<last_fill_index; ++i)
+                       {
+                               o << indent(ind) << "&&" << mapCodeName["yyFillLabel"] << i << ",\n";
+                       }
+
+                       o << indent(--ind) << "};\n";
+                       o << "\n";
+
+                       o << indent(ind) << "if(" << mapCodeName["YYGETSTATE"];
+                       if (!bUseYYGetStateNaked)
+                       {
+                               o << "()";
+                       }
+                       if (bUseStateAbort)
+                       {
+                               o << " == -1) {";
+                               ++ind;
+                       }
+                       else
+                       {
+                               o << " < 0)";
+                       }
+                       o << " goto " << labelPrefix << start_label << ";\n";
+                       if (bUseStateAbort)
+                       {
+                               o << indent(--ind) << "} else if (" << mapCodeName["YYGETSTATE"];
+                               if (!bUseYYGetStateNaked)
+                               {
+                                       o << "()";
+                               }
+                               o << " < -1) {\n";
+                               o << indent(++ind) << "abort();\n";
+                               o << indent(--ind) << "}\n";
+                       }
+
+                       o << indent(ind) << "goto *" << mapCodeName["yystable"] << "[" << mapCodeName["YYGETSTATE"];
+                       if (!bUseYYGetStateNaked)
+                       {
+                               o << "()";
+                       }
+                       o << "];\n";
                }
                else
                {
-                       o << indent(ind) << "default: goto " << labelPrefix << start_label << ";\n";
-               }
-
-               for (size_t i=0; i<last_fill_index; ++i)
-               {
-                       o << indent(ind) << "case " << i << ": goto " << mapCodeName["yyFillLabel"] << i << ";\n";
+                       o << indent(ind) << "switch(" << mapCodeName["YYGETSTATE"];
+                       if (!bUseYYGetStateNaked)
+                       {
+                               o << "()";
+                       }
+                       o << ") {\n";
+                       if (bUseStateAbort)
+                       {
+                               o << indent(ind) << "default: abort();\n";
+                               o << indent(ind) << "case -1: goto " << labelPrefix << start_label << ";\n";
+                       }
+                       else
+                       {
+                               o << indent(ind) << "default: goto " << labelPrefix << start_label << ";\n";
+                       }
+       
+                       for (size_t i=0; i<last_fill_index; ++i)
+                       {
+                               o << indent(ind) << "case " << i << ": goto " << mapCodeName["yyFillLabel"] << i << ";\n";
+                       }
+       
+                       o << indent(ind) << "}\n";
                }
-
-               o << indent(ind) << "}\n";
                if (bUseStateNext)
                {
                        o << mapCodeName["yyNext"] << ":\n";
@@ -1988,6 +2037,7 @@ void Scanner::config(const Str& cfg, const Str& val)
                mapVariableKeys.insert("variable:yybm");
                mapVariableKeys.insert("variable:yych");
                mapVariableKeys.insert("variable:yyctable");
+               mapVariableKeys.insert("variable:yystable");
                mapVariableKeys.insert("variable:yytarget");
                mapDefineKeys.insert("define:YYCONDTYPE");
                mapDefineKeys.insert("define:YYCTXMARKER");
index 6e7a878edd2f5aa42e4a394b279c0d4c8621e34f..e10bde91a7e5e89b22eddbb1c7059d1621ea7435 100755 (executable)
@@ -78,13 +78,15 @@ void scan(Scanner *s)
 {
        s->tok = s->cur;
 
-       switch(s->state) {
-       default: goto yy0;
-       case 0: goto yyFillLabel0;
-       case 1: goto yyFillLabel1;
-       case 2: goto yyFillLabel2;
-       case 3: goto yyFillLabel3;
-       }
+       static void *yystable[] = {
+               &&yyFillLabel0,
+               &&yyFillLabel1,
+               &&yyFillLabel2,
+               &&yyFillLabel3,
+       };
+
+       if(s->state < 0) goto yy0;
+       goto *yystable[s->state];
        for(;;)
        {
                s->tok = s->cur;
@@ -170,7 +172,7 @@ yy9:
                        if(s->yych == '?') goto yy26;
 yy10:
                        {
-                               fputc(*s->tok, stdout);
+                               fputc(s->cur[-1], stdout);
                                continue;
                        }
 yy11:
@@ -187,7 +189,7 @@ yy13:
                        ++s->cur;
                        s->cond = EStateString;
                        {
-                               fputc(*s->tok, stdout);
+                               fputc(s->cur[-1], stdout);
                                continue;
                        }
 yy15:
@@ -321,55 +323,97 @@ yyc_Skiptoeol:
                        if((s->lim - s->cur) < 5) if(fill(s, 5) == ~0) break;
 yyFillLabel2:
                        s->yych = *s->cur;
-                       if(s->yych <= '>') {
-                               if(s->yych == 0x0A) goto yy50;
-                               goto yy52;
-                       } else {
-                               if(s->yych <= '?') goto yy47;
-                               if(s->yych == '\\') goto yy49;
-                               goto yy52;
+                       {
+                               static void *yytarget[256] = {
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy51, &&yy53, &&yy53, &&yy50, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy47,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy49, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53,
+                                       &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53, &&yy53
+                               };
+                               goto *yytarget[s->yych];
                        }
 yy47:
                        s->yych = *(s->tok = ++s->cur);
-                       if(s->yych == '?') goto yy57;
+                       if(s->yych == '?') goto yy60;
 yy48:
                        {
                                goto yyc_Skiptoeol;
                        }
 yy49:
                        s->yych = *(s->tok = ++s->cur);
-                       if(s->yych == 0x0A) goto yy55;
-                       if(s->yych == 0x0D) goto yy53;
+                       if(s->yych == 0x0A) goto yy58;
+                       if(s->yych == 0x0D) goto yy56;
                        goto yy48;
 yy50:
+                       s->yych = *++s->cur;
+                       if(s->yych == 0x0A) goto yy54;
+                       goto yy48;
+yy51:
                        ++s->cur;
                        s->cond = EStateNormal;
                        {
+                               fputc('\n', stdout);
                                continue;
                        }
-yy52:
-                       s->yych = *++s->cur;
-                       goto yy48;
 yy53:
                        s->yych = *++s->cur;
-                       if(s->yych == 0x0A) goto yy55;
+                       goto yy48;
 yy54:
+                       ++s->cur;
+                       s->cond = EStateNormal;
+                       {
+                               fputc('\r', stdout);
+                               fputc('\n', stdout);
+                               continue;
+                       }
+yy56:
+                       s->yych = *++s->cur;
+                       if(s->yych == 0x0A) goto yy58;
+yy57:
                        s->cur = s->tok;
                        goto yy48;
-yy55:
+yy58:
                        ++s->cur;
                        {
                                goto yyc_Skiptoeol;
                        }
-yy57:
+yy60:
                        s->yych = *++s->cur;
-                       if(s->yych != '/') goto yy54;
+                       if(s->yych != '/') goto yy57;
                        s->yych = *++s->cur;
-                       if(s->yych == 0x0A) goto yy60;
-                       if(s->yych != 0x0D) goto yy54;
+                       if(s->yych == 0x0A) goto yy63;
+                       if(s->yych != 0x0D) goto yy57;
                        s->yych = *++s->cur;
-                       if(s->yych != 0x0A) goto yy54;
-yy60:
+                       if(s->yych != 0x0A) goto yy57;
+yy63:
                        ++s->cur;
                        {
                                goto yyc_Skiptoeol;
@@ -380,29 +424,29 @@ yyc_String:
                        if((s->lim - s->cur) < 2) if(fill(s, 2) == ~0) break;
 yyFillLabel3:
                        s->yych = *s->cur;
-                       if(s->yych == '"') goto yy66;
-                       if(s->yych != '\\') goto yy68;
+                       if(s->yych == '"') goto yy69;
+                       if(s->yych != '\\') goto yy71;
                        ++s->cur;
-                       if((s->yych = *s->cur) != 0x0A) goto yy69;
-yy65:
+                       if((s->yych = *s->cur) != 0x0A) goto yy72;
+yy68:
                        {
-                               fputc(*s->tok, stdout);
+                               fputc(s->cur[-1], stdout);
                                continue;
                        }
-yy66:
+yy69:
                        ++s->cur;
                        s->cond = EStateNormal;
                        {
-                               fputc(*s->tok, stdout);
+                               fputc(s->cur[-1], stdout);
                                continue;
                        }
-yy68:
+yy71:
                        s->yych = *++s->cur;
-                       goto yy65;
-yy69:
+                       goto yy68;
+yy72:
                        ++s->cur;
                        {
-                               fputl((const char*)s->tok, 2, stdout);
+                               fputl((const char*)s->cur-2, 2, stdout);
                                continue;
                        }
                }
index 7bd5bce3b01d519030c3afd6d0cacdd2cd76ccc2..59b54a77ba0db2042cd45fc4362db53e49cc9172 100755 (executable)
@@ -159,12 +159,12 @@ re2c:condenumprefix          = EState;
                        }
 <Normal>       '"' => String
                        {
-                               fputc(*s->tok, stdout);
+                               fputc(s->cur[-1], stdout);
                                continue;
                        }
 <Normal>       [^]
                        {
-                               fputc(*s->tok, stdout);
+                               fputc(s->cur[-1], stdout);
                                continue;
                        }
 <Comment>      "*" "/" => Normal
@@ -183,8 +183,15 @@ re2c:condenumprefix          = EState;
                        {
                                goto yyc_Skiptoeol;
                        }
+<Skiptoeol>    "\r" "\n" => Normal
+                       {
+                               fputc('\r', stdout);
+                               fputc('\n', stdout);
+                               continue;
+                       }
 <Skiptoeol>    "\n" => Normal
                        {
+                               fputc('\n', stdout);
                                continue;
                        }
 <Skiptoeol> [^]
@@ -193,17 +200,17 @@ re2c:condenumprefix          = EState;
                        }
 <String>       '\\' .
                        {
-                               fputl((const char*)s->tok, 2, stdout);
+                               fputl((const char*)s->cur-2, 2, stdout);
                                continue;
                        }
 <String>       '"' => Normal
                        {
-                               fputc(*s->tok, stdout);
+                               fputc(s->cur[-1], stdout);
                                continue;
                        }
 <String>       [^]
                        {
-                               fputc(*s->tok, stdout);
+                               fputc(s->cur[-1], stdout);
                                continue;
                        }
 */
index ac3700dc06cb88e28bfc9df0f073f62808345533..d451e462d1ba0bd161d4486e225972981b3157ef 100755 (executable)
@@ -266,12 +266,14 @@ public:
                  0,   0,   0,   0,   0,   0,   0,   0, 
                  0,   0,   0,   0,   0,   0,   0,   0, 
        };
-       switch(YYGETSTATE()) {
-       default: goto yy0;
-       case 0: goto yyFillLabel0;
-       case 1: goto yyFillLabel1;
-       case 2: goto yyFillLabel2;
-       }
+       static void *yystable[] = {
+               &&yyFillLabel0,
+               &&yyFillLabel1,
+               &&yyFillLabel2,
+       };
+
+       if(YYGETSTATE() < 0) goto yy0;
+       goto *yystable[YYGETSTATE()];
 yy0:
        YYSETSTATE(0);
        if((YYLIMIT - YYCURSOR) < 7) YYFILL(7);
@@ -321,7 +323,7 @@ yy2:
 yy3:
 #line 246 "push.fg.re"
        { SEND(kIdentifier);     }
-#line 325 "<stdout>"
+#line 327 "<stdout>"
 yy4:
        yych = *++YYCURSOR;
        if(yych == 'o') goto yy64;
@@ -359,62 +361,62 @@ yy12:
 yy13:
 #line 247 "push.fg.re"
        { SEND(kDecimalConstant);}
-#line 363 "<stdout>"
+#line 365 "<stdout>"
 yy14:
        ++YYCURSOR;
 #line 249 "push.fg.re"
        { SEND(kEqual);          }
-#line 368 "<stdout>"
+#line 370 "<stdout>"
 yy16:
        ++YYCURSOR;
 #line 250 "push.fg.re"
        { SEND(kLeftParen);      }
-#line 373 "<stdout>"
+#line 375 "<stdout>"
 yy18:
        ++YYCURSOR;
 #line 251 "push.fg.re"
        { SEND(kRightParen);     }
-#line 378 "<stdout>"
+#line 380 "<stdout>"
 yy20:
        ++YYCURSOR;
 #line 252 "push.fg.re"
        { SEND(kMinus);          }
-#line 383 "<stdout>"
+#line 385 "<stdout>"
 yy22:
        ++YYCURSOR;
 #line 253 "push.fg.re"
        { SEND(kPlus);           }
-#line 388 "<stdout>"
+#line 390 "<stdout>"
 yy24:
        ++YYCURSOR;
 #line 254 "push.fg.re"
        { SEND(kStar);           }
-#line 393 "<stdout>"
+#line 395 "<stdout>"
 yy26:
        ++YYCURSOR;
 #line 255 "push.fg.re"
        { SEND(kSlash);          }
-#line 398 "<stdout>"
+#line 400 "<stdout>"
 yy28:
        ++YYCURSOR;
 #line 257 "push.fg.re"
        { SKIP();                }
-#line 403 "<stdout>"
+#line 405 "<stdout>"
 yy30:
        ++YYCURSOR;
 #line 258 "push.fg.re"
        { SKIP();                }
-#line 408 "<stdout>"
+#line 410 "<stdout>"
 yy32:
        ++YYCURSOR;
 #line 259 "push.fg.re"
        { send(kEOF); return 1;  }
-#line 413 "<stdout>"
+#line 415 "<stdout>"
 yy34:
        ++YYCURSOR;
 #line 260 "push.fg.re"
        { SEND(kUnknown);        }
-#line 418 "<stdout>"
+#line 420 "<stdout>"
 yy36:
        ++YYCURSOR;
        YYSETSTATE(1);
@@ -452,7 +454,7 @@ yy40:
        }
 #line 245 "push.fg.re"
        { SEND(kReturn);         }
-#line 456 "<stdout>"
+#line 458 "<stdout>"
 yy46:
        yych = *++YYCURSOR;
        if(yych != 'i') goto yy39;
@@ -466,7 +468,7 @@ yy46:
        }
 #line 244 "push.fg.re"
        { SEND(kWhile);          }
-#line 470 "<stdout>"
+#line 472 "<stdout>"
 yy51:
        yych = *++YYCURSOR;
        if(yych != 'e') goto yy39;
@@ -480,7 +482,7 @@ yy51:
        }
 #line 243 "push.fg.re"
        { SEND(kBreak);          }
-#line 484 "<stdout>"
+#line 486 "<stdout>"
 yy56:
        yych = *++YYCURSOR;
        if(yych != 't') goto yy39;
@@ -492,7 +494,7 @@ yy56:
        }
 #line 242 "push.fg.re"
        { SEND(kGoto);           }
-#line 496 "<stdout>"
+#line 498 "<stdout>"
 yy60:
        yych = *++YYCURSOR;
        if(yych != 's') goto yy39;
@@ -504,7 +506,7 @@ yy60:
        }
 #line 241 "push.fg.re"
        { SEND(kElse);           }
-#line 508 "<stdout>"
+#line 510 "<stdout>"
 yy64:
        yych = *++YYCURSOR;
        if(yych != 'r') goto yy39;
@@ -514,7 +516,7 @@ yy64:
        }
 #line 240 "push.fg.re"
        { SEND(kFor);            }
-#line 518 "<stdout>"
+#line 520 "<stdout>"
 yy67:
        ++YYCURSOR;
        if(yybm[0+(yych = *YYCURSOR)] & 128) {
@@ -522,7 +524,7 @@ yy67:
        }
 #line 239 "push.fg.re"
        { SEND(kIf);             }
-#line 526 "<stdout>"
+#line 528 "<stdout>"
 }
 #line 261 "push.fg.re"