Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 1 | # This file defines a tcl proc to assist with testing the llvm2cpp. There are |
| 2 | # no llvm2cpp specific test cases. Instead, it utilizes all the existing test |
| 3 | # cases and makes sure llvm2cpp can run them. The basic idea is that we find |
| 4 | # all the LLVM Assembly (*.ll) files, run llvm2cpp on them to generate a C++ |
| 5 | # program, compile those programs, run them and see if what they produce matches |
| 6 | # the original input to llvm2cpp. |
| 7 | |
| 8 | proc llvm2cpp-test { files } { |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 9 | global subdir llvmtoolsdir llvmlibsdir objdir srcdir objroot srcroot |
| 10 | set timeout 30 |
| 11 | set path [file join $objdir $subdir] |
Anton Korobeynikov | 488fe31 | 2008-04-23 22:41:53 +0000 | [diff] [blame] | 12 | set llc [file join $llvmtoolsdir llc ] |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 13 | set llvmas [file join $llvmtoolsdir llvm-as ] |
| 14 | set llvmdis [file join $llvmtoolsdir llvm-dis ] |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 15 | |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 16 | #Make Output Directory if it does not exist already |
| 17 | if { [file exists path] } { |
| 18 | cd $path |
| 19 | } else { |
| 20 | file mkdir $path |
| 21 | cd $path |
| 22 | } |
| 23 | |
| 24 | file mkdir Output |
| 25 | |
| 26 | foreach test $files { |
| 27 | |
| 28 | set filename [file tail $test] |
| 29 | set generated [file join Output $filename.cpp] |
| 30 | set executable [file join Output $filename.exe] |
| 31 | set output [file join Output $filename.gen] |
| 32 | set assembly [file join Output $filename.asm] |
| 33 | set testname [file rootname $filename] |
| 34 | set bytecode [file join Output $filename.bc] |
| 35 | |
Reid Spencer | 0aac889 | 2007-04-11 17:56:23 +0000 | [diff] [blame] | 36 | # Note that the stderr for llvm-as, etc. must be redirected to /dev/null |
| 37 | # because otherwise exec will see the msgs and return 1 even though they |
| 38 | # are only warnings. If real errors are generated on stderr then llvm-as |
| 39 | # will return a non-zero retval anyway so we're good. |
| 40 | |
| 41 | # Scan the test file to see if there's an XFAIL file. If so, don't run it |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 42 | set retval [ catch { |
Reid Spencer | 0aac889 | 2007-04-11 17:56:23 +0000 | [diff] [blame] | 43 | exec -keepnewline grep XFAIL $test 2>/dev/null } msg ] |
| 44 | if { $retval == 0 } { |
| 45 | continue; |
| 46 | } |
| 47 | |
Tanya Lattner | 6f729d6 | 2008-03-25 04:26:08 +0000 | [diff] [blame] | 48 | # Run llvm-as/llvm-dis |
| 49 | set pipeline llvm-as|llvm-dis |
Reid Spencer | 0aac889 | 2007-04-11 17:56:23 +0000 | [diff] [blame] | 50 | set retval [ catch { |
Dan Gohman | 47dd94e | 2009-08-25 15:45:44 +0000 | [diff] [blame] | 51 | exec -keepnewline $llvmas < $test -o - | $llvmdis -o $assembly 2>/dev/null } msg ] |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 52 | |
| 53 | if { $retval != 0 } { |
Reid Spencer | 0aac889 | 2007-04-11 17:56:23 +0000 | [diff] [blame] | 54 | fail "$test: $pipeline returned $retval\n$msg" |
| 55 | continue |
| 56 | } |
| 57 | |
| 58 | # Build bytecode for llvm2cpp input |
| 59 | set retval [ catch { |
| 60 | exec -keepnewline $llvmas < $assembly > $bytecode 2>/dev/null } msg ] |
| 61 | |
| 62 | if { $retval != 0 } { |
| 63 | fail "$test: llvm-as returned $retval\n$msg" |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 64 | continue |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 65 | } |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 66 | |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 67 | set retval [ catch { |
Dan Gohman | 47dd94e | 2009-08-25 15:45:44 +0000 | [diff] [blame] | 68 | exec -keepnewline $llc -march=cpp -o $generated < $bytecode 2>/dev/null } msg] |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 69 | |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 70 | if { $retval != 0 } { |
| 71 | fail "$test: llvm2cpp returned $retval\n$msg" |
| 72 | continue |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 73 | } |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 74 | |
| 75 | set retval [ catch { |
Anton Korobeynikov | e55db74 | 2009-08-18 00:40:33 +0000 | [diff] [blame] | 76 | exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$llvmlibsdir -lLLVMCore -lLLVMSupport -lLLVMSystem -lstdc++ } msg ] |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 77 | if { $retval != 0 } { |
| 78 | fail "$test: gcc returned $retval\n$msg" |
| 79 | continue |
| 80 | } |
| 81 | |
| 82 | set retval [ catch { exec -keepnewline $executable > $output } msg ] |
| 83 | if { $retval != 0 } { |
| 84 | set execname [file tail $executable] |
| 85 | fail "$test: $execname returned $retval:\n$msg" |
| 86 | continue |
| 87 | } |
| 88 | |
| 89 | set retval [ catch { |
| 90 | exec -keepnewline diff $assembly $output } msg ] |
| 91 | |
| 92 | if { $retval != 0 } { |
| 93 | fail "$test: diff returned $retval:\n$msg" |
| 94 | continue |
| 95 | } |
| 96 | pass "$test" |
| 97 | } |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |