From a8c8fadea692781b62de964b91649ff4ee650a51 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 13 Oct 2014 17:03:12 -0700 Subject: [PATCH] finalize saved original code when it will be swapped in --- emcc | 13 +++++++++++++ tests/test_browser.py | 4 ++++ tests/test_other.py | 7 +++++++ tools/emterpretify.py | 3 +-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/emcc b/emcc index 968b7ea6a..430392a4a 100755 --- a/emcc +++ b/emcc @@ -1498,11 +1498,24 @@ try: shared.try_delete(js_target) # minify (if requested) after emterpreter processing, and finalize output + logging.debug('finalizing emterpreted code') shared.Settings.FINALIZE_ASM_JS = 1 do_minify() js_optimizer_queue += ['last'] flush_js_optimizer_queue() + # finalize the original as well, if we will be swapping it in (TODO: add specific option for this) + if shared.Settings.SWAPPABLE_ASM_MODULE: + real = final + original = js_target + '.orig.js' # the emterpretify tool saves the original here + final = original + logging.debug('finalizing original (non-emterpreted) code at ' + final) + do_minify() + js_optimizer_queue += ['last'] + flush_js_optimizer_queue() + safe_move(final, original) + final = real + # Remove some trivial whitespace # TODO: do not run when compress has already been done on all parts of the code #src = open(final).read() #src = re.sub(r'\n+[ \n]*\n+', '\n', src) diff --git a/tests/test_browser.py b/tests/test_browser.py index 235cfacef..6ba8736d0 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -2060,5 +2060,9 @@ Module['_main'] = function() { Popen([PYTHON, EMCC, 'second.cpp'] + opts).communicate() Popen([PYTHON, path_from_root('tools', 'distill_asm.py'), 'a.out.js', 'second.js', 'swap-in']).communicate() assert os.path.exists('second.js') + + out = run_js('second.js', engine=SPIDERMONKEY_ENGINE, stderr=PIPE, full_output=True, assert_returncode=None) + self.validate_asmjs(out) + self.btest(path_from_root('tests', 'asm_swap.cpp'), args=['-s', 'SWAPPABLE_ASM_MODULE=1', '-s', 'NO_EXIT_RUNTIME=1', '--pre-js', 'run.js'] + opts, expected='999') diff --git a/tests/test_other.py b/tests/test_other.py index fa129a7e4..95e12b817 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -4303,3 +4303,10 @@ function _main() { do_log_test(path_from_root('tests', 'primes.cpp'), 86, 'main') do_log_test(path_from_root('tests', 'fannkuch.cpp'), 234, 'fannkuch_worker') + def test_emterpreter_swap_orig(self): + Popen([PYTHON, EMCC, path_from_root('tests', 'fasta.cpp'), '-s', 'EMTERPRETIFY=1', '-s', 'SWAPPABLE_ASM_MODULE=1', '-O2']).communicate() + Popen([PYTHON, path_from_root('tools', 'distill_asm.py'), 'a.out.js.orig.js', 'second.js', 'swap-in']).communicate() + assert os.path.exists('second.js') + out = run_js('second.js', engine=SPIDERMONKEY_ENGINE, stderr=PIPE, full_output=True, assert_returncode=None) + self.validate_asmjs(out) + diff --git a/tools/emterpretify.py b/tools/emterpretify.py index dba132474..05f8162f1 100755 --- a/tools/emterpretify.py +++ b/tools/emterpretify.py @@ -561,8 +561,7 @@ force_memfile = sys.argv[3] if len(sys.argv) >= 4 else None if len(sys.argv) >= 5: BLACKLIST = set(list(BLACKLIST) + json.loads(sys.argv[4])) -#print 'emterpretifying %s to %s' % (infile, outfile) - +shared.logging.debug('saving original (non-emterpreted) code to ' + infile + '.orig.js') shutil.copyfile(infile, infile + '.orig.js') # final global functions