X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/f10e19fd1a546ee6b79947c6de86ad7f118a6686..30bb2edccf7f352a0c149513905f5e1fcac04aaf:/etc/bench.pl.in diff --git a/etc/bench.pl.in b/etc/bench.pl.in index f71611f0..d058ce19 100755 --- a/etc/bench.pl.in +++ b/etc/bench.pl.in @@ -23,18 +23,21 @@ bench.pl - bench marks for Bison parsers. =head1 SYNOPSIS - ./bench.pl [OPTIONS]... I + ./bench.pl [OPTIONS]... DIRECTIVES =head1 DIRECTIVES Specify the set of benches to run. The following grammar defines the I: - I ::= I | I -- Alternation - | I & I -- Concatenation - | [ I ] -- Optional - | ( I ) -- Parentheses - | I + directives ::= + directives | directives -- Alternation + | directives & directives -- Concatenation + | [ directives> ] -- Optional + | ( directives> ) -- Parentheses + | %s skeleton -- %skeleton "skeleton" + | #d definition -- %code { #define definition } + | directive Parentheses only group to override precedence. For instance: @@ -575,8 +578,7 @@ sub generate_grammar_list ($$@) { my ($base, $max, @directive) = @_; my $directives = directives ($base, @directive); - my $variant = grep { $_ eq '%define variant' } @directive; - + my $variant = grep { /%define "?variant"?/ } @directive; my $out = new IO::File ">$base.y" or die; print $out <build(), yylval->ival) = stage; +#if USE_VARIANTS +# ifdef ONE_STAGE_BUILD + yylval->build(stage); +# else + yylval->build() = stage; +# endif +#else + yylval->ival = stage; +#endif return yy::parser::token::NUMBER; } else { - IF_VARIANTS(yylval->build() =, yylval->sval = new) std::string("A string."); +#if USE_VARIANTS +# ifdef ONE_STAGE_BUILD + yylval->build(std::string("A string.")); +# else + yylval->build() = std::string("A string."); +# endif +#else + yylval->sval = new std::string("A string."); +#endif return yy::parser::token::TEXT; } abort(); @@ -718,7 +743,7 @@ Generate F<$base.y> by calling C<&generate_grammar_$name>. sub generate_grammar ($$@) { my ($name, $base, @directive) = @_; - verbose 2, "Generating $base.y\n"; + verbose 3, "Generating $base.y\n"; my %generator = ( "calc" => \&generate_grammar_calc, @@ -739,7 +764,7 @@ Run, possibly verbosely, the shell C<$command>. sub run ($) { my ($command) = @_; - verbose 2, "$command\n"; + verbose 3, "$command\n"; system ("$command") == 0 or die "$command failed"; } @@ -813,7 +838,7 @@ sub bench ($@) # shows only wallclock and the two children times. 'auto' (the # default) will act as 'all' unless the children times are both # zero, in which case it acts as 'noc'. 'none' prevents output. - verbose 2, "Running the benches for $grammar\n"; + verbose 3, "Running the benches for $grammar\n"; my $res = timethese ($iterations, \%bench, 'nop'); # Output the speed result. @@ -864,15 +889,20 @@ Bench the C++ lalr1.cc parser using Boost.Variants or %union. sub bench_variant_parser () { - bench ('variant', - ('%skeleton "lalr1.cc"', - '&', - '[', '%debug', ']', - '&', - '[', '%define variant', ']', - '&', - '[', "%code {\n#define VARIANT_DESTROY\n}", ']' - )); + bench ('list', + qw( + %s lalr1.cc + & + [ %debug ] + & + [ %define variant + & + [ #d VARIANT_DESTROY ] + & + [ #d ONE_STAGE_BUILD ] + ] + ) + ); } ###################################################################### @@ -886,9 +916,12 @@ Bench the C++ lalr1.cc parser using Boost.Variants or %union. sub bench_fusion_parser () { bench ('list', - ('%skeleton "lalr1-split.cc"', - '|', - '%skeleton "lalr1.cc"')); + qw( + %s lalr1-split.cc + | + %s lalr1.cc + ) + ); } ############################################################################ @@ -913,11 +946,15 @@ my @token; # expr: term (| term)* # term: fact (& fact)* # fact: ( expr ) | [ expr ] | dirs +# dirs: %s SKELETON | #d DEFINE | directive sub parse (@) { @token = @_; - verbose 2, "Parsing: @token\n"; - return parse_expr (); + verbose 3, "Parsing: @token\n"; + my @res = parse_expr (); + die "expected end of directives, unexpected: @token" + if defined $token[0]; + return @res; } sub parse_expr () @@ -974,11 +1011,37 @@ sub parse_fact () unless $token[0] eq ']'; shift @token; } + else + { + @res = parse_dirs (); + } + return @res; +} + +sub parse_dirs () +{ + my @res; + die "unexpected end of expression" + unless defined $token[0]; + + if ($token[0] eq '#d') + { + shift @token; + @res = ("%code {\n#define\n}"); + shift @token; + } + elsif ($token[0] eq '%s') + { + shift @token; + @res = ("%skeleton \"$token[0]\""); + shift @token; + } else { @res = $token[0]; shift @token; } + return @res; } @@ -1000,36 +1063,53 @@ sub getopt () Getopt::Long::Configure ("bundling", "pass_through"); GetOptions (%option) or exit 1; - - # Support -b: predefined benches. - my %bench = - ( - "fusion" => \&bench_fusion_parser, - "push" => \&bench_push_parser, - "variant" => \&bench_variant_parser, - ); - - if (defined $bench) - { - die "invalid argument for --bench: $bench" - unless defined $bench{$bench}; - &{$bench{$bench}}(); - exit 0; - } } ###################################################################### getopt; + +# Create the directory we work in. +mkdir "benches" or die "cannot create benches" + unless -d "benches"; +my $count = 1; +++$count + while -d "benches/$count"; +my $dir = "benches/$count"; +mkdir $dir + or die "cannot create $dir"; +chdir $dir + or die "cannot chdir $dir"; + +# The following message is tailored to please Emacs' compilation-mode. +verbose 1, "Entering directory `$dir'\n"; verbose 1, "Using bison=$bison.\n"; -verbose 1, "Using cc=$cc.\n"; -verbose 1, "Using cxx=$cxx.\n"; -verbose 1, "Using cflags=$cflags.\n"; +verbose 2, "Using cc=$cc.\n"; +verbose 2, "Using cxx=$cxx.\n"; +verbose 2, "Using cflags=$cflags.\n"; verbose 2, "Grammar: $grammar\n"; -# Launch the bench marking. -bench ($grammar, @ARGV); +# Support -b: predefined benches. +my %bench = + ( + "fusion" => \&bench_fusion_parser, + "push" => \&bench_push_parser, + "variant" => \&bench_variant_parser, + ); + +if (defined $bench) +{ + die "invalid argument for --bench: $bench" + unless defined $bench{$bench}; + &{$bench{$bench}}(); + exit 0; +} +else +{ + # Launch the bench marking. + bench ($grammar, @ARGV); +} ### Setup "GNU" style for perl-mode and cperl-mode. ## Local Variables: