bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bench: use *.cc for C++


From: Akim Demaille
Subject: bench: use *.cc for C++
Date: Sat, 9 May 2020 16:47:35 +0200

commit 19f45df02bf434477731a9aab9b3add5c642d01a
Author: Akim Demaille <address@hidden>
Date:   Sun Mar 22 17:15:50 2020 +0100

    bench: use *.cc for C++
    
    Using *.c is simpler, but triggers annoying warnings with Clang++.
    
    * etc/bench.pl.in: Please the dictator.

diff --git a/etc/bench.pl.in b/etc/bench.pl.in
index 96299939..053efd22 100755
--- a/etc/bench.pl.in
+++ b/etc/bench.pl.in
@@ -775,30 +775,50 @@ sub run ($)
 
 ##################################################################
 
-=item C<compile ($base)>
+=item C<language ($base)>
 
-The compiler to use depending on the %language specification in
-C<$base.y>.
+The language to use depending on the %language specification in
+C<$base.y>: C<c> or C<c++>.
 
 =cut
 
-sub compiler ($)
+sub language ($)
 {
   my ($base) = @_;
   if ($gbench)
     {
-      $cxx;
+      "c++";
     }
   else
     {
       my $language = `sed -ne '/%language "\\(.*\\)"/{s//\\1/;p;q;}' $base.y`;
       chomp $language;
-      $language eq 'C++' ? $cxx : $cc;
+      $language eq 'C++' ? "c++" : "c";
     }
 }
 
 ##################################################################
 
+=item C<compiler ($base)>
+
+The compiler to use depending on the %language specification in
+C<$base.y>.
+
+=cut
+
+sub compiler ($)
+{
+  my ($base) = @_;
+  my %compiler =
+    (
+      'c++' => $cxx,
+      'c'   => $cc,
+    );
+  $compiler{language ($base)};
+}
+
+##################################################################
+
 =item C<compile ($base)>
 
 Compile C<$base.y> to an executable.
@@ -812,14 +832,20 @@ sub compile ($)
 
   my $my_bison = `sed -ne '/[/][/] %bison "\\(.*\\)"/{s//\\1/;p;q;}' $base.y`;
   chop $my_bison;
-  run ((length $my_bison ? $my_bison : $bison) . " $base.y -o $base.c");
+  my %ext =
+    (
+      'c++' => 'cc',
+      'c'   => 'c',
+    );
+  my $ext = $ext{language ($base)};
+  run ((length $my_bison ? $my_bison : $bison) . " $base.y -o $base.$ext");
   if ($gbench)
     {
-      run "$compiler -c -o $base.o $cflags $base.c";
+      run "$compiler -c -o $base.o $cflags $base.$ext";
     }
   else
     {
-      run "$compiler -o $base $cflags $base.c";
+      run "$compiler -o $base $cflags $base.$ext";
     }
 }
 
@@ -920,14 +946,14 @@ EOF
       push @obj, "$base.o";
     }
 
-  my $out = new IO::File ">main.c";
+  my $out = new IO::File ">main.cc";
   print $out <<EOF;
 #include <benchmark/benchmark.h>
 
 BENCHMARK_MAIN();
 EOF
 
-  run "$compiler -o main $cflags main.c @obj -lbenchmark";
+  run "$compiler -o main $cflags main.cc @obj -lbenchmark";
   run "./main | tee -a README.md";
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]