aboutsummaryrefslogtreecommitdiff
path: root/test/lib/llvm2cpp.exp
blob: 8bd1044882e6e259a5677bd7936cde8b1499b0a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# This file defines a tcl proc to assist with testing the llvm2cpp. There are
# no llvm2cpp specific test cases. Instead, it utilizes all the existing test
# cases and makes sure llvm2cpp can run them. The basic idea is that we find
# all the LLVM Assembly (*.ll) files, run llvm2cpp on them to generate a C++
# program, compile those programs, run them and see if what they produce matches
# the original input to llvm2cpp.

proc llvm2cpp-test { files } {
#  if { $env(LLVM_RUNLLVM2CPP_TEST) == 1 } {
    global subdir llvmtoolsdir llvmlibsdir objdir srcdir objroot srcroot 
    set timeout 30
    set path [file join $objdir $subdir]
    set llvm2cpp [file join $llvmtoolsdir llvm2cpp ]
    set llvmas [file join $llvmtoolsdir llvm-as ]
    set llvmdis [file join $llvmtoolsdir llvm-dis ]

    #Make Output Directory if it does not exist already
    if { [file exists path] } {
	cd $path
    } else {
	file mkdir $path
	cd $path
    }
    
    file mkdir Output
 
    foreach test $files {
	
      set filename [file tail $test]
      set generated [file join Output $filename.cpp]
      set executable [file join Output $filename.exe]
      set output [file join Output $filename.gen]
      set assembly [file join Output $filename.asm]

      set retval [ catch { 
        exec -keepnewline $llvmas $test -o - | $llvmdis -f -o $assembly } msg ] 

      if { $retval != 0 } {
        fail "$test: llvm-as/llvm-dis returned $retval\n$msg"
        continue 
      }

      set retval [ catch { 
        exec -keepnewline $llvm2cpp -f -o $generated $test } msg]

      if { $retval != 0 } {
        fail "$test: llvm2cpp returned $retval\n$msg"
        continue
      }

      set retval [ catch { 
        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 ] 
      if { $retval != 0 } {
        fail "$test: gcc returned $retval\n$msg"
        continue
      }

      set retval [ catch { 
        exec -keepnewline $executable > $output } msg ]

      if { $retval != 0 } {
        fail "$test: $filename returned $retval\n$msg"
        continue
      } 

      set retval [ catch { 
        exec -keepnewline diff -u $assembly $generated } msg ]

      if { $retval != 0 } {
        fail "$test: diff returned $retval\n$msg"
        continue
      }
      pass "$test"
    }
#  }
}