From: helly Date: Sun, 7 May 2006 19:11:37 +0000 (+0000) Subject: - Added -g switch to support gcc's computed goto's. X-Git-Tag: 0.13.6~351 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7e6f657f04ffad7961e9ac549fa59bebc3d2e10;p=re2c - Added -g switch to support gcc's computed goto's. # 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. --- diff --git a/CHANGELOG b/CHANGELOG index a00975d5..a9e3d92a 100644 --- 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 c9a89fe2..df3ee6f8 100644 --- 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); } diff --git a/globals.h b/globals.h index 7cff108a..610d4097 100644 --- 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 ad7ab749..4106015f 100644 --- 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 index 00000000..1f3d44d4 --- /dev/null +++ b/test/input8.b.c @@ -0,0 +1,60 @@ +/* Generated by re2c */ +#line 1 "input8.b.re" +{ + +#line 6 "" + { + 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 "" +yy4: + ++YYCURSOR; +#line 7 "input8.b.re" + { return 2; } +#line 26 "" +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 "" +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 index 00000000..2a57f414 --- /dev/null +++ b/test/input8.b.re @@ -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 index 00000000..1dd6e591 --- /dev/null +++ b/test/input8.g.c @@ -0,0 +1,62 @@ +/* Generated by re2c */ +#line 1 "input8.g.re" +{ + +#line 6 "" + { + 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 "" +yy4: + ++YYCURSOR; +#line 7 "input8.g.re" + { return 2; } +#line 26 "" +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 "" +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 index 00000000..2a57f414 --- /dev/null +++ b/test/input8.g.re @@ -0,0 +1,9 @@ +/*!re2c + +any = [\000-\377]; + +.{1,3}"\000" { return 0; } +. { return 1; } +any { return 2; } + +*/