[llvm-commits] CVS: llvm-www/demo/index.cgi

Brian Gaeke gaeke at cs.uiuc.edu
Thu Nov 20 19:10:01 PST 2003


Changes in directory llvm-www/demo:

index.cgi updated: 1.16 -> 1.17

---
Log message:

Stats output seems to be working much better now.
Re-run perltidy on the code.


---
Diffs of the changes:  (+95 -61)

Index: llvm-www/demo/index.cgi
diff -u llvm-www/demo/index.cgi:1.16 llvm-www/demo/index.cgi:1.17
--- llvm-www/demo/index.cgi:1.16	Thu Nov 20 18:56:40 2003
+++ llvm-www/demo/index.cgi	Thu Nov 20 19:09:49 2003
@@ -5,7 +5,7 @@
 # doing remote web JO99C compilations.  (It could still be used for that
 # purpose, though the two scripts have diverged somewhat.)
 #
-# Last modified $Date: 2003/11/21 00:56:40 $
+# Last modified $Date: 2003/11/21 01:09:49 $
 #
 
 use CGI;
@@ -14,12 +14,12 @@
 
 open( STDERR, ">&STDOUT" ) or die "can't redirect stderr to stdout";
 
-if (! -d "/tmp/webcompile") { mkdir ("/tmp/webcompile", 0777); }
+if ( !-d "/tmp/webcompile" ) { mkdir( "/tmp/webcompile", 0777 ); }
 
-$LOGFILE           = '/tmp/webcompile/log.txt';
-$FORM_URL          = 'http://llvm.cs.uiuc.edu/demo/index.cgi';
-$CONTACT_ADDRESS   = 'gaeke -at- uiuc.edu';
-$LOGO_IMAGE_URL    = 'cathead.png';
+$LOGFILE         = '/tmp/webcompile/log.txt';
+$FORM_URL        = 'http://llvm.cs.uiuc.edu/demo/index.cgi';
+$CONTACT_ADDRESS = 'gaeke -at- uiuc.edu';
+$LOGO_IMAGE_URL  = 'cathead.png';
 @PREPENDPATHDIRS =
   ( '/home/vadve/gaeke/llvm/tools/Debug', '/home/vadve/gaeke/bin' );
 $ENV{'LLVM_LIB_SEARCH_PATH'} =
@@ -29,7 +29,8 @@
 sub getname {
     my ($extension) = @_;
     for ( my $count = 0 ; ; $count++ ) {
-        my $name = sprintf( "/tmp/webcompile/_%d_%d%s", $$, $count, $extension );
+        my $name =
+          sprintf( "/tmp/webcompile/_%d_%d%s", $$, $count, $extension );
         if ( !-f $name ) { return $name; }
     }
 }
@@ -70,14 +71,14 @@
     }
     close FILE;
     my $UnhilightedResult = $result;
-    my $HtmlResult = "<h3>$header</h3>\n<pre>\n"
-                   . $c->escapeHTML($result)
-                   . "\n</pre>\n";
-	if (wantarray) {
-		return ($UnhilightedResult, $HtmlResult);
-	} else {
-		return $HtmlResult;
-	}
+    my $HtmlResult        =
+      "<h3>$header</h3>\n<pre>\n" . $c->escapeHTML($result) . "\n</pre>\n";
+    if (wantarray) {
+        return ( $UnhilightedResult, $HtmlResult );
+    }
+    else {
+        return $HtmlResult;
+    }
 }
 
 sub syntaxHighlightLLVM {
@@ -90,12 +91,13 @@
 }
 
 sub mailto {
-	my ($recipient, $body) = @_;
-	my $msg = new Mail::Send (Subject=>"LLVM Demo Page Run", To=>$recipient);
+    my ( $recipient, $body ) = @_;
+    my $msg =
+      new Mail::Send( Subject => "LLVM Demo Page Run", To => $recipient );
     local ($fh);
-	$fh = $msg->open();
-	print $fh $body;
-	$fh->close();
+    $fh = $msg->open();
+    print $fh $body;
+    $fh->close();
 }
 
 $c = new CGI;
@@ -119,9 +121,8 @@
 </div>
 EOF
 
-
 if ($LOGO_IMAGE_URL) {
-  print "<img align=right width=100 height=114 src=\"$LOGO_IMAGE_URL\" />";
+    print "<img align=right width=100 height=114 src=\"$LOGO_IMAGE_URL\" />";
 }
 
 print <<END;
@@ -135,7 +136,6 @@
 
 END
 
-
 print $c->start_multipart_form( 'POST', $FORM_URL );
 
 print "Upload a file: ";
@@ -152,40 +152,47 @@
 
 print "<p />\n";
 
-print "<p>By the way, what language is this code in?: ", $c->radio_group(
+print "<p>By the way, what language is this code in?: ",
+  $c->radio_group(
     -name    => 'language',
     -values  => [ 'C', 'C++' ],
     -default => 'C'
-);
+  );
 print "</p>\n";
 
-
 print "<table border><tr><td>";
-print "<p>Click here if you want Bitter Melon to run the resulting code through c++filt.  Warning, the LLVM code produced will probably not be lexically valid, but it will be easier to read.</p><ul>",
+print
+"<p>Click here if you want Bitter Melon to run the resulting code through c++filt.  Warning, the LLVM code produced will probably not be lexically valid, but it will be easier to read.</p><ul>",
   $c->checkbox(
     -name  => 'cxxdemangle',
     -label => 'Demangle C++ names with c++filt'
-), "</ul>";
+  ),
+  "</ul>";
 print "</td><td>";
 
-print "<p>Bitter Melon can also run the link-time optimizer for you, if you like (but she won't link your code with any libraries.)</p><ul>",
+print
+"<p>Bitter Melon can also run the link-time optimizer for you, if you like (but she won't link your code with any libraries.)</p><ul>",
   $c->checkbox(
     -name  => 'linkopt',
     -label => 'Run link-time optimizer'
-), "</ul>";
+  ),
+  "</ul>";
 
 print "</td><td>";
 
-print "<p>Would you believe the cat even has a stopwatch? Click here to get detailed compilation statistics from each pass.</p><ul>",
+print
+"<p>Would you believe the cat even has a stopwatch? Click here to get detailed compilation statistics from each pass.</p><ul>",
   $c->checkbox(
     -name  => 'showstats',
     -label => 'Show detailed statistics'
-), "</ul>";
+  ),
+  "</ul>";
 print "</td></tr></table>";
 
 print "<p>", $c->submit, "\n", $c->endform;
 
-print "\n<p>If you have questions about the LLVM code generated by the front-end, please <a href='/docs/FAQ.html#cfe_code'>check the FAQ</a>, your question just might be answered (e.g., what is this <tt>__main</tt> thing?).</p>\n";
+print
+"\n<p>If you have questions about the LLVM code generated by the front-end, please <a href='/docs/FAQ.html#cfe_code'>check the FAQ</a>, your question just might be answered (e.g., what is this <tt>__main</tt> thing?).</p>\n";
 
 $ENV{'PATH'} = ( join ( ':', @PREPENDPATHDIRS ) ) . ":" . $ENV{'PATH'};
 
@@ -209,6 +216,8 @@
 
 sub try_run {
     my ( $program, $commandline, $outputFile ) = @_;
+
+    #print "command line was [ $commandline ]\n";
     my $retcode = system($commandline);
     if ( -s $outputFile ) {
         print dumpFile( "Output from $program", $outputFile );
@@ -227,12 +236,12 @@
 }
 
 %suffixes = (
-    'Java'              => '.java',
-    'JO99'              => '.jo9',
-    'C'                 => '.c',
-    'C++'               => '.cc',
-    'preprocessed C'    => '.i',
-    'preprocessed C++'  => '.ii'
+    'Java'             => '.java',
+    'JO99'             => '.jo9',
+    'C'                => '.c',
+    'C++'              => '.cc',
+    'preprocessed C'   => '.i',
+    'preprocessed C++' => '.ii'
 );
 %languages = (
     '.jo9'  => 'JO99',
@@ -274,32 +283,52 @@
     # Add a newline to the source here to avoid a warning from gcc.
     $source .= "\n";
 
+    # Avoid security hole due to #including bad stuff.
     $source =~
 s@(\n)?#include.*[<"](.*\.\..*)[">].*\n@$1#error "invalid #include file $2 detected"\n at g;
 
     my $inputFile = writeIntoFile( $extension, $source );
-    my $pid = $$;
+    my $pid       = $$;
 
     my $bytecodeFile = getname(".o");
     my $outputFile   = getname(".llvm-gcc.out");
+    my $timerFile    = getname(".llvm-gcc.time");
 
-	my $stats = '';
-	$stats = '-Wa,--stats,--time-passes' if ($c->param('showstats'));
+    my $stats = '';
+    $stats = "-Wa,--stats,--time-passes,--info-output-file=$timerFile"
+      if ( $c->param('showstats') );
     try_run( "llvm C/C++ front-end (llvm-gcc)",
         "llvm-gcc $stats -o $bytecodeFile -c $inputFile > $outputFile 2>&1",
         $outputFile );
+    if ( $c->param('showstats') && -s $timerFile ) {
+        ( $UnhilightedResult, $HtmlResult ) =
+          dumpFile( "Statistics for C/C++ front-end", $timerFile );
+        print "$HtmlResult\n";
+    }
 
     if ( $c->param('linkopt') ) {
-		my $stats = '';
-		my $outputFile   = getname(".gccld.out");
-		$stats = '--stats --time-passes' if ($c->param('showstats'));
-        print " Running link-time optimizer.\n";
+        my $stats      = '';
+        my $outputFile = getname(".gccld.out");
+        my $timerFile  = getname(".gccld.time");
+        $stats = "--stats --time-passes --info-output-file=$timerFile"
+          if ( $c->param('showstats') );
+        print " Running optimizing linker.\n";
         my $tmpFile = getname(".bc");
-        try_run("link-time optimizer (gccld)", "gccld $stats --link-as-library -o=$tmpFile $bytecodeFile > $outputFile 2>&1", $outputFile );
+        try_run(
+            "optimizing linker (gccld)",
+"gccld $stats --link-as-library -o=$tmpFile $bytecodeFile > $outputFile 2>&1",
+            $outputFile
+        );
         system("mv $tmpFile $bytecodeFile");
+
+        if ( $c->param('showstats') && -s $timerFile ) {
+            ( $UnhilightedResult, $HtmlResult ) =
+              dumpFile( "Statistics for optimizing linker", $timerFile );
+            print "$HtmlResult\n";
+        }
     }
 
-	print " Bytecode size is ", -s $bytecodeFile, " bytes.\n";
+    print " Bytecode size is ", -s $bytecodeFile, " bytes.\n";
 
     my $disassemblyFile = getname(".ll");
     try_run( "llvm-dis",
@@ -313,29 +342,34 @@
         system("mv $tmpFile $disassemblyFile");
     }
 
-    my ($UnhilightedResult, $HtmlResult);
+    my ( $UnhilightedResult, $HtmlResult );
     if ( -s $disassemblyFile ) {
-        ($UnhilightedResult, $HtmlResult)
-          = dumpFile( "Output from LLVM disassembler", $disassemblyFile );
+        ( $UnhilightedResult, $HtmlResult ) =
+          dumpFile( "Output from LLVM disassembler", $disassemblyFile );
         print syntaxHighlightLLVM($HtmlResult);
-    } else {
+    }
+    else {
         print "<p>Hmm, that's weird, llvm-dis didn't produce any output.</p>\n";
     }
     addlog( $source, $pid, $UnhilightedResult );
 
-	my ($ip, $host, $lg, $lines);
-	chomp ($lines = `wc -l < $inputFile`);
-	$lg = $c->param('language');
-	$ip = $c->remote_addr();
-	chomp ($host = `host $ip`) if $ip;
+    my ( $ip, $host, $lg, $lines );
+    chomp( $lines = `wc -l < $inputFile` );
+    $lg = $c->param('language');
+    $ip = $c->remote_addr();
+    chomp( $host = `host $ip` ) if $ip;
     mailto( 'lattner at cs.uiuc.edu',
-            "--- Query: ---\nFrom: ($ip) $host\nInput: $lines lines of $lg\n"
-          . "cxxdemangle = " . ($c->param('cxxdemangle') ? 1 : 0)
-          . ", linkopt = " . ($c->param('linkopt') ? 1 : 0) . "\n\n"
+        "--- Query: ---\nFrom: ($ip) $host\nInput: $lines lines of $lg\n"
+          . "C++ demangle = "
+          . ( $c->param('cxxdemangle') ? 1 : 0 )
+          . ", Link opt = "
+          . ( $c->param('linkopt') ? 1 : 0 ) . "\n\n"
+          . ", Show stats = "
+          . ( $c->param('showstats') ? 1 : 0 ) . "\n\n"
           . "--- Source: ---\n$source\n"
           . "--- Result: ---\n$UnhilightedResult\n" );
 
-	unlink( $inputFile, $bytecodeFile, $outputFile, $disassemblyFile );
+    unlink( $inputFile, $bytecodeFile, $outputFile, $disassemblyFile );
 }
 
 print $c->hr, "<address>$CONTACT_ADDRESS</address>", $c->end_html;





More information about the llvm-commits mailing list