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.
8 proc llvm2cpp-test { files } {
9 global subdir llvmtoolsdir llvmlibsdir objdir srcdir objroot srcroot
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 ]
16 #Make Output Directory if it does not exist already
17 if { [file exists path] } {
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]
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.
41 exec -keepnewline $llvmas $test -o - | $llvmdis -f -o $assembly 2>/dev/null } msg ]
44 fail "$test: llvm-as/llvm-dis returned $retval\n$msg"
49 exec -keepnewline $llvm2cpp -f -o $generated < $test 2>/dev/null } msg]
52 fail "$test: llvm2cpp returned $retval\n$msg"
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 ]
59 fail "$test: gcc returned $retval\n$msg"
63 set retval [ catch { exec -keepnewline $executable > $output } msg ]
65 set execname [file tail $executable]
66 fail "$test: $execname returned $retval:\n$msg"
71 exec -keepnewline diff $assembly $output } msg ]
74 fail "$test: diff returned $retval:\n$msg"