diff options
-rw-r--r-- | src/modules.js | 2 | ||||
-rw-r--r-- | tests/runner.py | 62 | ||||
-rwxr-xr-x | tools/exec_llvm.py | 39 | ||||
-rw-r--r-- | tools/shared.py | 1 |
4 files changed, 74 insertions, 30 deletions
diff --git a/src/modules.js b/src/modules.js index 31ede3a3..4d811b56 100644 --- a/src/modules.js +++ b/src/modules.js @@ -23,7 +23,7 @@ var Debugging = { var form3 = new RegExp(/^!(\d+) = metadata !{i32 (\d+), i32 \d+, metadata !(\d+), .*}$/); var form3a = new RegExp(/^!(\d+) = metadata !{i32 \d+, metadata !\d+, i32 \d+, i32 \d+, metadata !(\d+), i32 \d+} ; \[ DW_TAG_lexical_block \]$/); var form3ab = new RegExp(/^!(\d+) = metadata !{i32 \d+, i32 \d+, metadata !(\d+), .*$/); - var form3ac = new RegExp(/^!(\d+) = metadata !{i32 \d+, metadata !\d+, metadata !"[^"]+", metadata !(\d+)[^\[]* ; \[ DW_TAG_structure_type \]$/); + var form3ac = new RegExp(/^!(\d+) = metadata !{i32 \d+, metadata !\d+, metadata !"[^"]+", metadata !(\d+)[^\[]* ; \[ DW_TAG_.*$/); var form3b = new RegExp(/^!(\d+) = metadata !{i32 \d+, metadata !"([^"]+)", metadata !"([^"]+)", metadata !\d+} ; \[ DW_TAG_file_type \]$/); var form3c = new RegExp(/^!(\d+) = metadata !{\w+\d* !?(\d+)[^\d].*$/); var form4 = new RegExp(/^!llvm.dbg.[\w\.]+ = .*$/); diff --git a/tests/runner.py b/tests/runner.py index 5897b263..c7668ad0 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -240,30 +240,29 @@ if 'benchmark' not in sys.argv: #shutil.rmtree(dirname) # TODO: leave no trace in memory. But for now nice for debugging - def prep_ll_test(self, filename, ll_file, force_recompile=False): + def prep_ll_test(self, filename, ll_file, force_recompile=False, build_ll_hook=None): if ll_file.endswith(('.bc', '.o')): shutil.copy(ll_file, filename + '.o') self.do_llvm_dis(filename) - shutil.copy(filename + '.o.ll', filename + '.o.ll.in') - os.remove(filename + '.o.ll') - ll_file = filename + '.o.ll.in' + else: + shutil.copy(ll_file, filename + '.o.ll') - if LLVM_OPTS or force_recompile: - shutil.copy(ll_file, filename + '.o.ll.pre') + if LLVM_OPTS or force_recompile or build_ll_hook: + if build_ll_hook: + build_ll_hook(filename) + shutil.move(filename + '.o.ll', filename + '.o.ll.pre') output = Popen([LLVM_AS, filename + '.o.ll.pre'] + ['-o=' + filename + '.o'], stdout=PIPE, stderr=STDOUT).communicate()[0] assert 'error:' not in output, 'Error in llvm-as: ' + output self.do_llvm_opts(filename) Popen([LLVM_DIS, filename + '.o'] + LLVM_DIS_OPTS + ['-o=' + filename + '.o.ll'], stdout=PIPE, stderr=STDOUT).communicate()[0] - else: - shutil.copy(ll_file, filename + '.o.ll') # No building - just process an existing .ll file (or .bc, which we turn into .ll) - def do_ll_test(self, ll_file, expected_output=None, args=[], js_engines=None, output_nicerizer=None, post_build=None, force_recompile=False): + def do_ll_test(self, ll_file, expected_output=None, args=[], js_engines=None, output_nicerizer=None, post_build=None, force_recompile=False, build_ll_hook=None): if COMPILER != LLVM_GCC: return # We use existing .ll, so which compiler is unimportant filename = os.path.join(self.get_dir(), 'src.cpp') - self.prep_ll_test(filename, ll_file, force_recompile) + self.prep_ll_test(filename, ll_file, force_recompile, build_ll_hook) self.do_emscripten(filename) self.do_test(None, expected_output, @@ -1592,8 +1591,10 @@ if 'benchmark' not in sys.argv: env = os.environ.copy() env['RANLIB'] = env['AR'] = env['CXX'] = env['CC'] = env['LIBTOOL'] = EMMAKEN env['EMMAKEN_COMPILER'] = COMPILER + env['EMSCRIPTEN_TOOLS'] = path_from_root('tools') env['CFLAGS'] = env['EMMAKEN_CFLAGS'] = ' '.join(COMPILER_OPTS + COMPILER_TEST_OPTS) # Normal CFLAGS is ignored by some configure's. - Popen(configure + configure_args, stdout=PIPE, stderr=STDOUT, env=env).communicate()[0] + if configure: + Popen(configure + configure_args, stdout=PIPE, stderr=STDOUT, env=env).communicate()[0] Popen(make + make_args, stdout=PIPE, stderr=STDOUT, env=env).communicate()[0] bc_file = os.path.join(project_dir, 'bc.bc') self.do_link(map(lambda lib: os.path.join(project_dir, lib), generated_libs), bc_file) @@ -1643,6 +1644,27 @@ if 'benchmark' not in sys.argv: includes=[path_from_root('tests', 'zlib')], force_c=True) + def zzztest_poppler(self): + global SAFE_HEAP; SAFE_HEAP = 0 # Has variable object + + def post(filename): + src = open(filename, 'r').read().replace( + '// {{PRE_RUN_ADDITIONS}}', + '''this._STDIO.prepare('paper.pdf', %s);''' % str( + map(ord, open(path_from_root('tests', 'poppler', 'paper.pdf'), 'rb').read()) + ) + ) + open(filename, 'w').write(src) + + poppler = self.get_library('poppler', + [os.path.join('poppler', '.libs', 'libpoppler.so.13.0.0'), + os.path.join('utils', 'pdftoppm.o')]) + #freetype = ... link it + self.do_ll_test(poppler, + 'halp',#open(path_from_root('tests', 'poppler', 'ref.txt'), 'r').read(), + args='-png -scale-to 512 paper.pdf filename'.split(' '), + post_build=post) + def test_openjpeg(self): global SAFE_HEAP; SAFE_HEAP = 0 # Very slow global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-g'] @@ -1726,24 +1748,6 @@ if 'benchmark' not in sys.argv: post_build=post, output_nicerizer=image_compare)#, build_ll_hook=self.do_autodebug) - def zzztest_poppler(self): - # Has 'Object', which has a big union with a value that can be of any type (like a dynamic value) - global SAFE_HEAP; SAFE_HEAP = 0 - - def post(filename): - src = open(filename, 'r').read().replace( - '// {{PRE_RUN_ADDITIONS}}', - '''this._STDIO.prepare('paper.pdf', %s);''' % str( - map(ord, open(path_from_root('tests', 'poppler', 'paper.pdf'), 'rb').read()) - ) - ) - open(filename, 'w').write(src) - - self.do_ll_test(path_from_root('tests', 'poppler', 'pdftoppm.bc'), - 'halp', - args='-png -scale-to 512 paper.pdf filename'.split(' '), - post_build=post) - def test_python(self): # Overflows in string_hash global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 1 diff --git a/tools/exec_llvm.py b/tools/exec_llvm.py new file mode 100755 index 00000000..05194b1a --- /dev/null +++ b/tools/exec_llvm.py @@ -0,0 +1,39 @@ +''' +Small utility to execute some llvm bitcode. + +The use case is a Makefile that builds some executable +and runs it as part of the build process. With emmaken, +the Makefile will generate llvm bitcode, so we can't +just execute it directly. This script will get that +code into a runnable form, and run it. + +We cannot just use lli, since code built with debug +symbols will crash it due to + + http://llvm.org/bugs/show_bug.cgi?id=6981 + +So instead we compile the bitcode into native code. + +To use this, change the Makefile so that instead of +running + + /bin/sh THE_FILE PARAMS + +it runs + + python $(EMSCRIPTEN_TOOLS)/exec_llvm.py THE_FILE PARAMS +''' + +import os, sys +from subprocess import Popen, PIPE, STDOUT + +abspath = os.path.abspath(os.path.dirname(__file__)) +def path_from_root(*pathelems): + return os.path.join(os.path.sep, *(abspath.split(os.sep)[:-1] + list(pathelems))) +exec(open(path_from_root('tools', 'shared.py'), 'r').read()) + +print 'EXEC_LLVM: ', sys.argv +Popen([LLVM_COMPILER, '-march=c', sys.argv[1]]).communicate()[0] +Popen(['gcc', sys.argv[1]+'.cbe.c']).communicate()[0] +Popen(['./a.out'] + sys.argv[2:]).communicate()[0] + diff --git a/tools/shared.py b/tools/shared.py index a0698d09..45473e2c 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -15,6 +15,7 @@ LLVM_AS=os.path.expanduser(os.path.join(LLVM_ROOT, 'llvm-as')) LLVM_DIS=os.path.expanduser(os.path.join(LLVM_ROOT, 'llvm-dis')) LLVM_DIS_OPTS = ['-show-annotations'] # For LLVM 2.8+. For 2.7, you may need to do just [] LLVM_INTERPRETER=os.path.expanduser(os.path.join(LLVM_ROOT, 'lli')) +LLVM_COMPILER=os.path.expanduser(os.path.join(LLVM_ROOT, 'llc')) # Engine tweaks |