Fix gcc command line options after LLVMCore and LLVMbzip2 became archive
[oota-llvm.git] / test / lib / llvm2cpp.exp
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 } {
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 ]
15
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 
46     }
47
48     set retval [ catch { 
49       exec -keepnewline $llvm2cpp -f -o $generated < $test 2>/dev/null } msg]
50
51     if { $retval != 0 } {
52       fail "$test: llvm2cpp returned $retval\n$msg"
53       continue
54     }
55
56     set retval [ catch { 
57       exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$llvmlibsdir -lLLVMCore -lLLVMSupport -lLLVMbzip2.o -lLLVMSystem -lstdc++ } msg ] 
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   }
79 }
80
81