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] |
| 12 | set llvm2cpp [file join $llvmtoolsdir llvm2cpp ] |
| 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 | |
| 36 | # Note that the stderr for llvm-as must be redirected to /dev/null because |
| 37 | # otherwise exec will see the msgs and return 1 even though they are only |
| 38 | # warnings. If real errors are generated on stderr then llvm-as will return |
| 39 | # a non-zero retval anyway so we're good. |
| 40 | set retval [ catch { |
| 41 | exec -keepnewline $llvmas $test -o - | $llvmdis -f -o $assembly 2>/dev/null } msg ] |
| 42 | |
| 43 | if { $retval != 0 } { |
| 44 | fail "$test: llvm-as/llvm-dis returned $retval\n$msg" |
| 45 | continue |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 46 | } |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 47 | |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 48 | set retval [ catch { |
| 49 | exec -keepnewline $llvm2cpp -f -o $generated < $test 2>/dev/null } msg] |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 50 | |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 51 | if { $retval != 0 } { |
| 52 | fail "$test: llvm2cpp returned $retval\n$msg" |
| 53 | continue |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 54 | } |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 55 | |
| 56 | set retval [ catch { |
Reid Spencer | ea60e20 | 2006-06-01 07:23:32 +0000 | [diff] [blame] | 57 | exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$llvmlibsdir -lLLVMCore -lLLVMSupport -lLLVMbzip2 -lLLVMSystem -lstdc++ } msg ] |
Reid Spencer | 226368f | 2006-05-30 23:07:17 +0000 | [diff] [blame] | 58 | if { $retval != 0 } { |
| 59 | fail "$test: gcc returned $retval\n$msg" |
| 60 | continue |
| 61 | } |
| 62 | |
| 63 | set retval [ catch { exec -keepnewline $executable > $output } msg ] |
| 64 | if { $retval != 0 } { |
| 65 | set execname [file tail $executable] |
| 66 | fail "$test: $execname returned $retval:\n$msg" |
| 67 | continue |
| 68 | } |
| 69 | |
| 70 | set retval [ catch { |
| 71 | exec -keepnewline diff $assembly $output } msg ] |
| 72 | |
| 73 | if { $retval != 0 } { |
| 74 | fail "$test: diff returned $retval:\n$msg" |
| 75 | continue |
| 76 | } |
| 77 | pass "$test" |
| 78 | } |
Reid Spencer | 15d4059 | 2006-05-28 04:21:40 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |