2006-05-28 12:21:40 +08:00
|
|
|
# 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 } {
|
2006-05-31 07:07:17 +08:00
|
|
|
global subdir llvmtoolsdir llvmlibsdir objdir srcdir objroot srcroot
|
|
|
|
set timeout 30
|
|
|
|
set path [file join $objdir $subdir]
|
2008-04-24 06:41:53 +08:00
|
|
|
set llc [file join $llvmtoolsdir llc ]
|
2006-05-31 07:07:17 +08:00
|
|
|
set llvmas [file join $llvmtoolsdir llvm-as ]
|
|
|
|
set llvmdis [file join $llvmtoolsdir llvm-dis ]
|
2006-05-28 12:21:40 +08:00
|
|
|
|
2006-05-31 07:07:17 +08:00
|
|
|
#Make Output Directory if it does not exist already
|
|
|
|
if { [file exists path] } {
|
|
|
|
cd $path
|
|
|
|
} else {
|
|
|
|
file mkdir $path
|
|
|
|
cd $path
|
|
|
|
}
|
|
|
|
|
|
|
|
file mkdir Output
|
2006-05-28 12:21:40 +08:00
|
|
|
|
2006-05-31 07:07:17 +08:00
|
|
|
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 testname [file rootname $filename]
|
|
|
|
set bytecode [file join Output $filename.bc]
|
2006-05-28 12:21:40 +08:00
|
|
|
|
2007-04-12 01:56:23 +08:00
|
|
|
# Note that the stderr for llvm-as, etc. must be redirected to /dev/null
|
|
|
|
# because otherwise exec will see the msgs and return 1 even though they
|
|
|
|
# are only warnings. If real errors are generated on stderr then llvm-as
|
|
|
|
# will return a non-zero retval anyway so we're good.
|
|
|
|
|
|
|
|
# Scan the test file to see if there's an XFAIL file. If so, don't run it
|
|
|
|
set retval [ catch {
|
|
|
|
exec -keepnewline grep XFAIL $test 2>/dev/null } msg ]
|
|
|
|
if { $retval == 0 } {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
# Run llvm-as/llvm-dis
|
|
|
|
set pipeline llvm-as|llvm-dis
|
2007-04-12 01:56:23 +08:00
|
|
|
set retval [ catch {
|
2009-08-25 23:45:44 +08:00
|
|
|
exec -keepnewline $llvmas < $test -o - | $llvmdis -o $assembly 2>/dev/null } msg ]
|
2007-04-12 01:56:23 +08:00
|
|
|
|
|
|
|
if { $retval != 0 } {
|
|
|
|
fail "$test: $pipeline returned $retval\n$msg"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
# Build bytecode for llvm2cpp input
|
2006-05-31 07:07:17 +08:00
|
|
|
set retval [ catch {
|
2007-04-12 01:56:23 +08:00
|
|
|
exec -keepnewline $llvmas < $assembly > $bytecode 2>/dev/null } msg ]
|
2006-05-28 12:21:40 +08:00
|
|
|
|
2006-05-31 07:07:17 +08:00
|
|
|
if { $retval != 0 } {
|
2007-04-12 01:56:23 +08:00
|
|
|
fail "$test: llvm-as returned $retval\n$msg"
|
2006-05-31 07:07:17 +08:00
|
|
|
continue
|
|
|
|
}
|
2006-05-28 12:21:40 +08:00
|
|
|
|
2006-05-31 07:07:17 +08:00
|
|
|
set retval [ catch {
|
2009-08-25 23:45:44 +08:00
|
|
|
exec -keepnewline $llc -march=cpp -o $generated < $bytecode 2>/dev/null } msg]
|
2006-05-28 12:21:40 +08:00
|
|
|
|
2006-05-31 07:07:17 +08:00
|
|
|
if { $retval != 0 } {
|
|
|
|
fail "$test: llvm2cpp returned $retval\n$msg"
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
set retval [ catch {
|
2009-08-18 08:40:33 +08:00
|
|
|
exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$llvmlibsdir -lLLVMCore -lLLVMSupport -lLLVMSystem -lstdc++ } msg ]
|
2006-05-31 07:07:17 +08:00
|
|
|
if { $retval != 0 } {
|
|
|
|
fail "$test: gcc returned $retval\n$msg"
|
|
|
|
continue
|
|
|
|
}
|
2006-05-28 12:21:40 +08:00
|
|
|
|
2006-05-31 07:07:17 +08:00
|
|
|
set retval [ catch { exec -keepnewline $executable > $output } msg ]
|
|
|
|
if { $retval != 0 } {
|
|
|
|
set execname [file tail $executable]
|
|
|
|
fail "$test: $execname returned $retval:\n$msg"
|
|
|
|
continue
|
|
|
|
}
|
2006-05-28 12:21:40 +08:00
|
|
|
|
2006-05-31 07:07:17 +08:00
|
|
|
set retval [ catch {
|
|
|
|
exec -keepnewline diff $assembly $output } msg ]
|
2006-05-28 12:21:40 +08:00
|
|
|
|
2006-05-31 07:07:17 +08:00
|
|
|
if { $retval != 0 } {
|
|
|
|
fail "$test: diff returned $retval:\n$msg"
|
|
|
|
continue
|
2006-05-28 12:21:40 +08:00
|
|
|
}
|
2006-05-31 07:07:17 +08:00
|
|
|
pass "$test"
|
|
|
|
}
|
2006-05-28 12:21:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|