diff --git a/Makefile b/Makefile index 25ae845f..f1e3ad78 100644 --- a/Makefile +++ b/Makefile @@ -58,11 +58,7 @@ LDFLAGS= ifeq ($(ARCH_OS),Linux) # try to link everything statically under Linux (including libstdc++) so # that the binaries we generate will be portable across distributions... - ifeq ($(ARCH_TYPE),x86_64) - LDFLAGS=-static -L/usr/lib/gcc/x86_64-linux-gnu/4.4 - else - LDFLAGS=-L/usr/lib/gcc/i686-redhat-linux/4.6.0 - endif + LDFLAGS=-static endif LEX=flex diff --git a/bitcode2cpp.py b/bitcode2cpp.py index 8c09b216..aaeb1f29 100755 --- a/bitcode2cpp.py +++ b/bitcode2cpp.py @@ -26,17 +26,21 @@ if platform.system() == 'Windows' or string.find(platform.system(), "CYGWIN_NT") try: as_out=subprocess.Popen([llvm_as, "-", "-o", "-"], stdout=subprocess.PIPE) except IOError: - print >> sys.stderr, "Couldn't open " + src + sys.stderr.write("Couldn't open " + src) sys.exit(1) -print "unsigned char builtins_bitcode_" + target + "[] = {" -for line in as_out.stdout.readlines(): - length = length + len(line) - for c in line: - print ord(c) - print ", " -print " 0 };\n\n" -print "int builtins_bitcode_" + target + "_length = " + str(length) + ";\n" +width = 16; +sys.stdout.write("unsigned char builtins_bitcode_" + target + "[] = {\n") + +data = as_out.stdout.read() +for i in range(0, len(data), 1): + sys.stdout.write("0x%0.2X, " % ord(data[i:i+1])) + + if i%width == (width-1): + sys.stdout.write("\n") + +sys.stdout.write("0x00 };\n\n") +sys.stdout.write("int builtins_bitcode_" + target + "_length = " + str(i+1) + ";\n") as_out.wait() diff --git a/run_tests.py b/run_tests.py index 923265d4..e2ea66f9 100755 --- a/run_tests.py +++ b/run_tests.py @@ -12,12 +12,14 @@ import re import signal import random import string -import mutex import subprocess import shlex import platform import tempfile +# This script is affected by http://bugs.python.org/issue5261 on OSX 10.5 Leopard +# git history has a workaround for that issue. + is_windows = (platform.system() == 'Windows' or 'CYGWIN_NT' in platform.system()) @@ -45,20 +47,25 @@ if not is_windows: (options, args) = parser.parse_args() if not is_windows and options.valgrind: - valgrind_cmd = "valgrind " + valgrind_exe = "valgrind " else: - valgrind_cmd = "" + valgrind_exe = "" + +if not is_windows: + ispc_exe = "./ispc" +else: + ispc_exe = "Release/ispc.exe" is_generic_target = options.target.find("generic-") != -1 if is_generic_target and options.include_file == None: if options.target == "generic-4": - print "No generics #include specified; using examples/intrinsics/sse4.h" + sys.stderr.write("No generics #include specified; using examples/intrinsics/sse4.h\n") options.include_file = "examples/intrinsics/sse4.h" elif options.target == "generic-8": - print "No generics #include specified and no default available for \"generic-8\" target."; + sys.stderr.write("No generics #include specified and no default available for \"generic-8\" target.\n") sys.exit(1) elif options.target == "generic-16": - print "No generics #include specified; using examples/intrinsics/generic-16.h" + sys.stderr.write("No generics #include specified; using examples/intrinsics/generic-16.h\n") options.include_file = "examples/intrinsics/generic-16.h" if options.compiler_exe == None: @@ -88,17 +95,11 @@ if (options.random): # counter total_tests = 0 -# We'd like to use the Lock class from the multiprocessing package to -# serialize accesses to finished_tests_counter. Unfortunately, the version of -# python that ships with OSX 10.5 has this bug: -# http://bugs.python.org/issue5261. Therefore, we use the (deprecated but -# still available) mutex class. -#finished_tests_counter_lock = multiprocessing.Lock() -finished_tests_mutex = mutex.mutex() finished_tests_counter = multiprocessing.Value(c_int) +finished_tests_counter_lock = multiprocessing.Lock() # utility routine to print an update on the number of tests that have been -# finished. Should be called with the mutex (or lock) held.. +# finished. Should be called with the lock held.. def update_progress(fn): finished_tests_counter.value = finished_tests_counter.value + 1 progress_str = " Done %d / %d [%s]" % (finished_tests_counter.value, total_tests, fn) @@ -108,18 +109,18 @@ def update_progress(fn): progress_str += '\r' sys.stdout.write(progress_str) sys.stdout.flush() - finished_tests_mutex.unlock() def run_command(cmd): if options.verbose: - print "Running: %s" % cmd + sys.stdout.write("Running: %s\n" % cmd) sp = subprocess.Popen(shlex.split(cmd), stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out = sp.communicate() output = "" - output += out[0] - output += out[1] + output += out[0].decode("utf-8") + output += out[1].decode("utf-8") + return (sp.returncode, output) # run the commands in cmd_list @@ -128,9 +129,9 @@ def run_cmds(compile_cmds, run_cmd, filename, expect_failure): (return_code, output) = run_command(cmd) compile_failed = (return_code != 0) if compile_failed: - print "Compilation of test %s failed " % filename + sys.stdout.write("Compilation of test %s failed \n" % filename) if output != "": - print "%s" % output + sys.stdout.write("%s" % output) return (1, 0) (return_code, output) = run_command(run_cmd) @@ -139,11 +140,11 @@ def run_cmds(compile_cmds, run_cmd, filename, expect_failure): surprise = ((expect_failure and not run_failed) or (not expect_failure and run_failed)) if surprise == True: - print "Test %s %s (return code %d) " % \ + sys.stderr.write("Test %s %s (return code %d) \n" % \ (filename, "unexpectedly passed" if expect_failure else "failed", - return_code) + return_code)) if output != "": - print "%s" % output + sys.stdout.write("%s\n" % output) if surprise == True: return (0, 1) else: @@ -160,7 +161,7 @@ def run_test(filename): # is this a test to make sure an error is issued? want_error = (filename.find("tests_errors") != -1) if want_error == True: - ispc_cmd = "ispc --werror --nowrap %s --arch=%s --target=%s" % \ + ispc_cmd = ispc_exe + " --werror --nowrap %s --arch=%s --target=%s" % \ (input_prefix + filename, options.arch, options.target) (return_code, output) = run_command(ispc_cmd) got_error = (return_code != 0) @@ -168,18 +169,17 @@ def run_test(filename): # figure out the error message we're expecting file = open(input_prefix + filename, 'r') firstline = file.readline() - firstline = string.replace(firstline, "//", "") - firstline = string.lstrip(firstline) - firstline = string.rstrip(firstline) + firstline = firstline.replace("//", "") + firstline = firstline.lstrip() + firstline = firstline.rstrip() file.close() if (output.find(firstline) == -1): - print "OUT %s" % filename - print "Didnt see expected error message %s from test %s.\nActual output:\n%s" % \ - (firstline, filename, output) + sys.stderr.write("Didn't see expected error message %s from test %s.\nActual output:\n%s\n" % \ + (firstline, filename, output)) return (1, 0) elif got_error == False: - print "Unexpectedly no errors issued from test %s" % filename + sys.stderr.write("Unexpectedly no errors issued from test %s\n" % filename) return (1, 0) else: return (0, 0) @@ -199,14 +199,14 @@ def run_test(filename): continue # one of them should have a function with one of the # declarations in sig2def - for pattern, ident in sig2def.items(): + for pattern, ident in list(sig2def.items()): if line.find(pattern) != -1: match = ident break file.close() if match == -1: - print "Fatal error: unable to find function signature " + \ - "in test %s" % filename + sys.stderr.write("Fatal error: unable to find function signature " + \ + "in test %s\n" % filename) return (1, 0) else: is_generic_target = options.target.find("generic-") != -1 @@ -218,7 +218,7 @@ def run_test(filename): obj_name = "%s%s.obj" % (input_prefix, filename) exe_name = "%s%s.exe" % (input_prefix, filename) - cc_cmd = "%s /I. /Zi /nologo /DTEST_SIG=%d %stest_static.cpp %s /Fe%s" % \ + cc_cmd = "%s /I. /Iwinstuff /Zi /nologo /DTEST_SIG=%d %stest_static.cpp %s /Fe%s" % \ (options.compiler_exe, match, input_prefix, obj_name, exe_name) if should_fail: cc_cmd += " /DEXPECT_FAILURE" @@ -238,18 +238,19 @@ def run_test(filename): if should_fail: cc_cmd += " -DEXPECT_FAILURE" - ispc_cmd = "ispc --woff %s -o %s --arch=%s --target=%s" % \ + ispc_cmd = ispc_exe + " --woff %s -o %s --arch=%s --target=%s" % \ (input_prefix+filename, obj_name, options.arch, options.target) if options.no_opt: ispc_cmd += " -O0" if is_generic_target: ispc_cmd += " --emit-c++ --c++-include-file=%s" % options.include_file - + # compile the ispc code, make the executable, and run it... - global valgrind_cmd + global valgrind_exe (compile_error, run_error) = run_cmds([ispc_cmd, cc_cmd], - valgrind_cmd + " " + exe_name, \ + valgrind_exe + " " + exe_name, \ filename, should_fail) + # clean up after running the test try: if not run_error: @@ -297,11 +298,8 @@ def run_tasks_from_queue(queue, queue_ret): if run_error != 0: run_error_files += [ filename ] - # If not for http://bugs.python.org/issue5261 on OSX, we'd like to do this: - #with finished_tests_counter_lock: - #update_progress(filename) - # but instead we do this... - finished_tests_mutex.lock(update_progress, filename) + with finished_tests_counter_lock: + update_progress(filename) task_threads = [] @@ -315,6 +313,7 @@ if __name__ == '__main__': compile_error_files = [ ] run_error_files = [ ] + nthreads = multiprocessing.cpu_count() print "Found %d CPUs. Running %d tests." % (nthreads, total_tests) @@ -349,13 +348,13 @@ if __name__ == '__main__': if len(compile_error_files) > 0: compile_error_files.sort() - print "%d / %d tests FAILED compilation:" % (len(compile_error_files), total_tests) + sys.stdout.write("%d / %d tests FAILED compilation:\n" % (len(compile_error_files), total_tests)) for f in compile_error_files: - print "\t%s" % f + sys.stdout.write("\t%s\n" % f) if len(run_error_files) > 0: run_error_files.sort() - print "%d / %d tests FAILED execution:" % (len(run_error_files), total_tests) + sys.stdout.write("%d / %d tests FAILED execution:\n" % (len(run_error_files), total_tests)) for f in run_error_files: - print "\t%s" % f + sys.stdout.write("\t%s\n" % f) sys.exit(len(compile_error_files) + len(run_error_files)) diff --git a/stdlib2cpp.py b/stdlib2cpp.py index 6fa5fc2e..d032d023 100755 --- a/stdlib2cpp.py +++ b/stdlib2cpp.py @@ -4,11 +4,15 @@ import sys t=str(sys.argv[1]) -print "char stdlib_" + t + "_code[] = { " +sys.stdout.write("char stdlib_" + t + "_code[] = {\n") -for line in sys.stdin: - for c in line: - print ord(c) - print ", " +width = 16 +data = sys.stdin.read() +for i in range(0, len(data), 1): + sys.stdout.write("0x%0.2X, " % ord(data[i:i+1])) -print "0 };" + if i%width == (width-1): + sys.stdout.write("\n") + +sys.stdout.write("0x00 };\n\n") + diff --git a/winstuff/stdint.h b/winstuff/stdint.h new file mode 100644 index 00000000..895f702a --- /dev/null +++ b/winstuff/stdint.h @@ -0,0 +1,7 @@ +#ifndef MY_STDINT_H +#define MY_STDINT_H 1 + +typedef __int32 int32_t; +typedef __int64 int64_t; + +#endif // MY_STDINT_H \ No newline at end of file