2b954dfe1d08876f2c5a96781b04c2a99dee2546
[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 #  if { $env(LLVM_RUNLLVM2CPP_TEST) == 1 } {
10     global subdir llvmtoolsdir llvmlibsdir objdir srcdir objroot srcroot 
11     set timeout 30
12     set path [file join $objdir $subdir]
13     set llvm2cpp [file join $llvmtoolsdir llvm2cpp ]
14     set llvmas [file join $llvmtoolsdir llvm-as ]
15     set llvmdis [file join $llvmtoolsdir llvm-dis ]
16
17     #Make Output Directory if it does not exist already
18     if { [file exists path] } {
19         cd $path
20     } else {
21         file mkdir $path
22         cd $path
23     }
24     
25     file mkdir Output
26  
27     foreach test $files {
28         
29       set filename [file tail $test]
30       set generated [file join Output $filename.cpp]
31       set executable [file join Output $filename.exe]
32       set output [file join Output $filename.gen]
33       set assembly [file join Output $filename.asm]
34       set testname [file rootname $filename]
35
36       set retval [ catch { 
37         exec -keepnewline $llvmas $test -o - | $llvmdis -f -o $assembly } msg ] 
38
39       if { $retval != 0 } {
40         fail "$test: llvm-as/llvm-dis returned $retval\n$msg"
41         continue 
42       }
43
44       set retval [ catch { 
45         exec -keepnewline $llvm2cpp -f -o $generated < $test } msg]
46
47       if { $retval != 0 } {
48         fail "$test: llvm2cpp returned $retval\n$msg"
49         continue
50       }
51
52       set retval [ catch { 
53         exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$llvmlibsdir $llvmlibsdir/LLVMCore.o -lLLVMSupport $llvmlibsdir/LLVMbzip2.o -lLLVMSystem -lstdc++ } msg ] 
54       if { $retval != 0 } {
55         fail "$test: gcc returned $retval\n$msg"
56         continue
57       }
58
59       set retval [ catch { exec -keepnewline $executable > $output } msg ]
60       if { $retval != 0 } {
61         set execname [file tail $executable]
62         fail "$test: $execname returned $retval:\n$msg"
63         continue
64       } 
65
66       set retval [ catch { 
67         exec -keepnewline diff $assembly $output } msg ]
68
69       if { $retval != 0 } {
70         fail "$test: diff returned $retval:\n$msg"
71         continue
72       }
73       pass "$test"
74     }
75 #  }
76 }
77
78