diff options
author | max99x <max99x@gmail.com> | 2011-07-09 20:14:00 +0300 |
---|---|---|
committer | max99x <max99x@gmail.com> | 2011-07-09 20:14:00 +0300 |
commit | 11e404d7a8c76dbc1f10e24f4cee527f36d20092 (patch) | |
tree | db9f500e777b9eee54c4f2fb46a31976340a67de | |
parent | b5b48bab8bddb23a80031897d97f8942e702787a (diff) |
Polish for emscripten.py and its tests.
-rwxr-xr-x | emscripten.py | 29 | ||||
-rw-r--r-- | tests/autoassemble.bc | bin | 576 -> 0 bytes | |||
-rw-r--r-- | tests/autoassemble.c | 6 | ||||
-rw-r--r-- | tests/cases/unannotated.ll (renamed from tests/unannotated.ll) | 0 | ||||
-rw-r--r-- | tests/cases/unannotated.txt | 1 | ||||
-rw-r--r-- | tests/runner.py | 26 |
6 files changed, 36 insertions, 26 deletions
diff --git a/emscripten.py b/emscripten.py index 6477439c..6fe7b504 100755 --- a/emscripten.py +++ b/emscripten.py @@ -9,9 +9,10 @@ import tempfile import tools.shared as shared -# Temporary files that should be deleted once teh program is finished. +# Temporary files that should be deleted once the program is finished. TEMP_FILES_TO_CLEAN = [] -# The data layout used by llvm-gcc (as opposed to clang). +# The data layout used by llvm-gcc (as opposed to clang, which doesn't have the +# f128:128:128 part). GCC_DATA_LAYOUT = ('target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16' '-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64' '-v128:128:128-a0:0:64-f80:32:32-f128:128:128-n8:16:32"') @@ -42,9 +43,8 @@ def assemble(filepath): The path to the assembled file. """ if not filepath.endswith('.bc'): - out = get_temp_file('.bc') - ret = subprocess.call([shared.LLVM_AS, '-o=-', filepath], stdout=out) - out.close() + command = [shared.LLVM_AS, '-o=-', filepath] + with get_temp_file('.bc') as out: ret = subprocess.call(command, stdout=out) if ret != 0: raise RuntimeError('Could not assemble %s.' % filepath) filepath = out.name return filepath @@ -61,10 +61,8 @@ def disassemble(filepath): The path to the disassembled file. """ if not filepath.endswith('.ll'): - out = get_temp_file('.ll') command = [shared.LLVM_DIS, '-o=-', filepath] + shared.LLVM_DIS_OPTS - ret = subprocess.call(command, stdout=out) - out.close() + with get_temp_file('.ll') as out: ret = subprocess.call(command, stdout=out) if ret != 0: raise RuntimeError('Could not disassemble %s.' % filepath) filepath = out.name return filepath @@ -79,10 +77,8 @@ def optimize(filepath): Returns: The path to the optimized file. """ - out = get_temp_file('.bc') - opts = shared.pick_llvm_opts(3, True) - ret = subprocess.call([shared.LLVM_OPT, '-o=-', filepath] + opts, stdout=out) - out.close() + command = [shared.LLVM_OPT, '-o=-', filepath] + shared.pick_llvm_opts(3, True) + with get_temp_file('.bc') as out: ret = subprocess.call(command, stdout=out) if ret != 0: raise RuntimeError('Could not optimize %s.' % filepath) return out.name @@ -96,9 +92,8 @@ def link(*objects): Returns: The path to the linked file. """ - out = get_temp_file('.bc') - ret = subprocess.call([shared.LLVM_LINK] + list(objects), stdout=out) - out.close() + command = [shared.LLVM_LINK] + list(objects) + with get_temp_file('.bc') as out: ret = subprocess.call(command, stdout=out) if ret != 0: raise RuntimeError('Could not link %s.' % objects) return out.name @@ -113,11 +108,9 @@ def compile_malloc(compiler): The path to the compiled dlmalloc as an LLVM bitcode (.bc) file. """ src = path_from_root('src', 'dlmalloc.c') - out = get_temp_file('.bc') includes = '-I' + path_from_root('src', 'include') command = [compiler, '-c', '-g', '-emit-llvm', '-m32', '-o-', includes, src] - ret = subprocess.call(command, stdout=out) - out.close() + with get_temp_file('.bc') as out: ret = subprocess.call(command, stdout=out) if ret != 0: raise RuntimeError('Could not compile dlmalloc.') return out.name diff --git a/tests/autoassemble.bc b/tests/autoassemble.bc Binary files differdeleted file mode 100644 index 27a668c8..00000000 --- a/tests/autoassemble.bc +++ /dev/null diff --git a/tests/autoassemble.c b/tests/autoassemble.c new file mode 100644 index 00000000..0619933c --- /dev/null +++ b/tests/autoassemble.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main() { + puts("test\n"); + return 0; +} diff --git a/tests/unannotated.ll b/tests/cases/unannotated.ll index 96ce5468..96ce5468 100644 --- a/tests/unannotated.ll +++ b/tests/cases/unannotated.ll diff --git a/tests/cases/unannotated.txt b/tests/cases/unannotated.txt new file mode 100644 index 00000000..9daeafb9 --- /dev/null +++ b/tests/cases/unannotated.txt @@ -0,0 +1 @@ +test diff --git a/tests/runner.py b/tests/runner.py index 04856b8b..28abbfde 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -2673,15 +2673,25 @@ if 'benchmark' not in sys.argv: # This test *should* fail assert 'Assertion failed' in str(e), str(e) - def test_unannotated(self): - self.do_ll_test(path_from_root('tests', 'unannotated.ll'), 'test\n') - def test_autoassemble(self): - filename = os.path.join(self.get_dir(), 'src.bc') - shutil.copy(path_from_root('tests', 'autoassemble.bc'), filename) - self.do_emscripten(filename, append_ext=False) - shutil.copy(filename + '.o.js', os.path.join(self.get_dir(), 'src.cpp.o.js')) - self.do_test(None, 'test\n', no_build=True) + src = r''' + #include <stdio.h> + + int main() { + puts("test\n"); + return 0; + } + ''' + dirname = self.get_dir() + filename = os.path.join(dirname, 'src.cpp') + self.build(src, dirname, filename) + + new_filename = os.path.join(dirname, 'new.bc') + shutil.copy(filename + '.o', new_filename) + self.do_emscripten(new_filename, append_ext=False) + + shutil.copy(filename + '.o.js', os.path.join(self.get_dir(), 'new.cpp.o.js')) + self.do_test(None, 'test\n', basename='new.cpp', no_build=True) def test_dlmalloc_linked(self): src = open(path_from_root('tests', 'dlmalloc_test.c'), 'r').read() |