mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
bench: check impact of %debug on variants.
* etc/bench.pl.in (variant_grammar): Fix the computation of $variant. Generate a grammar file that can work with or without %debug. Do use the @directive. (bench_variant_parser): Check impact of %debug. (@directives): Rename all the occurrences to... (@directive): this, for consistency.
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
|||||||
|
2008-11-03 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
|
bench: check impact of %debug on variants.
|
||||||
|
* etc/bench.pl.in (variant_grammar): Fix the computation of
|
||||||
|
$variant.
|
||||||
|
Generate a grammar file that can work with or without %debug.
|
||||||
|
Do use the @directive.
|
||||||
|
(bench_variant_parser): Check impact of %debug.
|
||||||
|
(@directives): Rename all the occurrences to...
|
||||||
|
(@directive): this, for consistency.
|
||||||
|
|
||||||
2008-11-03 Akim Demaille <demaille@gostai.com>
|
2008-11-03 Akim Demaille <demaille@gostai.com>
|
||||||
|
|
||||||
bench: report the size too.
|
bench: report the size too.
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ not a valid directive.
|
|||||||
|
|
||||||
sub directives($@)
|
sub directives($@)
|
||||||
{
|
{
|
||||||
my ($bench, @directives) = @_;
|
my ($bench, @directive) = @_;
|
||||||
my $res = "/* Directives for bench `$bench'. */\n";
|
my $res = "/* Directives for bench `$bench'. */\n";
|
||||||
for my $d (@directives)
|
for my $d (@directive)
|
||||||
{
|
{
|
||||||
$res .= $d . "\n"
|
$res .= $d . "\n"
|
||||||
unless $d eq '%variant';
|
unless $d eq '%variant';
|
||||||
@@ -130,7 +130,7 @@ sub directives($@)
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
=item C<triangular_grammar ($base, $max, @directives)>
|
=item C<triangular_grammar ($base, $max, @directive)>
|
||||||
|
|
||||||
Create a large triangular grammar which looks like :
|
Create a large triangular grammar which looks like :
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ Create a large triangular grammar which looks like :
|
|||||||
|
|
||||||
C<$base> is the base name for the file to create (F<$base.y>).
|
C<$base> is the base name for the file to create (F<$base.y>).
|
||||||
C<$max> is the number of such rules (here, 5). You may pass
|
C<$max> is the number of such rules (here, 5). You may pass
|
||||||
additional Bison C<@directives>.
|
additional Bison C<@directive>.
|
||||||
|
|
||||||
The created parser is self contained: it includes its scanner, and
|
The created parser is self contained: it includes its scanner, and
|
||||||
source of input.
|
source of input.
|
||||||
@@ -158,8 +158,8 @@ source of input.
|
|||||||
|
|
||||||
sub triangular_grammar ($$$)
|
sub triangular_grammar ($$$)
|
||||||
{
|
{
|
||||||
my ($base, $max, @directives) = @_;
|
my ($base, $max, @directive) = @_;
|
||||||
my $directives = directives ($base, @directives);
|
my $directives = directives ($base, @directive);
|
||||||
|
|
||||||
my $out = new IO::File ">$base.y"
|
my $out = new IO::File ">$base.y"
|
||||||
or die;
|
or die;
|
||||||
@@ -267,18 +267,18 @@ sub calc_input ($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
=item C<calc_grammar ($base, $max, @directives)>
|
=item C<calc_grammar ($base, $max, @directive)>
|
||||||
|
|
||||||
Generate a Bison file F<$base.y> for a calculator parser in C. Pass
|
Generate a Bison file F<$base.y> for a calculator parser in C. Pass
|
||||||
the additional Bison C<@directives>. C<$max> is ignored, but left to
|
the additional Bison C<@directive>. C<$max> is ignored, but left to
|
||||||
have the same interface as C<triangular_grammar>.
|
have the same interface as C<triangular_grammar>.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub calc_grammar ($$$)
|
sub calc_grammar ($$$)
|
||||||
{
|
{
|
||||||
my ($base, $max, @directives) = @_;
|
my ($base, $max, @directive) = @_;
|
||||||
my $directives = directives ($base, @directives);
|
my $directives = directives ($base, @directive);
|
||||||
|
|
||||||
my $out = new IO::File ">$base.y"
|
my $out = new IO::File ">$base.y"
|
||||||
or die;
|
or die;
|
||||||
@@ -477,32 +477,32 @@ EOF
|
|||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
||||||
=item C<variant_grammar ($base, $max, @directives)>
|
=item C<variant_grammar ($base, $max, @directive)>
|
||||||
|
|
||||||
Generate a Bison file F<$base.y> that uses, or not, the Boost.Variants
|
Generate a Bison file F<$base.y> that uses, or not, the Boost.Variants
|
||||||
depending on the C<@directives>.
|
depending on the C<@directive>.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub variant_grammar ($$$)
|
sub variant_grammar ($$$)
|
||||||
{
|
{
|
||||||
my ($base, $max, @directives) = @_;
|
my ($base, $max, @directive) = @_;
|
||||||
my $directives = directives ($base, @directives);
|
my $directives = directives ($base, @directive);
|
||||||
my $variant = grep { '%variant' } @directives;
|
my $variant = grep { $_ eq '%variant' } @directive;
|
||||||
|
|
||||||
my $out = new IO::File ">$base.y"
|
my $out = new IO::File ">$base.y"
|
||||||
or die;
|
or die;
|
||||||
print $out <<EOF;
|
print $out <<EOF;
|
||||||
%debug
|
|
||||||
%language "C++"
|
%language "C++"
|
||||||
%defines
|
%defines
|
||||||
|
$directives
|
||||||
|
|
||||||
%code requires // code for the .hh file
|
%code requires // variant.h
|
||||||
{
|
{
|
||||||
#include <string>
|
#include <string>
|
||||||
}
|
}
|
||||||
|
|
||||||
%code // code for the .cc file
|
%code // variant.c
|
||||||
{
|
{
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -612,7 +612,9 @@ yy::parser::error(const yy::parser::location_type& yylloc,
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
yy::parser p;
|
yy::parser p;
|
||||||
|
#if YYDEBUG
|
||||||
p.set_debug_level(!!getenv("YYDEBUG"));
|
p.set_debug_level(!!getenv("YYDEBUG"));
|
||||||
|
#endif
|
||||||
p.parse();
|
p.parse();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -647,9 +649,9 @@ sub compile ($)
|
|||||||
Generate benches for C<$gram>. C<$gram> should be C<calc> or
|
Generate benches for C<$gram>. C<$gram> should be C<calc> or
|
||||||
C<triangle>. C<%bench> is a hash of the form:
|
C<triangle>. C<%bench> is a hash of the form:
|
||||||
|
|
||||||
$name => @directives
|
$name => @directive
|
||||||
|
|
||||||
where C<$name> is the name of the bench, and C<@directives> are the
|
where C<$name> is the name of the bench, and C<@directive> are the
|
||||||
Bison directive to use for this bench. All the benches are compared
|
Bison directive to use for this bench. All the benches are compared
|
||||||
against each other, repeated 50 times.
|
against each other, repeated 50 times.
|
||||||
|
|
||||||
@@ -671,6 +673,7 @@ sub bench_grammar ($%)
|
|||||||
# Call the Bison input file generator.
|
# Call the Bison input file generator.
|
||||||
my $generator = "$gram" . "_grammar";
|
my $generator = "$gram" . "_grammar";
|
||||||
&$generator ($name, 200, @$directives);
|
&$generator ($name, 200, @$directives);
|
||||||
|
# Compile the executable.
|
||||||
compile ($name);
|
compile ($name);
|
||||||
$bench{$name} = "system ('./$name');";
|
$bench{$name} = "system ('./$name');";
|
||||||
chop($size{$name} = `wc -c <$name`);
|
chop($size{$name} = `wc -c <$name`);
|
||||||
@@ -732,8 +735,10 @@ sub bench_variant_parser ()
|
|||||||
bench_grammar
|
bench_grammar
|
||||||
('variant',
|
('variant',
|
||||||
(
|
(
|
||||||
"union" => [],
|
"union" => [],
|
||||||
"variant" => ['%variant'],
|
"variant" => ['%variant'],
|
||||||
|
"union-debug" => ['%debug'],
|
||||||
|
"variant-debug" => ['%debug', '%variant'],
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user