=head1 SYNOPSIS
- ./bench.pl [OPTIONS]... I<directives>
+ ./bench.pl [OPTIONS]... DIRECTIVES
=head1 DIRECTIVES
Specify the set of benches to run. The following grammar defines the
I<directives>:
- I<directives> ::= I<directives> | I<directives> -- Alternation
- | I<directives> & I<directives> -- Concatenation
- | [ I<directives> ] -- Optional
- | ( I<directives> ) -- Parentheses
- | I<directive>
+ 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:
{
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 <<EOF;
static yy::parser::token_type yylex(yy::parser::semantic_type* yylval);
#define STAGE_MAX ($max * 10) // max = $max
+
#define USE_VARIANTS $variant
#if USE_VARIANTS
# define IF_VARIANTS(True, False) True
#else
# define IF_VARIANTS(True, False) False
#endif
+
+#ifdef ONE_STAGE_BUILD
+# define IF_ONE_STAGE_BUILD(True, False) True
+#else
+# define IF_ONE_STAGE_BUILD(True, False) False
+#endif
}
EOF
return yy::parser::token::END_OF_FILE;
else if (stage % 2)
{
- IF_VARIANTS(yylval->build<int>(), yylval->ival) = stage;
+#if USE_VARIANTS
+# ifdef ONE_STAGE_BUILD
+ yylval->build(stage);
+# else
+ yylval->build<int>() = stage;
+# endif
+#else
+ yylval->ival = stage;
+#endif
return yy::parser::token::NUMBER;
}
else
{
- IF_VARIANTS(yylval->build<std::string>() =, 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>() = std::string("A string.");
+# endif
+#else
+ yylval->sval = new std::string("A string.");
+#endif
return yy::parser::token::TEXT;
}
abort();
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,
sub run ($)
{
my ($command) = @_;
- verbose 2, "$command\n";
+ verbose 3, "$command\n";
system ("$command") == 0
or die "$command failed";
}
# 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.
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 ]
+ ]
+ )
+ );
}
######################################################################
sub bench_fusion_parser ()
{
bench ('list',
- ('%skeleton "lalr1-split.cc"',
- '|',
- '%skeleton "lalr1.cc"'));
+ qw(
+ %s lalr1-split.cc
+ |
+ %s lalr1.cc
+ )
+ );
}
############################################################################
# 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 ()
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;
}
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: