aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemscripten.py17
-rwxr-xr-xtests/runner.py16
2 files changed, 17 insertions, 16 deletions
diff --git a/emscripten.py b/emscripten.py
index c91814a4..f1f90e2c 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -175,22 +175,22 @@ def emscript(infile, settings, outfile, libraries=[]):
if jcache:
# load chunks from cache where we can # TODO: ignore small chunks
- cached_funcs = []
+ cached_outputs = []
def load_from_cache(chunk):
keys = [settings_text, forwarded_data, chunk]
shortkey = shared.JCache.get_shortkey(keys) # TODO: share shortkeys with later code
out = shared.JCache.get(shortkey, keys)
if out:
- cached_funcs.append(out)
+ cached_outputs.append(out)
return False
return True
chunks = filter(load_from_cache, chunks)
- if len(cached_funcs) > 0:
- if out and DEBUG: print >> sys.stderr, ' loading %d funcchunks from jcache' % len(cached_funcs)
- cached_funcs_js = ''.join(cached_funcs)
- cached_funcs = None
+ if len(cached_outputs) > 0:
+ if out and DEBUG: print >> sys.stderr, ' loading %d funcchunks from jcache' % len(cached_outputs)
else:
- cached_funcs_js = ''
+ cached_outputs = []
+
+ # TODO: minimize size of forwarded data from funcs to what we actually need
if cores == 1 and total_ll_size < MAX_CHUNK_SIZE: assert len(chunks) == 1, 'no point in splitting up without multiple cores'
@@ -216,9 +216,8 @@ def emscript(infile, settings, outfile, libraries=[]):
shared.JCache.set(shortkey, keys, outputs[i])
if out and DEBUG and len(chunks) > 0: print >> sys.stderr, ' saving %d funcchunks to jcache' % len(chunks)
+ if jcache: outputs += cached_outputs # TODO: preserve order
funcs_js = ''.join([output[0] for output in outputs])
- if jcache:
- funcs_js += cached_funcs_js # TODO insert them in the original order
for func_js, curr_forwarded_data in outputs:
# merge forwarded data
diff --git a/tests/runner.py b/tests/runner.py
index 0b0a41ca..d93105ed 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -10461,7 +10461,9 @@ fi
assert not os.path.exists(JCache.get_cachename('emscript_files'))
- src = None
+ srcs = {}
+ used_jcache = False
+
for args, input_file, expect_save, expect_load in [
([], 'hello_world_loop.cpp', False, False),
(['--jcache'], 'hello_world_loop.cpp', True, False),
@@ -10473,7 +10475,7 @@ fi
([], 'hello_world.cpp', False, False),
(['--jcache'], 'hello_world_loop.cpp', False, True), # go back to old file, experience caching
]:
- print args, input_file, expect_save, expect_load
+ print >> sys.stderr, args, input_file, expect_save, expect_load
self.clear()
out, err = Popen(['python', EMCC, path_from_root('tests', input_file)] + args, stdout=PIPE, stderr=PIPE).communicate()
assert (PRE_SAVE_MSG in err) == expect_save, err
@@ -10481,12 +10483,12 @@ fi
assert (FUNC_CHUNKS_SAVE_MSG in err) == expect_save, err
assert (FUNC_CHUNKS_LOAD_MSG in err) == expect_load, err
curr = open('a.out.js').read()
- if src is None:
- src = None
+ if input_file not in srcs:
+ srcs[input_file] = curr
else:
- assert src == curr, 'caching must not affect codegen'
-
- assert os.path.exists(JCache.get_cachename('emscript_files'))
+ assert curr == srcs[input_file], err
+ used_jcache = used_jcache or ('--jcache' in args)
+ assert used_jcache == os.path.exists(JCache.get_cachename('emscript_files'))
finally:
del os.environ['EMCC_DEBUG']