diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-10-23 14:19:52 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-10-23 14:19:52 +0000 |
commit | 4a142eb28942073eb27a112b5ca1cca3f01beb9c (patch) | |
tree | 22cc59e4b240d84c3a5a60531119c4eca914a256 /utils | |
parent | 5cd822fa9bbb9622241e3bf4d7674ed49ccde5b9 (diff) |
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/NewNightlyTest.pl | 944 | ||||
-rw-r--r-- | utils/TableGen/AsmWriterEmitter.cpp | 23 | ||||
-rw-r--r-- | utils/TableGen/ClangDiagnosticsEmitter.cpp | 16 | ||||
-rw-r--r-- | utils/TableGen/CodeGenDAGPatterns.h | 2 | ||||
-rw-r--r-- | utils/TableGen/DAGISelEmitter.cpp | 12 | ||||
-rw-r--r-- | utils/TableGen/LLVMCConfigurationEmitter.cpp | 637 | ||||
-rw-r--r-- | utils/TableGen/LLVMCConfigurationEmitter.h | 3 | ||||
-rw-r--r-- | utils/TableGen/StringToOffsetTable.h | 9 | ||||
-rw-r--r-- | utils/buildit/GNUmakefile | 2 | ||||
-rwxr-xr-x | utils/buildit/build_llvm | 4 | ||||
-rw-r--r-- | utils/emacs/tablegen-mode.el | 2 | ||||
-rw-r--r-- | utils/lit/LitConfig.py | 22 | ||||
-rw-r--r-- | utils/lit/TestFormats.py | 4 | ||||
-rw-r--r-- | utils/lit/TestRunner.py | 6 |
14 files changed, 906 insertions, 780 deletions
diff --git a/utils/NewNightlyTest.pl b/utils/NewNightlyTest.pl index 477df8fc12e0..ed22b77f9989 100755 --- a/utils/NewNightlyTest.pl +++ b/utils/NewNightlyTest.pl @@ -15,19 +15,48 @@ use Socket; # Syntax: NightlyTest.pl [OPTIONS] [CVSROOT BUILDDIR WEBDIR] # where # OPTIONS may include one or more of the following: +# +# MAIN OPTIONS: +# -config LLVMPATH If specified, use an existing LLVM build and only run and +# report the test information. The LLVMCONFIG argument should +# be the path to the llvm-config executable in the LLVM build. +# This should be the first argument if given. NOT YET +# IMPLEMENTED. +# -nickname NAME The NAME argument specifieds the nickname this script +# will submit to the nightlytest results repository. +# -submit-server Specifies a server to submit the test results too. If this +# option is not specified it defaults to +# llvm.org. This is basically just the address of the +# webserver +# -submit-script Specifies which script to call on the submit server. If +# this option is not specified it defaults to +# /nightlytest/NightlyTestAccept.php. This is basically +# everything after the www.yourserver.org. +# -submit-aux If specified, an auxiliary script to run in addition to the +# normal submit script. The script will be passed the path to +# the "sentdata.txt" file as its sole argument. +# -nosubmit Do not report the test results back to a submit server. +# +# +# BUILD OPTIONS (not used with -config): # -nocheckout Do not create, checkout, update, or configure # the source tree. # -noremove Do not remove the BUILDDIR after it has been built. # -noremoveresults Do not remove the WEBDIR after it has been built. # -nobuild Do not build llvm. If tests are enabled perform them # on the llvm build specified in the build directory -# -notest Do not even attempt to run the test programs. -# -nodejagnu Do not run feature or regression tests -# -parallel Run parallel jobs with GNU Make (see -parallel-jobs). -# -parallel-jobs The number of parallel Make jobs to use (default is two). -# -with-clang Checkout Clang source into tools/clang. # -release Build an LLVM Release version # -release-asserts Build an LLVM ReleaseAsserts version +# -disable-bindings Disable building LLVM bindings. +# -with-clang Checkout Clang source into tools/clang. +# -compileflags Next argument specifies extra options passed to make when +# building LLVM. +# -use-gmake Use gmake instead of the default make command to build +# llvm and run tests. +# +# TESTING OPTIONS: +# -notest Do not even attempt to run the test programs. +# -nodejagnu Do not run feature or regression tests # -enable-llcbeta Enable testing of beta features in llc. # -enable-lli Enable testing of lli (interpreter) features, default is off # -disable-pic Disable building with Position Independent Code. @@ -35,19 +64,25 @@ use Socket; # -disable-jit Disable JIT tests in the nightly tester. # -disable-cbe Disable C backend tests in the nightly tester. # -disable-lto Disable link time optimization. -# -disable-bindings Disable building LLVM bindings. +# -test-cflags Next argument specifies that C compilation options that +# override the default when running the testsuite. +# -test-cxxflags Next argument specifies that C++ compilation options that +# override the default when running the testsuite. +# -extraflags Next argument specifies extra options that are passed to +# compile the tests. +# -noexternals Do not run the external tests (for cases where povray +# or SPEC are not installed) +# -with-externals Specify a directory where the external tests are located. +# +# OTHER OPTIONS: +# -parallel Run parallel jobs with GNU Make (see -parallel-jobs). +# -parallel-jobs The number of parallel Make jobs to use (default is two). +# -parallel-test Allow parallel execution of llvm-test # -verbose Turn on some debug output -# -debug Print information useful only to maintainers of this script. # -nice Checkout/Configure/Build with "nice" to reduce impact # on busy servers. # -f2c Next argument specifies path to F2C utility -# -nickname The next argument specifieds the nickname this script -# will submit to the nightlytest results repository. # -gccpath Path to gcc/g++ used to build LLVM -# -cvstag Check out a specific CVS tag to build LLVM (useful for -# testing release branches) -# -usecvs Check code out from the (old) CVS Repository instead of from -# the standard Subversion repository. # -target Specify the target triplet # -cflags Next argument specifies that C compilation options that # override the default. @@ -55,40 +90,11 @@ use Socket; # override the default. # -ldflags Next argument specifies that linker options that override # the default. -# -test-cflags Next argument specifies that C compilation options that -# override the default when running the testsuite. -# -test-cxxflags Next argument specifies that C++ compilation options that -# override the default when running the testsuite. -# -compileflags Next argument specifies extra options passed to make when -# building LLVM. -# -use-gmake Use gmake instead of the default make command to build -# llvm and run tests. -# -# ---------------- Options to configure llvm-test ---------------------------- -# -extraflags Next argument specifies extra options that are passed to -# compile the tests. -# -noexternals Do not run the external tests (for cases where povray -# or SPEC are not installed) -# -with-externals Specify a directory where the external tests are located. -# -submit-server Specifies a server to submit the test results too. If this -# option is not specified it defaults to -# llvm.org. This is basically just the address of the -# webserver -# -submit-script Specifies which script to call on the submit server. If -# this option is not specified it defaults to -# /nightlytest/NightlyTestAccept.php. This is basically -# everything after the www.yourserver.org. -# -submit-aux If specified, an auxiliary script to run in addition to the -# normal submit script. The script will be passed the path to -# the "sentdata.txt" file as its sole argument. -# -nosubmit Do not report the test results back to a submit server. # -# CVSROOT is the CVS repository from which the tree will be checked out, -# specified either in the full :method:user@host:/dir syntax, or -# just /dir if using a local repo. +# CVSROOT is ignored, it is passed for backwards compatibility. # BUILDDIR is the directory where sources for this test run will be checked out # AND objects for this test run will be built. This directory MUST NOT -# exist before the script is run; it will be created by the cvs checkout +# exist before the script is run; it will be created by the svn checkout # process and erased (unless -noremove is specified; see above.) # WEBDIR is the directory into which the test results web page will be written, # AND in which the "index.html" is assumed to be a symlink to the most recent @@ -106,12 +112,8 @@ my $SVNURL = $ENV{"SVNURL"}; $SVNURL = 'http://llvm.org/svn/llvm-project' unless $SVNURL; my $TestSVNURL = $ENV{"TestSVNURL"}; $TestSVNURL = 'http://llvm.org/svn/llvm-project' unless $TestSVNURL; -my $CVSRootDir = $ENV{'CVSROOT'}; -$CVSRootDir = "/home/vadve/shared/PublicCVS" unless $CVSRootDir; my $BuildDir = $ENV{'BUILDDIR'}; -$BuildDir = "$HOME/buildtest" unless $BuildDir; my $WebDir = $ENV{'WEBDIR'}; -$WebDir = "$HOME/cvs/testresults-X86" unless $WebDir; my $LLVMSrcDir = $ENV{'LLVMSRCDIR'}; $LLVMSrcDir = "$BuildDir/llvm" unless $LLVMSrcDir; @@ -133,10 +135,10 @@ my $DATE = sprintf "%4d-%02d-%02d_%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3 # Parse arguments... # ############################################################## +$CONFIG_PATH=""; $CONFIGUREARGS=""; $nickname=""; $NOTEST=0; -$USESVN=1; $MAKECMD="make"; $SUBMITSERVER = "llvm.org"; $SUBMITSCRIPT = "/nightlytest/NightlyTestAccept.php"; @@ -150,22 +152,22 @@ while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) { last if /^--$/; # Stop processing arguments on -- # List command line options here... + if (/^-config$/) { $CONFIG_PATH = "$ARGV[0]"; shift; next; } if (/^-nocheckout$/) { $NOCHECKOUT = 1; next; } - if (/^-nocvsstats$/) { $NOCVSSTATS = 1; next; } if (/^-noremove$/) { $NOREMOVE = 1; next; } if (/^-noremoveatend$/) { $NOREMOVEATEND = 1; next; } if (/^-noremoveresults$/){ $NOREMOVERESULTS = 1; next; } if (/^-notest$/) { $NOTEST = 1; next; } if (/^-norunningtests$/) { next; } # Backward compatibility, ignored. if (/^-parallel-jobs$/) { $PARALLELJOBS = "$ARGV[0]"; shift; next;} - if (/^-parallel$/) { $MAKEOPTS = "$MAKEOPTS -j$PARALLELJOBS -l3.0"; next; } + if (/^-parallel$/) { $MAKEOPTS = "$MAKEOPTS -j$PARALLELJOBS"; next; } + if (/^-parallel-test$/) { $PROGTESTOPTS .= " ENABLE_PARALLEL_REPORT=1"; next; } if (/^-with-clang$/) { $WITHCLANG = 1; next; } if (/^-release$/) { $MAKEOPTS = "$MAKEOPTS ENABLE_OPTIMIZED=1 ". - "OPTIMIZE_OPTION=-O2"; $BUILDTYPE="release"; next;} + "OPTIMIZE_OPTION=-O2"; next;} if (/^-release-asserts$/){ $MAKEOPTS = "$MAKEOPTS ENABLE_OPTIMIZED=1 ". "DISABLE_ASSERTIONS=1 ". - "OPTIMIZE_OPTION=-O2"; - $BUILDTYPE="release-asserts"; next;} + "OPTIMIZE_OPTION=-O2"; next;} if (/^-enable-llcbeta$/) { $PROGTESTOPTS .= " ENABLE_LLCBETA=1"; next; } if (/^-disable-pic$/) { $CONFIGUREARGS .= " --enable-pic=no"; next; } if (/^-enable-lli$/) { $PROGTESTOPTS .= " ENABLE_LLI=1"; @@ -180,7 +182,6 @@ while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) { if (/^-test-opts$/) { $PROGTESTOPTS .= " $ARGV[0]"; shift; next; } if (/^-verbose$/) { $VERBOSE = 1; next; } if (/^-teelogs$/) { $TEELOGS = 1; next; } - if (/^-debug$/) { $DEBUG = 1; next; } if (/^-nice$/) { $NICE = "nice "; next; } if (/^-f2c$/) { $CONFIGUREARGS .= " --with-f2c=$ARGV[0]"; shift; next; } @@ -197,9 +198,6 @@ while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) { " CC=$ARGV[0]/gcc CXX=$ARGV[0]/g++"; $GCCPATH=$ARGV[0]; shift; next; } else { $GCCPATH=""; } - if (/^-cvstag/) { $CVSCOOPT .= " -r $ARGV[0]"; shift; next; } - else { $CVSCOOPT="";} - if (/^-usecvs/) { $USESVN = 0; } if (/^-target/) { $CONFIGUREARGS .= " --target=$ARGV[0]"; shift; next; } if (/^-cflags/) { $MAKEOPTS = "$MAKEOPTS C.Flags=\'$ARGV[0]\'"; @@ -234,75 +232,62 @@ if ($CONFIGUREARGS !~ /--disable-jit/) { $CONFIGUREARGS .= " --enable-jit"; } -if (@ARGV != 0 and @ARGV != 3 and $VERBOSE) { - foreach $x (@ARGV) { - print "$x\n"; - } - print "Must specify 0 or 3 options!"; +if (@ARGV != 0 and @ARGV != 3) { + die "error: must specify 0 or 3 options!"; } if (@ARGV == 3) { - $CVSRootDir = $ARGV[0]; + if ($CONFIG_PATH ne "") { + die "error: arguments are unsupported in -config mode,"; + } + + # ARGV[0] used to be the CVS root, ignored for backward compatibility. $BuildDir = $ARGV[1]; $WebDir = $ARGV[2]; } -if ($CVSRootDir eq "" or - $BuildDir eq "" or - $WebDir eq "") { - die("please specify a cvs root directory, a build directory, and a ". - "web directory"); - } +if ($CONFIG_PATH ne "") { + $BuildDir = ""; + $SVNURL = $TestSVNURL = ""; + if ($WebDir eq "") { + die("please specify a web directory"); + } +} else { + if ($BuildDir eq "" or + $WebDir eq "") { + die("please specify a build directory, and a web directory"); + } +} if ($nickname eq "") { die ("Please invoke NewNightlyTest.pl with command line option " . "\"-nickname <nickname>\""); } -if ($BUILDTYPE ne "release" && $BUILDTYPE ne "release-asserts") { - $BUILDTYPE = "debug"; -} - ############################################################## # -#define the file names we'll use +# Define the file names we'll use # ############################################################## + my $Prefix = "$WebDir/$DATE"; -my $BuildLog = "$Prefix-Build-Log.txt"; -my $COLog = "$Prefix-CVS-Log.txt"; my $SingleSourceLog = "$Prefix-SingleSource-ProgramTest.txt.gz"; my $MultiSourceLog = "$Prefix-MultiSource-ProgramTest.txt.gz"; my $ExternalLog = "$Prefix-External-ProgramTest.txt.gz"; -my $DejagnuLog = "$Prefix-Dejagnu-testrun.log"; -my $DejagnuSum = "$Prefix-Dejagnu-testrun.sum"; -my $DejagnuTestsLog = "$Prefix-DejagnuTests-Log.txt"; -if (! -d $WebDir) { - mkdir $WebDir, 0777; - if($VERBOSE){ - warn "$WebDir did not exist; creating it.\n"; - } -} -if ($VERBOSE) { - print "INITIALIZED\n"; - if ($USESVN) { - print "SVN URL = $SVNURL\n"; - } else { - print "CVS Root = $CVSRootDir\n"; - } - print "COLog = $COLog\n"; - print "BuildDir = $BuildDir\n"; - print "WebDir = $WebDir\n"; - print "Prefix = $Prefix\n"; - print "BuildLog = $BuildLog\n"; -} +# These are only valid in non-config mode. +my $ConfigureLog = "", $BuildLog = "", $COLog = ""; +my $DejagnuLog = "", $DejagnuSum = "", $DejagnuLog = ""; + +# Are we in config mode? +my $ConfigMode = 0; ############################################################## # # Helper functions # ############################################################## + sub GetDir { my $Suffix = shift; opendir DH, $WebDir; @@ -349,61 +334,25 @@ sub RunAppendingLoggedCommand { } } -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# DiffFiles - Diff the current version of the file against the last version of -# the file, reporting things added and removed. This is used to report, for -# example, added and removed warnings. This returns a pair (added, removed) -# -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -sub DiffFiles { - my $Suffix = shift; - my @Others = GetDir $Suffix; - if (@Others == 0) { # No other files? We added all entries... - return (`cat $WebDir/$DATE$Suffix`, ""); - } -# Diff the files now... - my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`; - my $Added = join "\n", grep /^</, @Diffs; - my $Removed = join "\n", grep /^>/, @Diffs; - $Added =~ s/^< //gm; - $Removed =~ s/^> //gm; - return ($Added, $Removed); -} - -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub GetRegex { # (Regex with ()'s, value) - $_[1] =~ /$_[0]/m; - return $1 - if (defined($1)); + if ($_[1] =~ /$_[0]/m) { + return $1; + } return "0"; } -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -sub GetRegexNum { - my ($Regex, $Num, $Regex2, $File) = @_; - my @Items = split "\n", `grep '$Regex' $File`; - return GetRegex $Regex2, $Items[$Num]; -} - -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub ChangeDir { # directory, logical name my ($dir,$name) = @_; chomp($dir); if ( $VERBOSE ) { print "Changing To: $name ($dir)\n"; } $result = chdir($dir); if (!$result) { - print "ERROR!!! Cannot change directory to: $name ($dir) because $!"; + print "ERROR!!! Cannot change directory to: $name ($dir) because $!\n"; return false; } return true; } -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub ReadFile { if (open (FILE, $_[0])) { undef $/; @@ -417,16 +366,12 @@ sub ReadFile { } } -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub WriteFile { # (filename, contents) open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!\n"; print FILE $_[1]; close FILE; } -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub CopyFile { #filename, newfile my ($file, $newfile) = @_; chomp($file); @@ -435,32 +380,6 @@ sub CopyFile { #filename, newfile } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -sub AddRecord { - my ($Val, $Filename,$WebDir) = @_; - my @Records; - if (open FILE, "$WebDir/$Filename") { - @Records = grep !/$DATE/, split "\n", <FILE>; - close FILE; - } - push @Records, "$DATE: $Val"; - WriteFile "$WebDir/$Filename", (join "\n", @Records) . "\n"; -} - -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# -# FormatTime - Convert a time from 1m23.45 into 83.45 -# -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -sub FormatTime { - my $Time = shift; - if ($Time =~ m/([0-9]+)m([0-9.]+)/) { - $Time = sprintf("%7.4f", $1*60.0+$2); - } - return $Time; -} - -#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # This function is meant to read in the dejagnu sum file and # return a string with only the results (i.e. PASS/FAIL/XPASS/ @@ -499,10 +418,10 @@ sub GetDejagnuTestResults { # (filename, log) # to our central server via the post method # #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -sub SendData{ +sub SendData { $host = $_[0]; $file = $_[1]; - $variables=$_[2]; + $variables = $_[2]; # Write out the "...-sentdata.txt" file. @@ -517,7 +436,7 @@ sub SendData{ system "$SUBMITAUX \"$Prefix-sentdata.txt\""; } - if (!$SUBMIT) { + if (!$SUBMIT) { return "Skipped standard submit.\n"; } @@ -531,9 +450,9 @@ sub SendData{ } # Send the data to the server. - # + # # FIXME: This code should be more robust? - + $port=80; $socketaddr= sockaddr_in $port, inet_aton $host or die "Bad hostname\n"; socket SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp') or @@ -561,17 +480,13 @@ sub SendData{ ############################################################## # -# Getting Start timestamp +# Individual Build & Test Functions # ############################################################## -$starttime = `date "+20%y-%m-%d %H:%M:%S"`; -############################################################## -# -# Create the CVS repository directory -# -############################################################## -if (!$NOCHECKOUT) { +# Create the source repository directory. +sub CheckoutSource { + die "Invalid call!" unless $ConfigMode == 0; if (-d $BuildDir) { if (!$NOREMOVE) { if ( $VERBOSE ) { @@ -587,341 +502,54 @@ if (!$NOCHECKOUT) { } else { mkdir $BuildDir or die "Could not create checkout directory $BuildDir!"; } -} - -############################################################## -# -# Check out the llvm tree, using either SVN or CVS -# -############################################################## -if (!$NOCHECKOUT) { ChangeDir( $BuildDir, "checkout directory" ); - if ($USESVN) { - my $SVNCMD = "$NICE svn co --non-interactive $SVNURL"; - my $SVNCMD2 = "$NICE svn co --non-interactive $TestSVNURL"; - RunLoggedCommand("( time -p $SVNCMD/llvm/trunk llvm; cd llvm/projects ; " . - "$SVNCMD2/test-suite/trunk llvm-test )", $COLog, - "CHECKOUT LLVM"); - if ($WITHCLANG) { - my $SVNCMD = "$NICE svn co --non-interactive $SVNURL/cfe/trunk"; - RunLoggedCommand("( time -p cd llvm/tools ; $SVNCMD clang )", $COLog, - "CHECKOUT CLANG"); - } - } else { - my $CVSOPT = ""; - $CVSOPT = "-z3" # Use compression if going over ssh. - if $CVSRootDir =~ /^:ext:/; - my $CVSCMD = "$NICE cvs $CVSOPT -d $CVSRootDir co -P $CVSCOOPT"; - RunLoggedCommand("( time -p $CVSCMD llvm; cd llvm/projects ; " . - "$CVSCMD llvm-test )", $COLog, - "CHECKOUT LLVM-TEST"); + my $SVNCMD = "$NICE svn co --non-interactive"; + RunLoggedCommand("( time -p $SVNCMD $SVNURL/llvm/trunk llvm; cd llvm/projects ; " . + " $SVNCMD $TestSVNURL/test-suite/trunk llvm-test )", $COLog, + "CHECKOUT LLVM"); + if ($WITHCLANG) { + RunLoggedCommand("( cd llvm/tools ; " . + " $SVNCMD $SVNURL/cfe/trunk clang )", $COLog, + "CHECKOUT CLANG"); } } -ChangeDir( $LLVMSrcDir , "llvm source directory") ; -############################################################## -# -# Get some static statistics about the current state of CVS -# -# This can probably be put on the server side -# -############################################################## -my $CheckoutTime_Wall = GetRegex "([0-9.]+)", `grep '^real' $COLog`; -my $CheckoutTime_User = GetRegex "([0-9.]+)", `grep '^user' $COLog`; -my $CheckoutTime_Sys = GetRegex "([0-9.]+)", `grep '^sys' $COLog`; -my $CheckoutTime_CPU = $CVSCheckoutTime_User + $CVSCheckoutTime_Sys; - -my $NumFilesInCVS = 0; -my $NumDirsInCVS = 0; -if ($USESVN) { - $NumFilesInCVS = `egrep '^A' $COLog | wc -l` + 0; - $NumDirsInCVS = `sed -e 's#/[^/]*\$##' $COLog | sort | uniq | wc -l` + 0; -} else { - $NumFilesInCVS = `egrep '^U' $COLog | wc -l` + 0; - $NumDirsInCVS = `egrep '^cvs (checkout|server|update):' $COLog | wc -l` + 0; -} - -############################################################## -# -# Extract some information from the CVS history... use a hash so no duplicate -# stuff is stored. This gets the history from the previous days worth -# of cvs activity and parses it. -# -############################################################## - -# This just computes a reasonably accurate #of seconds since 2000. It doesn't -# have to be perfect as its only used for comparing date ranges within a couple -# of days. -sub ConvertToSeconds { - my ($sec, $min, $hour, $day, $mon, $yr) = @_; - my $Result = ($yr - 2000) * 12; - $Result += $mon; - $Result *= 31; - $Result += $day; - $Result *= 24; - $Result += $hour; - $Result *= 60; - $Result += $min; - $Result *= 60; - $Result += $sec; - return $Result; -} - -my (%AddedFiles, %ModifiedFiles, %RemovedFiles, %UsersCommitted, %UsersUpdated); - -if (!$NOCVSSTATS) { - if ($VERBOSE) { print "CHANGE HISTORY ANALYSIS STAGE\n"; } - - if ($USESVN) { - @SVNHistory = split /<logentry/, `svn log --non-interactive --xml --verbose -r{$DATE}:HEAD`; - # Skip very first entry because it is the XML header cruft - shift @SVNHistory; - my $Now = time(); - foreach $Record (@SVNHistory) { - my @Lines = split "\n", $Record; - my ($Author, $Date, $Revision); - # Get the date and see if its one we want to process. - my ($Year, $Month, $Day, $Hour, $Min, $Sec); - if ($Lines[3] =~ /<date>(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/){ - $Year = $1; $Month = $2; $Day = $3; $Hour = $4; $Min = $5; $Sec = $6; - } - my $Then = ConvertToSeconds($Sec, $Min, $Hour, $Day, $Month, $Year); - # Get the current date and compute when "yesterday" is. - my ($NSec, $NMin, $NHour, $NDay, $NMon, $NYear) = gmtime(); - my $Now = ConvertToSeconds( $NSec, $NMin, $NHour, $NDay, $NMon, $NYear); - if (($Now - 24*60*60) > $Then) { - next; - } - if ($Lines[1] =~ / revision="([0-9]*)">/) { - $Revision = $1; - } - if ($Lines[2] =~ /<author>([^<]*)<\/author>/) { - $Author = $1; - } - $UsersCommitted{$Author} = 1; - $Date = $Year . "-" . $Month . "-" . $Day; - $Time = $Hour . ":" . $Min . ":" . $Sec; - print "Rev: $Revision, Author: $Author, Date: $Date, Time: $Time\n"; - for ($i = 6; $i < $#Lines; $i += 2 ) { - if ($Lines[$i] =~ /^ action="(.)">([^<]*)</) { - if ($1 == "A") { - $AddedFiles{$2} = 1; - } elsif ($1 == 'D') { - $RemovedFiles{$2} = 1; - } elsif ($1 == 'M' || $1 == 'R' || $1 == 'C') { - $ModifiedFiles{$2} = 1; - } else { - print "UNMATCHABLE: $Lines[$i]\n"; - } - } - } - } - } else { - @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`; -#print join "\n", @CVSHistory; print "\n"; - - my $DateRE = '[-/:0-9 ]+\+[0-9]+'; - -# Loop over every record from the CVS history, filling in the hashes. - foreach $File (@CVSHistory) { - my ($Type, $Date, $UID, $Rev, $Filename); - if ($File =~ /([AMRUGC]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)/) { - ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5"); - } elsif ($File =~ /([W]) ($DateRE) ([^ ]+)/) { - ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", ""); - } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^ ]+)/) { - ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/"); - } else { - print "UNMATCHABLE: $File\n"; - next; - } - # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n"; - - if ($Filename =~ /^llvm/) { - if ($Type eq 'M') { # Modified - $ModifiedFiles{$Filename} = 1; - $UsersCommitted{$UID} = 1; - } elsif ($Type eq 'A') { # Added - $AddedFiles{$Filename} = 1; - $UsersCommitted{$UID} = 1; - } elsif ($Type eq 'R') { # Removed - $RemovedFiles{$Filename} = 1; - $UsersCommitted{$UID} = 1; - } else { - $UsersUpdated{$UID} = 1; - } - } - } - - my $TestError = 1; - } #$USESVN -}#!NOCVSSTATS - -my $CVSAddedFiles = join "\n", sort keys %AddedFiles; -my $CVSModifiedFiles = join "\n", sort keys %ModifiedFiles; -my $CVSRemovedFiles = join "\n", sort keys %RemovedFiles; -my $UserCommitList = join "\n", sort keys %UsersCommitted; -my $UserUpdateList = join "\n", sort keys %UsersUpdated; - -############################################################## -# -# Build the entire tree, saving build messages to the build log -# -############################################################## -if (!$NOCHECKOUT && !$NOBUILD) { +# Build the entire tree, saving build messages to the build log. Returns false +# on build failure. +sub BuildLLVM { + die "Invalid call!" unless $ConfigMode == 0; my $EXTRAFLAGS = "--enable-spec --with-objroot=."; RunLoggedCommand("(time -p $NICE ./configure $CONFIGUREARGS $EXTRAFLAGS) ", - $BuildLog, "CONFIGURE"); + $ConfigureLog, "CONFIGURE"); # Build the entire tree, capturing the output into $BuildLog - RunAppendingLoggedCommand("(time -p $NICE $MAKECMD clean)", $BuildLog, "BUILD CLEAN"); + RunAppendingLoggedCommand("($NICE $MAKECMD $MAKEOPTS clean)", $BuildLog, "BUILD CLEAN"); RunAppendingLoggedCommand("(time -p $NICE $MAKECMD $MAKEOPTS)", $BuildLog, "BUILD"); -} -############################################################## -# -# Get some statistics about the build... -# -############################################################## -#this can de done on server -#my @Linked = split '\n', `grep Linking $BuildLog`; -#my $NumExecutables = scalar(grep(/executable/, @Linked)); -#my $NumLibraries = scalar(grep(!/executable/, @Linked)); -#my $NumObjects = `grep ']\: Compiling ' $BuildLog | wc -l` + 0; - -# Get the number of lines of source code. Must be here after the build is done -# because countloc.sh uses the llvm-config script which must be built. -my $LOC = `utils/countloc.sh -topdir $LLVMSrcDir`; - -# Get the time taken by the configure script -my $ConfigTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$BuildLog"; -my $ConfigTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$BuildLog"; -my $ConfigTime = $ConfigTimeU+$ConfigTimeS; # ConfigTime = User+System -my $ConfigWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$BuildLog"; - -$ConfigTime=-1 unless $ConfigTime; -$ConfigWallTime=-1 unless $ConfigWallTime; - -my $BuildTimeU = GetRegexNum "^user", 1, "([0-9.]+)", "$BuildLog"; -my $BuildTimeS = GetRegexNum "^sys", 1, "([0-9.]+)", "$BuildLog"; -my $BuildTime = $BuildTimeU+$BuildTimeS; # BuildTime = User+System -my $BuildWallTime = GetRegexNum "^real", 1, "([0-9.]+)","$BuildLog"; - -$BuildTime=-1 unless $BuildTime; -$BuildWallTime=-1 unless $BuildWallTime; - -my $BuildError = 0, $BuildStatus = "OK"; -if ($NOBUILD) { - $BuildStatus = "Skipped by user"; -} -elsif (`grep '^$MAKECMD\[^:]*: .*Error' $BuildLog | wc -l` + 0 || - `grep '^$MAKECMD: \*\*\*.*Stop.' $BuildLog | wc -l`+0) { - $BuildStatus = "Error: compilation aborted"; - $BuildError = 1; - if( $VERBOSE) { print "\n***ERROR BUILDING TREE\n\n"; } -} -if ($BuildError) { $NODEJAGNU=1; } - -my $a_file_sizes=""; -my $o_file_sizes=""; -if (!$BuildError) { - print "Organizing size of .o and .a files\n" - if ( $VERBOSE ); - ChangeDir( "$LLVMObjDir", "Build Directory" ); - - my @dirs = ('utils', 'lib', 'tools'); - if($BUILDTYPE eq "release"){ - push @dirs, 'Release'; - } elsif($BUILDTYPE eq "release-asserts") { - push @dirs, 'Release-Asserts'; - } else { - push @dirs, 'Debug'; + if (`grep '^$MAKECMD\[^:]*: .*Error' $BuildLog | wc -l` + 0 || + `grep '^$MAKECMD: \*\*\*.*Stop.' $BuildLog | wc -l` + 0) { + return 0; } - find(sub { - $a_file_sizes .= (-s $_)." $File::Find::name $BUILDTYPE\n" if /\.a$/i; - $o_file_sizes .= (-s $_)." $File::Find::name $BUILDTYPE\n" if /\.o$/i; - }, @dirs); -} else { - $a_file_sizes="No data due to a bad build."; - $o_file_sizes="No data due to a bad build."; + return 1; } -############################################################## -# -# Running dejagnu tests -# -############################################################## -my $DejangnuTestResults=""; # String containing the results of the dejagnu -my $dejagnu_output = "$DejagnuTestsLog"; -if (!$NODEJAGNU) { - #Run the feature and regression tests, results are put into testrun.sum - #Full log in testrun.log - RunLoggedCommand("(time -p $MAKECMD $MAKEOPTS check)", $dejagnu_output, "DEJAGNU"); - - #Copy the testrun.log and testrun.sum to our webdir +# Running dejagnu tests and save results to log. +sub RunDejaGNUTests { + die "Invalid call!" unless $ConfigMode == 0; + # Run the feature and regression tests, results are put into testrun.sum and + # the full log in testrun.log. + system "rm -f test/testrun.log test/testrun.sum"; + RunLoggedCommand("(time -p $MAKECMD $MAKEOPTS check)", $DejagnuLog, "DEJAGNU"); + + # Copy the testrun.log and testrun.sum to our webdir. CopyFile("test/testrun.log", $DejagnuLog); CopyFile("test/testrun.sum", $DejagnuSum); - #can be done on server - $DejagnuTestResults = GetDejagnuTestResults($DejagnuSum, $DejagnuLog); - $unexpfail_tests = $DejagnuTestResults; -} - -#Extract time of dejagnu tests -my $DejagnuTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$dejagnu_output"; -my $DejagnuTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$dejagnu_output"; -$DejagnuTime = $DejagnuTimeU+$DejagnuTimeS; # DejagnuTime = User+System -$DejagnuWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$dejagnu_output"; -$DejagnuTestResults = - "Dejagnu skipped by user choice." unless $DejagnuTestResults; -$DejagnuTime = "0.0" unless $DejagnuTime; -$DejagnuWallTime = "0.0" unless $DejagnuWallTime; -############################################################## -# -# Get warnings from the build -# -############################################################## -if (!$NODEJAGNU) { - if ( $VERBOSE ) { print "BUILD INFORMATION COLLECTION STAGE\n"; } - my @Warn = split "\n", `egrep 'warning:|Entering dir' $BuildLog`; - my @Warnings; - my $CurDir = ""; - - foreach $Warning (@Warn) { - if ($Warning =~ m/Entering directory \`([^\`]+)\'/) { - $CurDir = $1; # Keep track of directory warning is in... - # Remove buildir prefix if included - if ($CurDir =~ m#$LLVMSrcDir/(.*)#) { $CurDir = $1; } - } else { - push @Warnings, "$CurDir/$Warning"; # Add directory to warning... - } - } - my $WarningsFile = join "\n", @Warnings; - $WarningsFile =~ s/:[0-9]+:/::/g; - - # Emit the warnings file, so we can diff... - WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n"; - my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt"; - - # Output something to stdout if something has changed - #print "ADDED WARNINGS:\n$WarningsAdded\n\n" if (length $WarningsAdded); - #print "REMOVED WARNINGS:\n$WarningsRemoved\n\n" if (length $WarningsRemoved); - - #my @TmpWarningsAdded = split "\n", $WarningsAdded; ~PJ on upgrade - #my @TmpWarningsRemoved = split "\n", $WarningsRemoved; ~PJ on upgrade - -} #endif !NODEGAGNU - -############################################################## -# -# If we built the tree successfully, run the nightly programs tests... -# -# A set of tests to run is passed in (i.e. "SingleSource" "MultiSource" -# "External") -# -############################################################## + return GetDejagnuTestResults($DejagnuSum, $DejagnuLog); +} +# Run the named tests (i.e. "SingleSource" "MultiSource" "External") sub TestDirectory { my $SubDir = shift; ChangeDir( "$LLVMTestDir/$SubDir", @@ -929,55 +557,47 @@ sub TestDirectory { my $ProgramTestLog = "$Prefix-$SubDir-ProgramTest.txt"; - # Run the programs tests... creating a report.nightly.csv file - if (!$NOTEST) { - if( $VERBOSE) { - print "$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv ". - "$TESTFLAGS TEST=nightly > $ProgramTestLog 2>&1\n"; - } - RunLoggedCommand("$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv ". - "$TESTFLAGS TEST=nightly", + # Make sure to clean things if in non-config mode. + if ($ConfigMode == 1) { + RunLoggedCommand("$MAKECMD -k $MAKEOPTS $PROGTESTOPTS clean $TESTFLAGS", $ProgramTestLog, "TEST DIRECTORY $SubDir"); - $llcbeta_options=`$MAKECMD print-llcbeta-option`; } + # Run the programs tests... creating a report.nightly.csv file. + my $LLCBetaOpts = ""; + RunLoggedCommand("$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv ". + "$TESTFLAGS TEST=nightly", + $ProgramTestLog, "TEST DIRECTORY $SubDir"); + $LLCBetaOpts = `$MAKECMD print-llcbeta-option`; + my $ProgramsTable; if (`grep '^$MAKECMD\[^:]: .*Error' $ProgramTestLog | wc -l` + 0) { - $TestError = 1; $ProgramsTable="Error running test $SubDir\n"; print "ERROR TESTING\n"; } elsif (`grep '^$MAKECMD\[^:]: .*No rule to make target' $ProgramTestLog | wc -l` + 0) { - $TestError = 1; $ProgramsTable="Makefile error running tests $SubDir!\n"; print "ERROR TESTING\n"; } else { - $TestError = 0; - # - # Create a list of the tests which were run... - # - system "egrep 'TEST-(PASS|FAIL)' < $ProgramTestLog ". - "| sort > $Prefix-$SubDir-Tests.txt"; + # Create a list of the tests which were run... + system "egrep 'TEST-(PASS|FAIL)' < $ProgramTestLog ". + "| sort > $Prefix-$SubDir-Tests.txt"; } $ProgramsTable = ReadFile "report.nightly.csv"; ChangeDir( "../../..", "Programs Test Parent Directory" ); - return ($ProgramsTable, $llcbeta_options); -} #end sub TestDirectory + return ($ProgramsTable, $LLCBetaOpts); +} -############################################################## -# -# Calling sub TestDirectory -# -############################################################## -if (!$BuildError) { - ($SingleSourceProgramsTable, $llcbeta_options) = - TestDirectory("SingleSource"); - WriteFile "$Prefix-SingleSource-Performance.txt", $SingleSourceProgramsTable; - ($MultiSourceProgramsTable, $llcbeta_options) = TestDirectory("MultiSource"); - WriteFile "$Prefix-MultiSource-Performance.txt", $MultiSourceProgramsTable; +# Run all the nightly tests and return the program tables and the list of tests, +# passes, fails, and xfails. +sub RunNightlyTest() { + ($SSProgs, $llcbeta_options) = TestDirectory("SingleSource"); + WriteFile "$Prefix-SingleSource-Performance.txt", $SSProgs; + ($MSProgs, $llcbeta_options) = TestDirectory("MultiSource"); + WriteFile "$Prefix-MultiSource-Performance.txt", $MSProgs; if ( ! $NOEXTERNALS ) { - ($ExternalProgramsTable, $llcbeta_options) = TestDirectory("External"); - WriteFile "$Prefix-External-Performance.txt", $ExternalProgramsTable; + ($ExtProgs, $llcbeta_options) = TestDirectory("External"); + WriteFile "$Prefix-External-Performance.txt", $ExtProgs; system "cat $Prefix-SingleSource-Tests.txt " . "$Prefix-MultiSource-Tests.txt ". "$Prefix-External-Tests.txt | sort > $Prefix-Tests.txt"; @@ -985,7 +605,7 @@ if (!$BuildError) { "$Prefix-MultiSource-Performance.txt ". "$Prefix-External-Performance.txt | sort > $Prefix-Performance.txt"; } else { - $ExternalProgramsTable = "External TEST STAGE SKIPPED\n"; + $ExtProgs = "External TEST STAGE SKIPPED\n"; if ( $VERBOSE ) { print "External TEST STAGE SKIPPED\n"; } @@ -997,46 +617,126 @@ if (!$BuildError) { " | sort > $Prefix-Performance.txt"; } - ############################################################## - # - # - # gathering tests added removed broken information here - # - # - ############################################################## - my $dejagnu_test_list = ReadFile "$Prefix-Tests.txt"; - my @DEJAGNU = split "\n", $dejagnu_test_list; - my ($passes, $fails, $xfails) = ""; - - if(!$NODEJAGNU) { - for ($x=0; $x<@DEJAGNU; $x++) { - if ($DEJAGNU[$x] =~ m/^PASS:/) { - $passes.="$DEJAGNU[$x]\n"; - } - elsif ($DEJAGNU[$x] =~ m/^FAIL:/) { - $fails.="$DEJAGNU[$x]\n"; - } - elsif ($DEJAGNU[$x] =~ m/^XFAIL:/) { - $xfails.="$DEJAGNU[$x]\n"; - } + # Compile passes, fails, xfails. + my $All = (ReadFile "$Prefix-Tests.txt"); + my @TestSuiteResultLines = split "\n", $All; + my ($Passes, $Fails, $XFails) = ""; + + for ($x=0; $x < @TestSuiteResultLines; $x++) { + if (@TestSuiteResultLines[$x] =~ m/^PASS:/) { + $Passes .= "$TestSuiteResultLines[$x]\n"; + } + elsif (@TestSuiteResultLines[$x] =~ m/^FAIL:/) { + $Fails .= "$TestSuiteResultLines[$x]\n"; + } + elsif (@TestSuiteResultLines[$x] =~ m/^XFAIL:/) { + $XFails .= "$TestSuiteResultLines[$x]\n"; } } -} #end if !$BuildError + return ($SSProgs, $MSProgs, $ExtProgs, $All, $Passes, $Fails, $XFails); +} + +############################################################## +# +# Initialize filenames +# +############################################################## + +if (! -d $WebDir) { + mkdir $WebDir, 0777 or die "Unable to create web directory: '$WebDir'."; + if($VERBOSE){ + warn "$WebDir did not exist; creating it.\n"; + } +} + +if ($CONFIG_PATH ne "") { + $ConfigMode = 1; + $LLVMSrcDir = GetRegex "^(.*)\\s+", `$CONFIG_PATH --src-root`; + $LLVMObjDir = GetRegex "^(.*)\\s+", `$CONFIG_PATH --obj-root`; + # FIXME: Add llvm-config hook for this? + $LLVMTestDir = $LLVMObjDir . "/projects/test-suite"; +} else { + $ConfigureLog = "$Prefix-Configure-Log.txt"; + $BuildLog = "$Prefix-Build-Log.txt"; + $COLog = "$Prefix-CVS-Log.txt"; + $DejagnuLog = "$Prefix-Dejagnu-testrun.log"; + $DejagnuSum = "$Prefix-Dejagnu-testrun.sum"; + $DejagnuLog = "$Prefix-DejagnuTests-Log.txt"; +} + +if ($VERBOSE) { + if ($CONFIG_PATH ne "") { + print "INITIALIZED (config mode)\n"; + print "WebDir = $WebDir\n"; + print "Prefix = $Prefix\n"; + print "LLVM Src = $LLVMSrcDir\n"; + print "LLVM Obj = $LLVMObjDir\n"; + print "LLVM Test = $LLVMTestDir\n"; + } else { + print "INITIALIZED\n"; + print "SVN URL = $SVNURL\n"; + print "COLog = $COLog\n"; + print "BuildDir = $BuildDir\n"; + print "WebDir = $WebDir\n"; + print "Prefix = $Prefix\n"; + print "BuildLog = $BuildLog\n"; + } +} ############################################################## # -# Getting end timestamp +# The actual NewNightlyTest logic. # ############################################################## + +$starttime = `date "+20%y-%m-%d %H:%M:%S"`; + +my $BuildError = 0, $BuildStatus = "OK"; +my $DejagnuTestResults = "Dejagnu skipped by user choice."; +if ($ConfigMode == 0) { + if (!$NOCHECKOUT) { + CheckoutSource(); + } + + # Build LLVM. + ChangeDir( $LLVMSrcDir , "llvm source directory") ; + if ($NOCHECKOUT || $NOBUILD) { + $BuildStatus = "Skipped by user"; + } else { + if (!BuildLLVM()) { + if( $VERBOSE) { print "\n***ERROR BUILDING TREE\n\n"; } + $BuildError = 1; + $BuildStatus = "Error: compilation aborted"; + $NODEJAGNU=1; + } + } + + # Run DejaGNU. + if (!$NODEJAGNU && !$BuildError) { + $DejagnuTestResults = RunDejaGNUTests(); + } +} + +# Run the llvm-test tests. +my ($SingleSourceProgramsTable, $MultiSourceProgramsTable, $ExternalProgramsTable, + $all_tests, $passes, $fails, $xfails) = ""; +if (!$NOTEST && !$BuildError) { + ($SingleSourceProgramsTable, $MultiSourceProgramsTable, $ExternalProgramsTable, + $all_tests, $passes, $fails, $xfails) = RunNightlyTest(); +} + $endtime = `date "+20%y-%m-%d %H:%M:%S"`; +# The last bit of logic is to remove the build and web dirs, after sending data +# to the server. ############################################################## # -# Place all the logs neatly into one humungous file +# Accumulate the information to send to the server. # ############################################################## + if ( $VERBOSE ) { print "PREPARING LOGS TO BE SENT TO SERVER\n"; } $machine_data = "uname: ".`uname -a`. @@ -1046,63 +746,71 @@ $machine_data = "uname: ".`uname -a`. "date: ".`date \"+20%y-%m-%d\"`. "time: ".`date +\"%H:%M:%S\"`; -my @CVS_DATA; -my $cvs_data; -@CVS_DATA = ReadFile "$COLog"; -$cvs_data = join("\n", @CVS_DATA); - -my @BUILD_DATA; -my $build_data; -@BUILD_DATA = ReadFile "$BuildLog"; -$build_data = join("\n", @BUILD_DATA); - -my (@DEJAGNU_LOG, @DEJAGNU_SUM, @DEJAGNULOG_FULL, @GCC_VERSION); -my ($dejagnutests_log ,$dejagnutests_sum, $dejagnulog_full) = ""; -my ($gcc_version, $gcc_version_long) = ""; - -$gcc_version_long=""; +# Get gcc version. +my $gcc_version_long = ""; if ($GCCPATH ne "") { - $gcc_version_long = `$GCCPATH/gcc --version`; + $gcc_version_long = `$GCCPATH/gcc --version`; } elsif ($ENV{"CC"}) { - $gcc_version_long = `$ENV{"CC"} --version`; + $gcc_version_long = `$ENV{"CC"} --version`; } else { - $gcc_version_long = `gcc --version`; + $gcc_version_long = `gcc --version`; } -@GCC_VERSION = split '\n', $gcc_version_long; -$gcc_version = $GCC_VERSION[0]; +my $gcc_version = (split '\n', $gcc_version_long)[0]; -$llvmgcc_version_long=""; +# Get llvm-gcc target triple. +my $llvmgcc_version_long = ""; if ($LLVMGCCPATH ne "") { $llvmgcc_version_long = `$LLVMGCCPATH/llvm-gcc -v 2>&1`; } else { $llvmgcc_version_long = `llvm-gcc -v 2>&1`; } -@LLVMGCC_VERSION = split '\n', $llvmgcc_version_long; -$llvmgcc_versionTarget = $LLVMGCC_VERSION[1]; -$llvmgcc_versionTarget =~ /Target: (.+)/; -$targetTriple = $1; - -if(!$BuildError){ - @DEJAGNU_LOG = ReadFile "$DejagnuLog"; - @DEJAGNU_SUM = ReadFile "$DejagnuSum"; - $dejagnutests_log = join("\n", @DEJAGNU_LOG); - $dejagnutests_sum = join("\n", @DEJAGNU_SUM); - - @DEJAGNULOG_FULL = ReadFile "$DejagnuTestsLog"; - $dejagnulog_full = join("\n", @DEJAGNULOG_FULL); +(split '\n', $llvmgcc_version_long)[1] =~ /Target: (.+)/; +my $targetTriple = $1; + +# Logs. +my ($ConfigureLogData, $BuildLogData, $DejagnuLogData, $CheckoutLogData) = ""; +if ($ConfigMode == 0) { + $ConfigureLogData = ReadFile $ConfigureLog; + $BuildLogData = ReadFile $BuildLog; + $DejagnuLogData = ReadFile $DejagnuLog; + $CheckoutLogData = ReadFile $COLog; } -############################################################## -# -# Send data via a post request -# -############################################################## +# Checkout info. +my $CheckoutTime_Wall = GetRegex "^real ([0-9.]+)", $CheckoutLogData; +my $CheckoutTime_User = GetRegex "^user ([0-9.]+)", $CheckoutLogData; +my $CheckoutTime_Sys = GetRegex "^sys ([0-9.]+)", $CheckoutLogData; +my $CheckoutTime_CPU = $CVSCheckoutTime_User + $CVSCheckoutTime_Sys; + +# Configure info. +my $ConfigTimeU = GetRegex "^user ([0-9.]+)", $ConfigureLogData; +my $ConfigTimeS = GetRegex "^sys ([0-9.]+)", $ConfigureLogData; +my $ConfigTime = $ConfigTimeU+$ConfigTimeS; # ConfigTime = User+System +my $ConfigWallTime = GetRegex "^real ([0-9.]+)",$ConfigureLogData; +$ConfigTime=-1 unless $ConfigTime; +$ConfigWallTime=-1 unless $ConfigWallTime; + +# Build info. +my $BuildTimeU = GetRegex "^user ([0-9.]+)", $BuildLogData; +my $BuildTimeS = GetRegex "^sys ([0-9.]+)", $BuildLogData; +my $BuildTime = $BuildTimeU+$BuildTimeS; # BuildTime = User+System +my $BuildWallTime = GetRegex "^real ([0-9.]+)", $BuildLogData; +$BuildTime=-1 unless $BuildTime; +$BuildWallTime=-1 unless $BuildWallTime; + +# DejaGNU info. +my $DejagnuTimeU = GetRegex "^user ([0-9.]+)", $DejagnuLogData; +my $DejagnuTimeS = GetRegex "^sys ([0-9.]+)", $DejagnuLogData; +$DejagnuTime = $DejagnuTimeU+$DejagnuTimeS; # DejagnuTime = User+System +$DejagnuWallTime = GetRegex "^real ([0-9.]+)", $DejagnuLogData; +$DejagnuTime = "0.0" unless $DejagnuTime; +$DejagnuWallTime = "0.0" unless $DejagnuWallTime; if ( $VERBOSE ) { print "SEND THE DATA VIA THE POST REQUEST\n"; } my %hash_of_data = ( 'machine_data' => $machine_data, - 'build_data' => $build_data, + 'build_data' => $ConfigureLogData . $BuildLogData, 'gcc_version' => $gcc_version, 'nickname' => $nickname, 'dejagnutime_wall' => $DejagnuWallTime, @@ -1113,35 +821,37 @@ my %hash_of_data = ( 'configtime_cpu'=> $ConfigTime, 'buildtime_wall' => $BuildWallTime, 'buildtime_cpu' => $BuildTime, - 'warnings' => $WarningsFile, - 'cvsusercommitlist' => $UserCommitList, - 'cvsuserupdatelist' => $UserUpdateList, - 'cvsaddedfiles' => $CVSAddedFiles, - 'cvsmodifiedfiles' => $CVSModifiedFiles, - 'cvsremovedfiles' => $CVSRemovedFiles, - 'lines_of_code' => $LOC, - 'cvs_file_count' => $NumFilesInCVS, - 'cvs_dir_count' => $NumDirsInCVS, 'buildstatus' => $BuildStatus, 'singlesource_programstable' => $SingleSourceProgramsTable, 'multisource_programstable' => $MultiSourceProgramsTable, 'externalsource_programstable' => $ExternalProgramsTable, - 'llcbeta_options' => $multisource_llcbeta_options, - 'warnings_removed' => $WarningsRemoved, - 'warnings_added' => $WarningsAdded, + 'llcbeta_options' => $llcbeta_options, 'passing_tests' => $passes, 'expfail_tests' => $xfails, 'unexpfail_tests' => $fails, - 'all_tests' => $dejagnu_test_list, - 'new_tests' => "", - 'removed_tests' => "", + 'all_tests' => $all_tests, 'dejagnutests_results' => $DejagnuTestResults, - 'dejagnutests_log' => $dejagnulog_full, + 'dejagnutests_log' => $DejagnuLogData, 'starttime' => $starttime, 'endtime' => $endtime, - 'o_file_sizes' => $o_file_sizes, - 'a_file_sizes' => $a_file_sizes, - 'target_triple' => $targetTriple + 'target_triple' => $targetTriple, + + # Unused, but left around for backwards compatability. + 'warnings' => "", + 'cvsusercommitlist' => "", + 'cvsuserupdatelist' => "", + 'cvsaddedfiles' => "", + 'cvsmodifiedfiles' => "", + 'cvsremovedfiles' => "", + 'lines_of_code' => "", + 'cvs_file_count' => 0, + 'cvs_dir_count' => 0, + 'warnings_removed' => "", + 'warnings_added' => "", + 'new_tests' => "", + 'removed_tests' => "", + 'o_file_sizes' => "", + 'a_file_sizes' => "" ); if ($SUBMIT || !($SUBMITAUX eq "")) { @@ -1156,7 +866,7 @@ if ($SUBMIT || !($SUBMITAUX eq "")) { ############################################################## # -# Remove the cvs tree... +# Remove the source tree... # ############################################################## system ( "$NICE rm -rf $BuildDir") diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index 84a647bea309..ff348e8e706d 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/utils/TableGen/AsmWriterEmitter.cpp @@ -538,6 +538,29 @@ FindUniqueOperandCommands(std::vector<std::string> &UniqueOperandCommands, } +static void UnescapeString(std::string &Str) { + for (unsigned i = 0; i != Str.size(); ++i) { + if (Str[i] == '\\' && i != Str.size()-1) { + switch (Str[i+1]) { + default: continue; // Don't execute the code after the switch. + case 'a': Str[i] = '\a'; break; + case 'b': Str[i] = '\b'; break; + case 'e': Str[i] = 27; break; + case 'f': Str[i] = '\f'; break; + case 'n': Str[i] = '\n'; break; + case 'r': Str[i] = '\r'; break; + case 't': Str[i] = '\t'; break; + case 'v': Str[i] = '\v'; break; + case '"': Str[i] = '\"'; break; + case '\'': Str[i] = '\''; break; + case '\\': Str[i] = '\\'; break; + } + // Nuke the second character. + Str.erase(Str.begin()+i+1); + } + } +} + /// EmitPrintInstruction - Generate the code for the "printInstruction" method /// implementation. void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { diff --git a/utils/TableGen/ClangDiagnosticsEmitter.cpp b/utils/TableGen/ClangDiagnosticsEmitter.cpp index c127afd77050..6f1080eb5eb2 100644 --- a/utils/TableGen/ClangDiagnosticsEmitter.cpp +++ b/utils/TableGen/ClangDiagnosticsEmitter.cpp @@ -52,15 +52,12 @@ void ClangDiagsDefsEmitter::run(raw_ostream &OS) { // Description string. OS << ", \""; - std::string S = R.getValueAsString("Text"); - EscapeString(S); - OS << S << "\""; + OS.write_escaped(R.getValueAsString("Text")) << '"'; // Warning associated with the diagnostic. if (DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group"))) { - S = DI->getDef()->getValueAsString("GroupName"); - EscapeString(S); - OS << ", \"" << S << "\""; + OS << ", \""; + OS.write_escaped(DI->getDef()->getValueAsString("GroupName")) << '"'; } else { OS << ", 0"; } @@ -151,11 +148,10 @@ void ClangDiagGroupsEmitter::run(raw_ostream &OS) { OS << "\n#ifdef GET_DIAG_TABLE\n"; for (std::map<std::string, GroupInfo>::iterator I = DiagsInGroup.begin(), E = DiagsInGroup.end(); I != E; ++I) { - std::string S = I->first; - EscapeString(S); // Group option string. - OS << " { \"" << S << "\"," - << std::string(MaxLen-I->first.size()+1, ' '); + OS << " { \""; + OS.write_escaped(I->first) << "\"," + << std::string(MaxLen-I->first.size()+1, ' '); // Diagnostics in the group. if (I->second.DiagsInGroup.empty()) diff --git a/utils/TableGen/CodeGenDAGPatterns.h b/utils/TableGen/CodeGenDAGPatterns.h index 9b53ecc5db95..398764b30a09 100644 --- a/utils/TableGen/CodeGenDAGPatterns.h +++ b/utils/TableGen/CodeGenDAGPatterns.h @@ -584,6 +584,8 @@ public: return intrinsic_wo_chain_sdnode; } + bool hasTargetIntrinsics() { return !TgtIntrinsics.empty(); } + private: void ParseNodeInfo(); void ParseNodeTransforms(); diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index dcf64e444c89..bbb8a18eec2c 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -2067,8 +2067,16 @@ void DAGISelEmitter::EmitInstructionSelector(raw_ostream &OS) { << " errs() << \"Cannot yet select: \";\n" << " unsigned iid = cast<ConstantSDNode>(N.getOperand(" << "N.getOperand(0).getValueType() == MVT::Other))->getZExtValue();\n" - << " llvm_report_error(\"Cannot yet select: intrinsic %\" +\n" - << "Intrinsic::getName((Intrinsic::ID)iid));\n" + << " if (iid < Intrinsic::num_intrinsics)\n" + << " llvm_report_error(\"Cannot yet select: intrinsic %\" + " + << "Intrinsic::getName((Intrinsic::ID)iid));\n"; + if (CGP.hasTargetIntrinsics()) { + OS << " else if (const TargetIntrinsicInfo *tii = TM.getIntrinsicInfo())\n" + << " llvm_report_error(Twine(\"Cannot yet select: target intrinsic " + << "%\") + tii->getName(iid));\n"; + } + OS << " else\n" + << " llvm_report_error(\"Cannot yet select: invalid intrinsic\");\n" << "}\n\n"; } diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index 06afaf73a02e..f5d1139bb62e 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -56,8 +56,14 @@ const char * SinkOptionName = "AutoGeneratedSinkOption"; /// Id - An 'identity' function object. struct Id { - template<typename T> - void operator()(const T&) const { + template<typename T0> + void operator()(const T0&) const { + } + template<typename T0, typename T1> + void operator()(const T0&, const T1&) const { + } + template<typename T0, typename T1, typename T2> + void operator()(const T0&, const T1&, const T2&) const { } }; @@ -81,16 +87,24 @@ const DagInit& InitPtrToDag(const Init* ptr) { return val; } +const std::string GetOperatorName(const DagInit* D) { + return D->getOperator()->getAsString(); +} + +const std::string GetOperatorName(const DagInit& D) { + return GetOperatorName(&D); +} + // checkNumberOfArguments - Ensure that the number of args in d is // greater than or equal to min_arguments, otherwise throw an exception. void checkNumberOfArguments (const DagInit* d, unsigned min_arguments) { if (!d || d->getNumArgs() < min_arguments) - throw d->getOperator()->getAsString() + ": too few arguments!"; + throw GetOperatorName(d) + ": too few arguments!"; } // isDagEmpty - is this DAG marked with an empty marker? bool isDagEmpty (const DagInit* d) { - return d->getOperator()->getAsString() == "empty_dag_marker"; + return GetOperatorName(d) == "empty_dag_marker"; } // EscapeVariableName - Escape commas and other symbols not allowed @@ -132,6 +146,18 @@ void checkedIncrement(I& P, I E, S ErrorString) { throw ErrorString; } +// apply is needed because C++'s syntax doesn't let us construct a function +// object and call it in the same statement. +template<typename F, typename T0> +void apply(F Fun, T0& Arg0) { + return Fun(Arg0); +} + +template<typename F, typename T0, typename T1> +void apply(F Fun, T0& Arg0, T1& Arg1) { + return Fun(Arg0, Arg1); +} + //===----------------------------------------------------------------------===// /// Back-end specific code @@ -143,6 +169,10 @@ namespace OptionType { enum OptionType { Alias, Switch, Parameter, ParameterList, Prefix, PrefixList}; + bool IsAlias(OptionType t) { + return (t == Alias); + } + bool IsList (OptionType t) { return (t == ParameterList || t == PrefixList); } @@ -231,12 +261,12 @@ struct OptionDescription { bool isReallyHidden() const; void setReallyHidden(); - bool isParameter() const - { return OptionType::IsParameter(this->Type); } - bool isSwitch() const { return OptionType::IsSwitch(this->Type); } + bool isParameter() const + { return OptionType::IsParameter(this->Type); } + bool isList() const { return OptionType::IsList(this->Type); } @@ -258,7 +288,7 @@ void OptionDescription::Merge (const OptionDescription& other) } bool OptionDescription::isAlias() const { - return Type == OptionType::Alias; + return OptionType::IsAlias(this->Type); } bool OptionDescription::isMultiVal() const { @@ -352,6 +382,14 @@ public: /// FindOption - exception-throwing wrapper for find(). const OptionDescription& FindOption(const std::string& OptName) const; + // Wrappers for FindOption that throw an exception in case the option has a + // wrong type. + const OptionDescription& FindSwitch(const std::string& OptName) const; + const OptionDescription& FindParameter(const std::string& OptName) const; + const OptionDescription& FindList(const std::string& OptName) const; + const OptionDescription& + FindListOrParameter(const std::string& OptName) const; + /// insertDescription - Insert new OptionDescription into /// OptionDescriptions list void InsertDescription (const OptionDescription& o); @@ -363,8 +401,7 @@ public: }; const OptionDescription& -OptionDescriptions::FindOption(const std::string& OptName) const -{ +OptionDescriptions::FindOption(const std::string& OptName) const { const_iterator I = Descriptions.find(OptName); if (I != Descriptions.end()) return I->second; @@ -372,8 +409,40 @@ OptionDescriptions::FindOption(const std::string& OptName) const throw OptName + ": no such option!"; } -void OptionDescriptions::InsertDescription (const OptionDescription& o) -{ +const OptionDescription& +OptionDescriptions::FindSwitch(const std::string& OptName) const { + const OptionDescription& OptDesc = this->FindOption(OptName); + if (!OptDesc.isSwitch()) + throw OptName + ": incorrect option type - should be a switch!"; + return OptDesc; +} + +const OptionDescription& +OptionDescriptions::FindList(const std::string& OptName) const { + const OptionDescription& OptDesc = this->FindOption(OptName); + if (!OptDesc.isList()) + throw OptName + ": incorrect option type - should be a list!"; + return OptDesc; +} + +const OptionDescription& +OptionDescriptions::FindParameter(const std::string& OptName) const { + const OptionDescription& OptDesc = this->FindOption(OptName); + if (!OptDesc.isParameter()) + throw OptName + ": incorrect option type - should be a parameter!"; + return OptDesc; +} + +const OptionDescription& +OptionDescriptions::FindListOrParameter(const std::string& OptName) const { + const OptionDescription& OptDesc = this->FindOption(OptName); + if (!OptDesc.isList() && !OptDesc.isParameter()) + throw OptName + + ": incorrect option type - should be a list or parameter!"; + return OptDesc; +} + +void OptionDescriptions::InsertDescription (const OptionDescription& o) { container_type::iterator I = Descriptions.find(o.Name); if (I != Descriptions.end()) { OptionDescription& D = I->second; @@ -409,7 +478,7 @@ public: /// handler. void operator() (Init* i) { const DagInit& property = InitPtrToDag(i); - const std::string& property_name = property.getOperator()->getAsString(); + const std::string& property_name = GetOperatorName(property); typename HandlerMap::iterator method = Handlers_.find(property_name); if (method != Handlers_.end()) { @@ -558,7 +627,7 @@ public: checkNumberOfArguments(&d, 1); const OptionType::OptionType Type = - stringToOptionType(d.getOperator()->getAsString()); + stringToOptionType(GetOperatorName(d)); const std::string& Name = InitPtrToString(d.getArg(0)); OptionDescription OD(Type, Name); @@ -678,7 +747,7 @@ private: checkNumberOfArguments(d, 1); Init* Case = d->getArg(0); if (typeid(*Case) != typeid(DagInit) || - static_cast<DagInit*>(Case)->getOperator()->getAsString() != "case") + GetOperatorName(static_cast<DagInit*>(Case)) != "case") throw std::string("The argument to (actions) should be a 'case' construct!"); toolDesc_.Actions = Case; @@ -775,11 +844,17 @@ void FillInEdgeVector(RecordVector::const_iterator B, /// CalculatePriority - Calculate the priority of this plugin. int CalculatePriority(RecordVector::const_iterator B, RecordVector::const_iterator E) { - int total = 0; - for (; B!=E; ++B) { - total += static_cast<int>((*B)->getValueAsInt("priority")); + int priority = 0; + + if (B != E) { + priority = static_cast<int>((*B)->getValueAsInt("priority")); + + if (++B != E) + throw std::string("More than one 'PluginPriority' instance found: " + "most probably an error!"); } - return total; + + return priority; } /// NotInGraph - Helper function object for FilterNotInGraph. @@ -874,22 +949,60 @@ void TypecheckGraph (const RecordVector& EdgeVector, /// WalkCase - Walks the 'case' expression DAG and invokes /// TestCallback on every test, and StatementCallback on every /// statement. Handles 'case' nesting, but not the 'and' and 'or' -/// combinators. -// TODO: Re-implement EmitCaseConstructHandler on top of this function? +/// combinators (that is, they are passed directly to TestCallback). +/// TestCallback must have type 'void TestCallback(const DagInit*, unsigned +/// IndentLevel, bool FirstTest)'. +/// StatementCallback must have type 'void StatementCallback(const Init*, +/// unsigned IndentLevel)'. template <typename F1, typename F2> -void WalkCase(Init* Case, F1 TestCallback, F2 StatementCallback) { +void WalkCase(const Init* Case, F1 TestCallback, F2 StatementCallback, + unsigned IndentLevel = 0) +{ const DagInit& d = InitPtrToDag(Case); + + // Error checks. + if (GetOperatorName(d) != "case") + throw std::string("WalkCase should be invoked only on 'case' expressions!"); + + if (d.getNumArgs() < 2) + throw "There should be at least one clause in the 'case' expression:\n" + + d.getAsString(); + + // Main loop. bool even = false; + const unsigned numArgs = d.getNumArgs(); + unsigned i = 1; for (DagInit::const_arg_iterator B = d.arg_begin(), E = d.arg_end(); B != E; ++B) { Init* arg = *B; - if (even && dynamic_cast<DagInit*>(arg) - && static_cast<DagInit*>(arg)->getOperator()->getAsString() == "case") - WalkCase(arg, TestCallback, StatementCallback); - else if (!even) - TestCallback(arg); + + if (!even) + { + // Handle test. + const DagInit& Test = InitPtrToDag(arg); + + if (GetOperatorName(Test) == "default" && (i+1 != numArgs)) + throw std::string("The 'default' clause should be the last in the" + "'case' construct!"); + if (i == numArgs) + throw "Case construct handler: no corresponding action " + "found for the test " + Test.getAsString() + '!'; + + TestCallback(&Test, IndentLevel, (i == 1)); + } else - StatementCallback(arg); + { + if (dynamic_cast<DagInit*>(arg) + && GetOperatorName(static_cast<DagInit*>(arg)) == "case") { + // Nested 'case'. + WalkCase(arg, TestCallback, StatementCallback, IndentLevel + Indent1); + } + + // Handle statement. + StatementCallback(arg, IndentLevel); + } + + ++i; even = !even; } } @@ -901,7 +1014,7 @@ class ExtractOptionNames { void processDag(const Init* Statement) { const DagInit& Stmt = InitPtrToDag(Statement); - const std::string& ActionName = Stmt.getOperator()->getAsString(); + const std::string& ActionName = GetOperatorName(Stmt); if (ActionName == "forward" || ActionName == "forward_as" || ActionName == "unpack_values" || ActionName == "switch_on" || ActionName == "parameter_equals" || ActionName == "element_in_list" || @@ -932,6 +1045,13 @@ public: this->processDag(Statement); } } + + void operator()(const DagInit* Test, unsigned, bool) { + this->operator()(Test); + } + void operator()(const Init* Statement, unsigned) { + this->operator()(Statement); + } }; /// CheckForSuperfluousOptions - Check that there are no side @@ -990,51 +1110,137 @@ bool EmitCaseTest0Args(const std::string& TestName, raw_ostream& O) { return false; } +/// EmitListTest - Helper function used by EmitCaseTest1ArgList(). +template <typename F> +void EmitListTest(const ListInit& L, const char* LogicOp, + F Callback, raw_ostream& O) +{ + // This is a lot like EmitLogicalOperationTest, but works on ListInits instead + // of Dags... + bool isFirst = true; + for (ListInit::const_iterator B = L.begin(), E = L.end(); B != E; ++B) { + if (isFirst) + isFirst = false; + else + O << " || "; + Callback(InitPtrToString(*B), O); + } +} + +// Callbacks for use with EmitListTest. -/// EmitCaseTest1Arg - Helper function used by EmitCaseConstructHandler(). -bool EmitCaseTest1Arg(const std::string& TestName, - const DagInit& d, - const OptionDescriptions& OptDescs, - raw_ostream& O) { - checkNumberOfArguments(&d, 1); +class EmitSwitchOn { + const OptionDescriptions& OptDescs_; +public: + EmitSwitchOn(const OptionDescriptions& OptDescs) : OptDescs_(OptDescs) + {} + + void operator()(const std::string& OptName, raw_ostream& O) const { + const OptionDescription& OptDesc = OptDescs_.FindSwitch(OptName); + O << OptDesc.GenVariableName(); + } +}; + +class EmitEmptyTest { + bool EmitNegate_; + const OptionDescriptions& OptDescs_; +public: + EmitEmptyTest(bool EmitNegate, const OptionDescriptions& OptDescs) + : EmitNegate_(EmitNegate), OptDescs_(OptDescs) + {} + + void operator()(const std::string& OptName, raw_ostream& O) const { + const char* Neg = (EmitNegate_ ? "!" : ""); + if (OptName == "o") { + O << Neg << "OutputFilename.empty()"; + } + else { + const OptionDescription& OptDesc = OptDescs_.FindListOrParameter(OptName); + O << Neg << OptDesc.GenVariableName() << ".empty()"; + } + } +}; + + +/// EmitCaseTest1ArgList - Helper function used by EmitCaseTest1Arg(); +bool EmitCaseTest1ArgList(const std::string& TestName, + const DagInit& d, + const OptionDescriptions& OptDescs, + raw_ostream& O) { + const ListInit& L = *static_cast<ListInit*>(d.getArg(0)); + + if (TestName == "any_switch_on") { + EmitListTest(L, "||", EmitSwitchOn(OptDescs), O); + return true; + } + else if (TestName == "switch_on") { + EmitListTest(L, "&&", EmitSwitchOn(OptDescs), O); + return true; + } + else if (TestName == "any_not_empty") { + EmitListTest(L, "||", EmitEmptyTest(true, OptDescs), O); + return true; + } + else if (TestName == "any_empty") { + EmitListTest(L, "||", EmitEmptyTest(false, OptDescs), O); + return true; + } + else if (TestName == "not_empty") { + EmitListTest(L, "&&", EmitEmptyTest(true, OptDescs), O); + return true; + } + else if (TestName == "empty") { + EmitListTest(L, "&&", EmitEmptyTest(false, OptDescs), O); + return true; + } + + return false; +} + +/// EmitCaseTest1ArgStr - Helper function used by EmitCaseTest1Arg(); +bool EmitCaseTest1ArgStr(const std::string& TestName, + const DagInit& d, + const OptionDescriptions& OptDescs, + raw_ostream& O) { const std::string& OptName = InitPtrToString(d.getArg(0)); if (TestName == "switch_on") { - const OptionDescription& OptDesc = OptDescs.FindOption(OptName); - if (!OptDesc.isSwitch()) - throw OptName + ": incorrect option type - should be a switch!"; - O << OptDesc.GenVariableName(); + apply(EmitSwitchOn(OptDescs), OptName, O); return true; - } else if (TestName == "input_languages_contain") { + } + else if (TestName == "input_languages_contain") { O << "InLangs.count(\"" << OptName << "\") != 0"; return true; - } else if (TestName == "in_language") { + } + else if (TestName == "in_language") { // This works only for single-argument Tool::GenerateAction. Join // tools can process several files in different languages simultaneously. // TODO: make this work with Edge::Weight (if possible). O << "LangMap.GetLanguage(inFile) == \"" << OptName << '\"'; return true; - } else if (TestName == "not_empty" || TestName == "empty") { - const char* Test = (TestName == "empty") ? "" : "!"; - - if (OptName == "o") { - O << Test << "OutputFilename.empty()"; - return true; - } - else { - const OptionDescription& OptDesc = OptDescs.FindOption(OptName); - if (OptDesc.isSwitch()) - throw OptName - + ": incorrect option type - should be a list or parameter!"; - O << Test << OptDesc.GenVariableName() << ".empty()"; - return true; - } + } + else if (TestName == "not_empty" || TestName == "empty") { + bool EmitNegate = (TestName == "not_empty"); + apply(EmitEmptyTest(EmitNegate, OptDescs), OptName, O); + return true; } return false; } +/// EmitCaseTest1Arg - Helper function used by EmitCaseConstructHandler(); +bool EmitCaseTest1Arg(const std::string& TestName, + const DagInit& d, + const OptionDescriptions& OptDescs, + raw_ostream& O) { + checkNumberOfArguments(&d, 1); + if (typeid(*d.getArg(0)) == typeid(ListInit)) + return EmitCaseTest1ArgList(TestName, d, OptDescs, O); + else + return EmitCaseTest1ArgStr(TestName, d, OptDescs, O); +} + /// EmitCaseTest2Args - Helper function used by EmitCaseConstructHandler(). bool EmitCaseTest2Args(const std::string& TestName, const DagInit& d, @@ -1044,17 +1250,14 @@ bool EmitCaseTest2Args(const std::string& TestName, checkNumberOfArguments(&d, 2); const std::string& OptName = InitPtrToString(d.getArg(0)); const std::string& OptArg = InitPtrToString(d.getArg(1)); - const OptionDescription& OptDesc = OptDescs.FindOption(OptName); if (TestName == "parameter_equals") { - if (!OptDesc.isParameter()) - throw OptName + ": incorrect option type - should be a parameter!"; + const OptionDescription& OptDesc = OptDescs.FindParameter(OptName); O << OptDesc.GenVariableName() << " == \"" << OptArg << "\""; return true; } else if (TestName == "element_in_list") { - if (!OptDesc.isList()) - throw OptName + ": incorrect option type - should be a list!"; + const OptionDescription& OptDesc = OptDescs.FindList(OptName); const std::string& VarName = OptDesc.GenVariableName(); O << "std::find(" << VarName << ".begin(),\n"; O.indent(IndentLevel + Indent1) @@ -1106,7 +1309,7 @@ void EmitLogicalNot(const DagInit& d, unsigned IndentLevel, void EmitCaseTest(const DagInit& d, unsigned IndentLevel, const OptionDescriptions& OptDescs, raw_ostream& O) { - const std::string& TestName = d.getOperator()->getAsString(); + const std::string& TestName = GetOperatorName(d); if (TestName == "and") EmitLogicalOperationTest(d, "&&", IndentLevel, OptDescs, O); @@ -1124,59 +1327,79 @@ void EmitCaseTest(const DagInit& d, unsigned IndentLevel, throw TestName + ": unknown edge property!"; } -// Emit code that handles the 'case' construct. -// Takes a function object that should emit code for every case clause. -// Callback's type is -// void F(Init* Statement, unsigned IndentLevel, raw_ostream& O). -template <typename F> -void EmitCaseConstructHandler(const Init* Dag, unsigned IndentLevel, - F Callback, bool EmitElseIf, - const OptionDescriptions& OptDescs, - raw_ostream& O) { - const DagInit* d = &InitPtrToDag(Dag); - if (d->getOperator()->getAsString() != "case") - throw std::string("EmitCaseConstructHandler should be invoked" - " only on 'case' expressions!"); - unsigned numArgs = d->getNumArgs(); - if (d->getNumArgs() < 2) - throw "There should be at least one clause in the 'case' expression:\n" - + d->getAsString(); +/// EmitCaseTestCallback - Callback used by EmitCaseConstructHandler. +class EmitCaseTestCallback { + bool EmitElseIf_; + const OptionDescriptions& OptDescs_; + raw_ostream& O_; +public: - for (unsigned i = 0; i != numArgs; ++i) { - const DagInit& Test = InitPtrToDag(d->getArg(i)); + EmitCaseTestCallback(bool EmitElseIf, + const OptionDescriptions& OptDescs, raw_ostream& O) + : EmitElseIf_(EmitElseIf), OptDescs_(OptDescs), O_(O) + {} - // Emit the test. - if (Test.getOperator()->getAsString() == "default") { - if (i+2 != numArgs) - throw std::string("The 'default' clause should be the last in the" - "'case' construct!"); - O.indent(IndentLevel) << "else {\n"; + void operator()(const DagInit* Test, unsigned IndentLevel, bool FirstTest) + { + if (GetOperatorName(Test) == "default") { + O_.indent(IndentLevel) << "else {\n"; } else { - O.indent(IndentLevel) << ((i != 0 && EmitElseIf) ? "else if (" : "if ("); - EmitCaseTest(Test, IndentLevel, OptDescs, O); - O << ") {\n"; + O_.indent(IndentLevel) + << ((!FirstTest && EmitElseIf_) ? "else if (" : "if ("); + EmitCaseTest(*Test, IndentLevel, OptDescs_, O_); + O_ << ") {\n"; } + } +}; - // Emit the corresponding statement. - ++i; - if (i == numArgs) - throw "Case construct handler: no corresponding action " - "found for the test " + Test.getAsString() + '!'; - - Init* arg = d->getArg(i); - const DagInit* nd = dynamic_cast<DagInit*>(arg); - if (nd && (nd->getOperator()->getAsString() == "case")) { - // Handle the nested 'case'. - EmitCaseConstructHandler(nd, (IndentLevel + Indent1), - Callback, EmitElseIf, OptDescs, O); - } - else { - Callback(arg, (IndentLevel + Indent1), O); +/// EmitCaseStatementCallback - Callback used by EmitCaseConstructHandler. +template <typename F> +class EmitCaseStatementCallback { + F Callback_; + raw_ostream& O_; +public: + + EmitCaseStatementCallback(F Callback, raw_ostream& O) + : Callback_(Callback), O_(O) + {} + + void operator() (const Init* Statement, unsigned IndentLevel) { + + // Ignore nested 'case' DAG. + if (!(dynamic_cast<const DagInit*>(Statement) && + GetOperatorName(static_cast<const DagInit*>(Statement)) == "case")) { + if (typeid(*Statement) == typeid(ListInit)) { + const ListInit& DagList = *static_cast<const ListInit*>(Statement); + for (ListInit::const_iterator B = DagList.begin(), E = DagList.end(); + B != E; ++B) + Callback_(*B, (IndentLevel + Indent1), O_); + } + else { + Callback_(Statement, (IndentLevel + Indent1), O_); + } } - O.indent(IndentLevel) << "}\n"; + O_.indent(IndentLevel) << "}\n"; } + +}; + +/// EmitCaseConstructHandler - Emit code that handles the 'case' +/// construct. Takes a function object that should emit code for every case +/// clause. Implemented on top of WalkCase. +/// Callback's type is void F(Init* Statement, unsigned IndentLevel, +/// raw_ostream& O). +/// EmitElseIf parameter controls the type of condition that is emitted ('if +/// (..) {..} else if (..) {} .. else {..}' vs. 'if (..) {..} if(..) {..} +/// .. else {..}'). +template <typename F> +void EmitCaseConstructHandler(const Init* Case, unsigned IndentLevel, + F Callback, bool EmitElseIf, + const OptionDescriptions& OptDescs, + raw_ostream& O) { + WalkCase(Case, EmitCaseTestCallback(EmitElseIf, OptDescs, O), + EmitCaseStatementCallback<F>(Callback, O), IndentLevel); } /// TokenizeCmdline - converts from "$CALL(HookName, 'Arg1', 'Arg2')/path" to @@ -1474,17 +1697,40 @@ void EmitForwardOptionPropertyHandlingCode (const OptionDescription& D, } } -/// EmitActionHandler - Emit code that handles actions. Used by -/// EmitGenerateActionMethod() as an argument to -/// EmitCaseConstructHandler(). -class EmitActionHandler { +/// ActionHandlingCallbackBase - Base class of EmitActionHandlersCallback and +/// EmitPreprocessOptionsCallback. +struct ActionHandlingCallbackBase { + + void onErrorDag(const DagInit& d, + unsigned IndentLevel, raw_ostream& O) const + { + O.indent(IndentLevel) + << "throw std::runtime_error(\"" << + (d.getNumArgs() >= 1 ? InitPtrToString(d.getArg(0)) + : "Unknown error!") + << "\");\n"; + } + + void onWarningDag(const DagInit& d, + unsigned IndentLevel, raw_ostream& O) const + { + checkNumberOfArguments(&d, 1); + O.indent(IndentLevel) << "llvm::errs() << \"" + << InitPtrToString(d.getArg(0)) << "\";\n"; + } + +}; + +/// EmitActionHandlersCallback - Emit code that handles actions. Used by +/// EmitGenerateActionMethod() as an argument to EmitCaseConstructHandler(). +class EmitActionHandlersCallback : ActionHandlingCallbackBase { const OptionDescriptions& OptDescs; void processActionDag(const Init* Statement, unsigned IndentLevel, raw_ostream& O) const { const DagInit& Dag = InitPtrToDag(Statement); - const std::string& ActionName = Dag.getOperator()->getAsString(); + const std::string& ActionName = GetOperatorName(Dag); if (ActionName == "append_cmd") { checkNumberOfArguments(&Dag, 1); @@ -1497,10 +1743,10 @@ class EmitActionHandler { O.indent(IndentLevel) << "vec.push_back(\"" << *B << "\");\n"; } else if (ActionName == "error") { - O.indent(IndentLevel) << "throw std::runtime_error(\"" << - (Dag.getNumArgs() >= 1 ? InitPtrToString(Dag.getArg(0)) - : "Unknown error!") - << "\");\n"; + this->onErrorDag(Dag, IndentLevel, O); + } + else if (ActionName == "warning") { + this->onWarningDag(Dag, IndentLevel, O); } else if (ActionName == "forward") { checkNumberOfArguments(&Dag, 1); @@ -1554,21 +1800,13 @@ class EmitActionHandler { } } public: - EmitActionHandler(const OptionDescriptions& OD) + EmitActionHandlersCallback(const OptionDescriptions& OD) : OptDescs(OD) {} - void operator()(const Init* Statement, unsigned IndentLevel, - raw_ostream& O) const + void operator()(const Init* Statement, + unsigned IndentLevel, raw_ostream& O) const { - if (typeid(*Statement) == typeid(ListInit)) { - const ListInit& DagList = *static_cast<const ListInit*>(Statement); - for (ListInit::const_iterator B = DagList.begin(), E = DagList.end(); - B != E; ++B) - this->processActionDag(*B, IndentLevel, O); - } - else { - this->processActionDag(Statement, IndentLevel, O); - } + this->processActionDag(Statement, IndentLevel, O); } }; @@ -1593,9 +1831,20 @@ public: {} void operator()(const Init* CmdLine) { + // Ignore nested 'case' DAG. + if (typeid(*CmdLine) == typeid(DagInit)) + return; + if (IsOutFileIndexCheckRequiredStr(CmdLine)) *ret_ = true; } + + void operator()(const DagInit* Test, unsigned, bool) { + this->operator()(Test); + } + void operator()(const Init* Statement, unsigned) { + this->operator()(Statement); + } }; bool IsOutFileIndexCheckRequiredCase (Init* CmdLine) { @@ -1652,7 +1901,7 @@ void EmitGenerateActionMethod (const ToolDescription& D, // For every understood option, emit handling code. if (D.Actions) - EmitCaseConstructHandler(D.Actions, Indent2, EmitActionHandler(OptDescs), + EmitCaseConstructHandler(D.Actions, Indent2, EmitActionHandlersCallback(OptDescs), false, OptDescs, O); O << '\n'; @@ -1870,10 +2119,93 @@ void EmitOptionDefinitions (const OptionDescriptions& descs, O << '\n'; } -/// EmitPopulateLanguageMap - Emit the PopulateLanguageMap() function. +/// EmitPreprocessOptionsCallback - Helper function passed to +/// EmitCaseConstructHandler() by EmitPreprocessOptions(). +class EmitPreprocessOptionsCallback : ActionHandlingCallbackBase { + const OptionDescriptions& OptDescs_; + + void onUnsetOption(Init* i, unsigned IndentLevel, raw_ostream& O) { + const std::string& OptName = InitPtrToString(i); + const OptionDescription& OptDesc = OptDescs_.FindOption(OptName); + + if (OptDesc.isSwitch()) { + O.indent(IndentLevel) << OptDesc.GenVariableName() << " = false;\n"; + } + else if (OptDesc.isParameter()) { + O.indent(IndentLevel) << OptDesc.GenVariableName() << " = \"\";\n"; + } + else if (OptDesc.isList()) { + O.indent(IndentLevel) << OptDesc.GenVariableName() << ".clear();\n"; + } + else { + throw "Can't apply 'unset_option' to alias option '" + OptName + "'"; + } + } + + void processDag(const Init* I, unsigned IndentLevel, raw_ostream& O) + { + const DagInit& d = InitPtrToDag(I); + const std::string& OpName = GetOperatorName(d); + + if (OpName == "warning") { + this->onWarningDag(d, IndentLevel, O); + } + else if (OpName == "error") { + this->onWarningDag(d, IndentLevel, O); + } + else if (OpName == "unset_option") { + checkNumberOfArguments(&d, 1); + Init* I = d.getArg(0); + if (typeid(*I) == typeid(ListInit)) { + const ListInit& DagList = *static_cast<const ListInit*>(I); + for (ListInit::const_iterator B = DagList.begin(), E = DagList.end(); + B != E; ++B) + this->onUnsetOption(*B, IndentLevel, O); + } + else { + this->onUnsetOption(I, IndentLevel, O); + } + } + else { + throw "Unknown operator in the option preprocessor: '" + OpName + "'!" + "\nOnly 'warning', 'error' and 'unset_option' are allowed."; + } + } + +public: + + void operator()(const Init* I, unsigned IndentLevel, raw_ostream& O) { + this->processDag(I, IndentLevel, O); + } + + EmitPreprocessOptionsCallback(const OptionDescriptions& OptDescs) + : OptDescs_(OptDescs) + {} +}; + +/// EmitPreprocessOptions - Emit the PreprocessOptionsLocal() function. +void EmitPreprocessOptions (const RecordKeeper& Records, + const OptionDescriptions& OptDecs, raw_ostream& O) +{ + O << "void PreprocessOptionsLocal() {\n"; + + const RecordVector& OptionPreprocessors = + Records.getAllDerivedDefinitions("OptionPreprocessor"); + + for (RecordVector::const_iterator B = OptionPreprocessors.begin(), + E = OptionPreprocessors.end(); B!=E; ++B) { + DagInit* Case = (*B)->getValueAsDag("preprocessor"); + EmitCaseConstructHandler(Case, Indent1, + EmitPreprocessOptionsCallback(OptDecs), + false, OptDecs, O); + } + + O << "}\n\n"; +} + +/// EmitPopulateLanguageMap - Emit the PopulateLanguageMapLocal() function. void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O) { - // Generate code O << "void PopulateLanguageMapLocal(LanguageMap& langMap) {\n"; // Get the relevant field out of RecordKeeper @@ -1907,7 +2239,7 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O) void IncDecWeight (const Init* i, unsigned IndentLevel, raw_ostream& O) { const DagInit& d = InitPtrToDag(i); - const std::string& OpName = d.getOperator()->getAsString(); + const std::string& OpName = GetOperatorName(d); if (OpName == "inc_weight") { O.indent(IndentLevel) << "ret += "; @@ -1916,17 +2248,16 @@ void IncDecWeight (const Init* i, unsigned IndentLevel, O.indent(IndentLevel) << "ret -= "; } else if (OpName == "error") { - O.indent(IndentLevel) - << "throw std::runtime_error(\"" << - (d.getNumArgs() >= 1 ? InitPtrToString(d.getArg(0)) - : "Unknown error!") - << "\");\n"; + checkNumberOfArguments(&d, 1); + O.indent(IndentLevel) << "throw std::runtime_error(\"" + << InitPtrToString(d.getArg(0)) + << "\");\n"; return; } - - else - throw "Unknown operator in edge properties list: " + OpName + '!' + + else { + throw "Unknown operator in edge properties list: '" + OpName + "'!" "\nOnly 'inc_weight', 'dec_weight' and 'error' are allowed."; + } if (d.getNumArgs() > 0) O << InitPtrToInt(d.getArg(0)) << ";\n"; @@ -1975,7 +2306,7 @@ void EmitEdgeClasses (const RecordVector& EdgeVector, } } -/// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraph() +/// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraphLocal() /// function. void EmitPopulateCompilationGraph (const RecordVector& EdgeVector, const ToolDescriptions& ToolDescs, @@ -2024,6 +2355,11 @@ public: void operator()(const Init* CmdLine) { StrVector cmds; + + // Ignore nested 'case' DAG. + if (typeid(*CmdLine) == typeid(DagInit)) + return; + TokenizeCmdline(InitPtrToString(CmdLine), cmds); for (StrVector::const_iterator B = cmds.begin(), E = cmds.end(); B != E; ++B) { @@ -2053,6 +2389,13 @@ public: } } } + + void operator()(const DagInit* Test, unsigned, bool) { + this->operator()(Test); + } + void operator()(const Init* Statement, unsigned) { + this->operator()(Statement); + } }; /// FillInHookNames - Actually extract the hook names from all command @@ -2104,6 +2447,8 @@ void EmitRegisterPlugin(int Priority, raw_ostream& O) { O << "struct Plugin : public llvmc::BasePlugin {\n\n"; O.indent(Indent1) << "int Priority() const { return " << Priority << "; }\n\n"; + O.indent(Indent1) << "void PreprocessOptions() const\n"; + O.indent(Indent1) << "{ PreprocessOptionsLocal(); }\n\n"; O.indent(Indent1) << "void PopulateLanguageMap(LanguageMap& langMap) const\n"; O.indent(Indent1) << "{ PopulateLanguageMapLocal(langMap); }\n\n"; O.indent(Indent1) @@ -2123,7 +2468,8 @@ void EmitIncludes(raw_ostream& O) { << "#include \"llvm/CompilerDriver/Tool.h\"\n\n" << "#include \"llvm/ADT/StringExtras.h\"\n" - << "#include \"llvm/Support/CommandLine.h\"\n\n" + << "#include \"llvm/Support/CommandLine.h\"\n" + << "#include \"llvm/Support/raw_ostream.h\"\n\n" << "#include <cstdlib>\n" << "#include <stdexcept>\n\n" @@ -2223,8 +2569,11 @@ void EmitPluginCode(const PluginData& Data, raw_ostream& O) { O << "namespace {\n\n"; - // Emit PopulateLanguageMap() function - // (a language map maps from file extensions to language names). + // Emit PreprocessOptionsLocal() function. + EmitPreprocessOptions(Records, Data.OptDescs, O); + + // Emit PopulateLanguageMapLocal() function + // (language map maps from file extensions to language names). EmitPopulateLanguageMap(Records, O); // Emit Tool classes. @@ -2235,7 +2584,7 @@ void EmitPluginCode(const PluginData& Data, raw_ostream& O) { // Emit Edge# classes. EmitEdgeClasses(Data.Edges, Data.OptDescs, O); - // Emit PopulateCompilationGraph() function. + // Emit PopulateCompilationGraphLocal() function. EmitPopulateCompilationGraph(Data.Edges, Data.ToolDescs, O); // Emit code for plugin registration. diff --git a/utils/TableGen/LLVMCConfigurationEmitter.h b/utils/TableGen/LLVMCConfigurationEmitter.h index 347f6f1cc555..b37b83fb9255 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.h +++ b/utils/TableGen/LLVMCConfigurationEmitter.h @@ -21,9 +21,8 @@ namespace llvm { /// LLVMCConfigurationEmitter - TableGen backend that generates /// configuration code for LLVMC. class LLVMCConfigurationEmitter : public TableGenBackend { - RecordKeeper &Records; public: - explicit LLVMCConfigurationEmitter(RecordKeeper &R) : Records(R) {} + explicit LLVMCConfigurationEmitter(RecordKeeper&) {} // run - Output the asmwriter, returning true on failure. void run(raw_ostream &o); diff --git a/utils/TableGen/StringToOffsetTable.h b/utils/TableGen/StringToOffsetTable.h index d9d7cf485efd..ac9422c5d72d 100644 --- a/utils/TableGen/StringToOffsetTable.h +++ b/utils/TableGen/StringToOffsetTable.h @@ -10,9 +10,10 @@ #ifndef TBLGEN_STRING_TO_OFFSET_TABLE_H #define TBLGEN_STRING_TO_OFFSET_TABLE_H +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringMap.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/raw_ostream.h" namespace llvm { @@ -38,9 +39,13 @@ public: } void EmitString(raw_ostream &O) { + // Escape the string. + SmallString<256> Str; + raw_svector_ostream(Str).write_escaped(AggregateString); + AggregateString = Str.str(); + O << " \""; unsigned CharsPrinted = 0; - EscapeString(AggregateString); for (unsigned i = 0, e = AggregateString.size(); i != e; ++i) { if (CharsPrinted > 70) { O << "\"\n \""; diff --git a/utils/buildit/GNUmakefile b/utils/buildit/GNUmakefile index e3b334a045d1..997188333c1b 100644 --- a/utils/buildit/GNUmakefile +++ b/utils/buildit/GNUmakefile @@ -59,7 +59,7 @@ endif # NOTE : Always put version numbers at the end because they are optional. install: $(OBJROOT) $(SYMROOT) $(DSTROOT) cd $(OBJROOT) && \ - $(SRC)/build_llvm "$(RC_ARCHS)" "$(TARGETS)" \ + $(SRC)/utils/buildit/build_llvm "$(RC_ARCHS)" "$(TARGETS)" \ $(SRC) $(PREFIX) $(DSTROOT) $(SYMROOT) \ $(LLVM_ASSERTIONS) $(LLVM_OPTIMIZED) \ $(RC_ProjectSourceVersion) $(RC_ProjectSourceSubversion) diff --git a/utils/buildit/build_llvm b/utils/buildit/build_llvm index 91fbe15be473..2bdb208237df 100755 --- a/utils/buildit/build_llvm +++ b/utils/buildit/build_llvm @@ -82,6 +82,10 @@ SRC_DIR=$DIR/src rm -rf $SRC_DIR || exit 1 mkdir $SRC_DIR || exit 1 ln -s $ORIG_SRC_DIR/* $SRC_DIR/ || exit 1 +# We can't use the top-level Makefile as-is. Remove the soft link: +rm $SRC_DIR/Makefile || exit 1 +# Now create our own by editing the top-level Makefile, deleting every line marked "Apple-style": +sed -e '/[Aa]pple-style/d' -e '/include.*GNUmakefile/d' $ORIG_SRC_DIR/Makefile > $SRC_DIR/Makefile || exit 1 # Build the LLVM tree universal. mkdir -p $DIR/obj-llvm || exit 1 diff --git a/utils/emacs/tablegen-mode.el b/utils/emacs/tablegen-mode.el index 08f7f252c681..833c16c599d4 100644 --- a/utils/emacs/tablegen-mode.el +++ b/utils/emacs/tablegen-mode.el @@ -112,6 +112,8 @@ ) (set-syntax-table tablegen-mode-syntax-table) + (make-local-variable 'comment-start) + (setq comment-start "//") (run-hooks 'tablegen-mode-hook)) ; Finally, this permits the user to ; customize the mode with a hook. diff --git a/utils/lit/LitConfig.py b/utils/lit/LitConfig.py index 4fb0ccc09353..c334109e1dee 100644 --- a/utils/lit/LitConfig.py +++ b/utils/lit/LitConfig.py @@ -29,6 +29,7 @@ class LitConfig: self.noExecute = noExecute self.debug = debug self.isWindows = bool(isWindows) + self.bashPath = None self.numErrors = 0 self.numWarnings = 0 @@ -41,6 +42,27 @@ class LitConfig: mustExist = True, config = config) + def getBashPath(self): + """getBashPath - Get the path to 'bash'""" + import os, Util + + if self.bashPath is not None: + return self.bashPath + + self.bashPath = Util.which('bash', os.pathsep.join(self.path)) + if self.bashPath is None: + # Check some known paths. + for path in ('/bin/bash', '/usr/bin/bash'): + if os.path.exists(path): + self.bashPath = path + break + + if self.bashPath is None: + self.warning("Unable to find 'bash', running Tcl tests internally.") + self.bashPath = '' + + return self.bashPath + def _write_message(self, kind, message): import inspect, os, sys diff --git a/utils/lit/TestFormats.py b/utils/lit/TestFormats.py index 61bdb185355f..7e638b47f4d8 100644 --- a/utils/lit/TestFormats.py +++ b/utils/lit/TestFormats.py @@ -53,6 +53,10 @@ class GoogleTest(object): def execute(self, test, litConfig): testPath,testName = os.path.split(test.getSourcePath()) + if not os.path.exists(testPath): + # Handle GTest typed tests, whose name includes a '/'. + testPath, namePrefix = os.path.split(testPath) + testName = os.path.join(namePrefix, testName) cmd = [testPath, '--gtest_filter=' + testName] out, err, exitCode = TestRunner.executeCommand(cmd) diff --git a/utils/lit/TestRunner.py b/utils/lit/TestRunner.py index 7b549ac1c615..34e828bf9609 100644 --- a/utils/lit/TestRunner.py +++ b/utils/lit/TestRunner.py @@ -237,7 +237,9 @@ def executeTclScriptInternal(test, litConfig, tmpBase, commands, cwd): for c in cmds[1:]: cmd = ShUtil.Seq(cmd, '&&', c) - if litConfig.useTclAsSh: + # FIXME: This is lame, we shouldn't need bash. See PR5240. + bashPath = litConfig.getBashPath() + if litConfig.useTclAsSh and bashPath: script = tmpBase + '.script' # Write script file @@ -252,7 +254,7 @@ def executeTclScriptInternal(test, litConfig, tmpBase, commands, cwd): print >>sys.stdout return '', '', 0 - command = ['/bin/bash', script] + command = [litConfig.getBashPath(), script] out,err,exitCode = executeCommand(command, cwd=cwd, env=test.config.environment) |