]> granicus.if.org Git - re2c/commitdiff
- Added -g switch to support gcc's computed goto's.
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 7 May 2006 19:11:37 +0000 (19:11 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Sun, 7 May 2006 19:11:37 +0000 (19:11 +0000)
# This is the initial step, maybe we use computed goto tables in other
# places too. That may however require to be able to configure a treshhold
# that defines when goto tables are being used.

CHANGELOG
code.cc
globals.h
main.cc
test/input8.b.c [new file with mode: 0755]
test/input8.b.re [new file with mode: 0755]
test/input8.g.c [new file with mode: 0755]
test/input8.g.re [new file with mode: 0755]

index a00975d54fedb7ec7e30ba05429fec7aedf91390..a9e3d92aae9b88183974998725bf125518d72123 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
 Version 0.10.3 (????-??-??)
 ---------------------------
+- Added -g switch to support gcc's computed goto's.
 - Changed to use nested if's instead of "switch(yyaccept)" in -s mode.
 
 Version 0.10.2 (2006-05-01)
diff --git a/code.cc b/code.cc
index c9a89fe273f816aeb114ba425e53471c0acd080f..df3ee6f8f11e04379cf174bd30c0a48c5d8fb4bf 100644 (file)
--- a/code.cc
+++ b/code.cc
@@ -524,8 +524,21 @@ void Accept::emit(std::ostream &o, uint ind, bool &readCh) const
                if (mapRules.size() > 1)
                {
                        bUsedYYAccept = true;
-                       
-                       if (sFlag)
+
+                       if (gFlag)
+                       {
+                               o << indent(ind++) << "{\n";
+                               o << indent(ind++) << "static void *yytarget[" << mapRules.size() << "] = {\n";
+                               for (RuleMap::const_iterator it = mapRules.begin(); it != mapRules.end(); ++it)
+                               {
+                                       o << indent(ind) << "&&yy" << it->second->label << ",\n";
+                                       vUsedLabels.insert(it->second->label);
+                               }
+                               o << indent(--ind) << "};\n";
+                               o << indent(ind) << "goto *yytarget[yyaccept];\n";
+                               o << indent(--ind) << "}\n";
+                       }
+                       else if (sFlag)
                        {
                                emitBinary(o, ind, 0, mapRules.size() - 1, readCh);
                        }
index 7cff108a0e6e8dcba93203578f478477077eb54c..610d4097397edd2b3ef49d79ad6f63ab74311a41 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -18,6 +18,7 @@ extern bool bFlag;
 extern bool dFlag;
 extern bool eFlag;
 extern bool fFlag;
+extern bool gFlag;
 extern bool iFlag;
 extern bool sFlag;
 extern bool wFlag;
diff --git a/main.cc b/main.cc
index ad7ab749661809839464c134f95d618f28628c26..4106015feb5ff0744c239bdf9b35fba4f4c7c28a 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -25,6 +25,7 @@ bool bFlag = false;
 bool dFlag = false;
 bool eFlag = false;
 bool fFlag = false;
+bool gFlag = false;
 bool iFlag = false;
 bool sFlag = false;
 bool wFlag = false;
@@ -68,6 +69,7 @@ static const mbo_opt_struct OPTIONS[] =
        mbo_opt_struct('d', 0, "debug-output"),
        mbo_opt_struct('e', 0, "ecb"),
        mbo_opt_struct('f', 0, "storable-state"),
+       mbo_opt_struct('g', 0, "computed-gotos"),
        mbo_opt_struct('h', 0, "help"),
        mbo_opt_struct('i', 0, "no-debug-info"),
        mbo_opt_struct('o', 1, "output"),
@@ -99,6 +101,9 @@ static void usage()
        "\n"
        "-f     --storable-state Generate a scanner that supports storable states.\n"
        "\n"
+       "-g     --computed-gotos Implies -b. Generate computed goto code (only useable \n"
+       "                        with gcc).\n"
+       "\n"
        "-i     --no-debug-info  Do not generate '#line' info (usefull for versioning).\n"
        "\n"
        "-o     --output=output  Specify the output file instead of stdout\n"
@@ -140,8 +145,8 @@ int main(int argc, char *argv[])
                {
 
                        case 'b':
-                       sFlag = true;
                        bFlag = true;
+                       sFlag = true;
                        break;
 
                        case 'e':
@@ -162,6 +167,12 @@ int main(int argc, char *argv[])
                        }
                        break;
 
+                       case 'g':
+                       gFlag = true;
+                       bFlag = true;
+                       sFlag = true;
+                       break;
+
                        case 'i':
                        iFlag = true;
                        break;
diff --git a/test/input8.b.c b/test/input8.b.c
new file mode 100755 (executable)
index 0000000..1f3d44d
--- /dev/null
@@ -0,0 +1,60 @@
+/* Generated by re2c */
+#line 1 "input8.b.re"
+{
+
+#line 6 "<stdout>"
+       {
+               YYCTYPE yych;
+               unsigned int yyaccept = 0;
+
+               if((YYLIMIT - YYCURSOR) < 4) YYFILL(4);
+               yych = *YYCURSOR;
+               if(yych == 0x0A) goto yy4;
+               yyaccept = 0;
+               yych = *(YYMARKER = ++YYCURSOR);
+               if(yych <= 0x00) goto yy6;
+               if(yych != 0x0A) goto yy8;
+yy3:
+#line 6 "input8.b.re"
+               { return 1; }
+#line 21 "<stdout>"
+yy4:
+               ++YYCURSOR;
+#line 7 "input8.b.re"
+               { return 2; }
+#line 26 "<stdout>"
+yy6:
+               yyaccept = 1;
+               yych = *(YYMARKER = ++YYCURSOR);
+               if(yych <= 0x00) goto yy10;
+               if(yych != 0x0A) goto yy11;
+yy7:
+#line 5 "input8.b.re"
+               { return 0; }
+#line 35 "<stdout>"
+yy8:
+               yych = *++YYCURSOR;
+               if(yych <= 0x00) goto yy10;
+               if(yych != 0x0A) goto yy11;
+yy9:
+               YYCURSOR = YYMARKER;
+               if(yyaccept <= 0) {
+                       goto yy3;
+               } else {
+                       goto yy7;
+               }
+yy10:
+               yych = *++YYCURSOR;
+               if(yych <= 0x00) goto yy12;
+               goto yy7;
+yy11:
+               yych = *++YYCURSOR;
+               if(yych >= 0x01) goto yy9;
+yy12:
+               ++YYCURSOR;
+               yych = *YYCURSOR;
+               goto yy7;
+       }
+}
+#line 9 "input8.b.re"
+
diff --git a/test/input8.b.re b/test/input8.b.re
new file mode 100755 (executable)
index 0000000..2a57f41
--- /dev/null
@@ -0,0 +1,9 @@
+/*!re2c
+
+any = [\000-\377];
+
+.{1,3}"\000"       { return 0; }
+.                  { return 1; }
+any                { return 2; }
+
+*/
diff --git a/test/input8.g.c b/test/input8.g.c
new file mode 100755 (executable)
index 0000000..1dd6e59
--- /dev/null
@@ -0,0 +1,62 @@
+/* Generated by re2c */
+#line 1 "input8.g.re"
+{
+
+#line 6 "<stdout>"
+       {
+               YYCTYPE yych;
+               unsigned int yyaccept = 0;
+
+               if((YYLIMIT - YYCURSOR) < 4) YYFILL(4);
+               yych = *YYCURSOR;
+               if(yych == 0x0A) goto yy4;
+               yyaccept = 0;
+               yych = *(YYMARKER = ++YYCURSOR);
+               if(yych <= 0x00) goto yy6;
+               if(yych != 0x0A) goto yy8;
+yy3:
+#line 6 "input8.g.re"
+               { return 1; }
+#line 21 "<stdout>"
+yy4:
+               ++YYCURSOR;
+#line 7 "input8.g.re"
+               { return 2; }
+#line 26 "<stdout>"
+yy6:
+               yyaccept = 1;
+               yych = *(YYMARKER = ++YYCURSOR);
+               if(yych <= 0x00) goto yy10;
+               if(yych != 0x0A) goto yy11;
+yy7:
+#line 5 "input8.g.re"
+               { return 0; }
+#line 35 "<stdout>"
+yy8:
+               yych = *++YYCURSOR;
+               if(yych <= 0x00) goto yy10;
+               if(yych != 0x0A) goto yy11;
+yy9:
+               YYCURSOR = YYMARKER;
+               {
+                       static void *yytarget[2] = {
+                               &&yy3,
+                               &&yy7,
+                       };
+                       goto *yytarget[yyaccept];
+               }
+yy10:
+               yych = *++YYCURSOR;
+               if(yych <= 0x00) goto yy12;
+               goto yy7;
+yy11:
+               yych = *++YYCURSOR;
+               if(yych >= 0x01) goto yy9;
+yy12:
+               ++YYCURSOR;
+               yych = *YYCURSOR;
+               goto yy7;
+       }
+}
+#line 9 "input8.g.re"
+
diff --git a/test/input8.g.re b/test/input8.g.re
new file mode 100755 (executable)
index 0000000..2a57f41
--- /dev/null
@@ -0,0 +1,9 @@
+/*!re2c
+
+any = [\000-\377];
+
+.{1,3}"\000"       { return 0; }
+.                  { return 1; }
+any                { return 2; }
+
+*/